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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2151>
This commit is contained in:
parent
a2382f3251
commit
124a1582e1
@ -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 */
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user