From 124a1582e1d1585fef2167285998f519fcc40f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 17 May 2021 19:13:40 +0200 Subject: [PATCH] native: Replace 'headless' property with 'mode' property There will be another mode added later, 'test'; prepare for this by changing the existing "mode" boolean ('headless') to a mode, which is either 'default' or 'headless'. Checking the is_headless variable is changed to using the function is_headless(), except for one place, being VT switching, which in preparation is only allowed on the 'default' mode. Other places where it makes sense, the conditions are changed to switch statements. Part-of: --- .../native/meta-backend-native-types.h | 6 ++ src/backends/native/meta-backend-native.c | 62 ++++++++++++------- src/core/meta-context-main.c | 2 +- src/tests/meta-context-test.c | 2 +- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/backends/native/meta-backend-native-types.h b/src/backends/native/meta-backend-native-types.h index f6c87484b..a8c4dd544 100644 --- a/src/backends/native/meta-backend-native-types.h +++ b/src/backends/native/meta-backend-native-types.h @@ -39,4 +39,10 @@ typedef enum _MetaSeatNativeFlag META_SEAT_NATIVE_FLAG_NO_LIBINPUT = 1 << 0, } MetaSeatNativeFlag; +typedef enum _MetaBackendNativeMode +{ + META_BACKEND_NATIVE_MODE_DEFAULT = 0, + META_BACKEND_NATIVE_MODE_HEADLESS, +} MetaBackendNativeMode; + #endif /* META_BACKEND_NATIVE_TYPES_H */ diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 0cbe40d87..be133b100 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -66,11 +66,13 @@ #include "backends/meta-screen-cast.h" #endif +#include "meta-private-enum-types.h" + enum { PROP_0, - PROP_HEADLESS, + PROP_MODE, N_PROPS }; @@ -86,7 +88,7 @@ struct _MetaBackendNative MetaUdev *udev; MetaKms *kms; - gboolean is_headless; + MetaBackendNativeMode mode; }; static GInitableIface *initable_parent_iface; @@ -254,10 +256,12 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend, { MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend); MetaMonitorManager *manager; + gboolean needs_outputs; + needs_outputs = !(backend_native->mode & META_BACKEND_NATIVE_MODE_HEADLESS); manager = g_initable_new (META_TYPE_MONITOR_MANAGER_NATIVE, NULL, error, "backend", backend, - "needs-outputs", !backend_native->is_headless, + "needs-outputs", needs_outputs, NULL); if (!manager) return NULL; @@ -372,16 +376,22 @@ meta_backend_native_lock_layout_group (MetaBackend *backend, const char * meta_backend_native_get_seat_id (MetaBackendNative *backend_native) { - if (backend_native->is_headless) - return "seat0"; - else - return meta_launcher_get_seat_id (backend_native->launcher); + switch (backend_native->mode) + { + case META_BACKEND_NATIVE_MODE_DEFAULT: + return meta_launcher_get_seat_id (backend_native->launcher); + case META_BACKEND_NATIVE_MODE_HEADLESS: + return "seat0"; + } + g_assert_not_reached (); } static gboolean meta_backend_native_is_headless (MetaBackend *backend) { - return META_BACKEND_NATIVE (backend)->is_headless; + MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend); + + return backend_native->mode == META_BACKEND_NATIVE_MODE_HEADLESS; } static void @@ -537,7 +547,7 @@ init_gpus (MetaBackendNative *native, g_list_free_full (devices, g_object_unref); - if (!native->is_headless && + if (!meta_backend_is_headless (backend) && g_list_length (meta_backend_get_gpus (backend)) == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND, @@ -558,6 +568,7 @@ meta_backend_native_initable_init (GInitable *initable, GError **error) { MetaBackendNative *native = META_BACKEND_NATIVE (initable); + MetaBackend *backend = META_BACKEND (native); MetaKmsFlags kms_flags; if (!meta_is_stage_views_enabled ()) @@ -567,7 +578,7 @@ meta_backend_native_initable_init (GInitable *initable, return FALSE; } - if (!native->is_headless) + if (!meta_backend_is_headless (backend)) { native->launcher = meta_launcher_new (error); if (!native->launcher) @@ -578,7 +589,7 @@ meta_backend_native_initable_init (GInitable *initable, native->udev = meta_udev_new (native); kms_flags = META_KMS_FLAG_NONE; - if (native->is_headless) + if (meta_backend_is_headless (backend)) kms_flags |= META_KMS_FLAG_NO_MODE_SETTING; native->kms = meta_kms_new (META_BACKEND (native), kms_flags, error); @@ -601,8 +612,8 @@ meta_backend_native_set_property (GObject *object, switch (prop_id) { - case PROP_HEADLESS: - backend_native->is_headless = g_value_get_boolean (value); + case PROP_MODE: + backend_native->mode = g_value_get_enum (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -649,14 +660,15 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass) backend_class->is_headless = meta_backend_native_is_headless; - obj_props[PROP_HEADLESS] = - g_param_spec_boolean ("headless", - "headless", - "Headless", - FALSE, - G_PARAM_WRITABLE | - G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS); + obj_props[PROP_MODE] = + g_param_spec_enum ("mode", + "mode", + "mode", + META_TYPE_BACKEND_NATIVE_MODE, + META_BACKEND_NATIVE_MODE_DEFAULT, + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); g_object_class_install_properties (object_class, N_PROPS, obj_props); } @@ -696,14 +708,18 @@ meta_activate_vt (int vt, GError **error) MetaBackendNative *native = META_BACKEND_NATIVE (backend); MetaLauncher *launcher = meta_backend_native_get_launcher (native); - if (native->is_headless) + switch (native->mode) { + case META_BACKEND_NATIVE_MODE_DEFAULT: + return meta_launcher_activate_vt (launcher, vt, error); + case META_BACKEND_NATIVE_MODE_HEADLESS: + case META_BACKEND_NATIVE_MODE_TEST: g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Can't switch VT while headless"); return FALSE; } - return meta_launcher_activate_vt (launcher, vt, error); + g_assert_not_reached (); } void diff --git a/src/core/meta-context-main.c b/src/core/meta-context-main.c index a81ea9f9f..fe11b4bb6 100644 --- a/src/core/meta-context-main.c +++ b/src/core/meta-context-main.c @@ -438,7 +438,7 @@ create_headless_backend (MetaContext *context, return g_initable_new (META_TYPE_BACKEND_NATIVE, NULL, error, "context", context, - "headless", TRUE, + "mode", META_BACKEND_NATIVE_MODE_HEADLESS, NULL); } diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c index 863c20a98..08acdcb73 100644 --- a/src/tests/meta-context-test.c +++ b/src/tests/meta-context-test.c @@ -159,7 +159,7 @@ create_headless_backend (MetaContext *context, return g_initable_new (META_TYPE_BACKEND_NATIVE, NULL, error, "context", context, - "headless", TRUE, + "mode", META_BACKEND_NATIVE_MODE_HEADLESS, NULL); } #endif /* HAVE_NATIVE_BACKEND */