seat/impl: Make it possible to run without libinput

Add a flag to MetaSeatNative and MetaSeatImpl that tells it not to
attempt to create a libinput context. This is intended to be used when
mutter is to run headless, as in without any input devices other than
virtual ones.

Currently not hooked up.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1698>
This commit is contained in:
Jonas Ådahl 2021-01-19 11:47:59 +01:00 committed by Marge Bot
parent 59a10cd188
commit 0786f44b0b
6 changed files with 119 additions and 39 deletions

View File

@ -28,4 +28,10 @@ typedef struct _MetaKeymapNative MetaKeymapNative;
typedef struct _MetaRendererNative MetaRendererNative; typedef struct _MetaRendererNative MetaRendererNative;
typedef struct _MetaGpuKms MetaGpuKms; typedef struct _MetaGpuKms MetaGpuKms;
typedef enum _MetaSeatNativeFlag
{
META_SEAT_NATIVE_FLAG_NONE = 0,
META_SEAT_NATIVE_FLAG_NO_LIBINPUT = 1 << 0,
} MetaSeatNativeFlag;
#endif /* META_BACKEND_NATIVE_TYPES_H */ #endif /* META_BACKEND_NATIVE_TYPES_H */

View File

@ -40,6 +40,8 @@
#include "clutter/clutter-mutter.h" #include "clutter/clutter-mutter.h"
#include "core/bell.h" #include "core/bell.h"
#include "meta-private-enum-types.h"
/* /*
* Clutter makes the assumption that two core devices have ID's 2 and 3 (core * Clutter makes the assumption that two core devices have ID's 2 and 3 (core
* pointer and core keyboard). * pointer and core keyboard).
@ -96,6 +98,7 @@ enum
PROP_0, PROP_0,
PROP_SEAT, PROP_SEAT,
PROP_SEAT_ID, PROP_SEAT_ID,
PROP_FLAGS,
N_PROPS, N_PROPS,
}; };
@ -259,9 +262,12 @@ keyboard_repeat (gpointer data)
/* There might be events queued in libinput that could cancel the /* There might be events queued in libinput that could cancel the
repeat timer. */ repeat timer. */
if (seat_impl->libinput)
{
dispatch_libinput (seat_impl); dispatch_libinput (seat_impl);
if (!seat_impl->repeat_source) if (!seat_impl->repeat_source)
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
}
g_return_val_if_fail (seat_impl->repeat_device != NULL, G_SOURCE_REMOVE); g_return_val_if_fail (seat_impl->repeat_device != NULL, G_SOURCE_REMOVE);
@ -2654,50 +2660,71 @@ meta_seat_impl_set_keyboard_numlock_in_impl (MetaSeatImpl *seat_impl,
seat_impl->xkb); seat_impl->xkb);
} }
static gpointer static gboolean
input_thread (MetaSeatImpl *seat_impl) init_libinput (MetaSeatImpl *seat_impl,
GError **error)
{ {
MetaEventSource *source; MetaEventSource *source;
struct udev *udev; struct udev *udev;
struct xkb_keymap *xkb_keymap; struct libinput *libinput;
g_main_context_push_thread_default (seat_impl->input_context);
udev = udev_new (); udev = udev_new ();
if (G_UNLIKELY (udev == NULL)) if (G_UNLIKELY (udev == NULL))
{ {
g_warning ("Failed to create udev object"); g_warning ("Failed to create udev object");
seat_impl->input_thread_initialized = TRUE; seat_impl->input_thread_initialized = TRUE;
return NULL; return FALSE;
} }
seat_impl->libinput = libinput_udev_create_context (&libinput_interface, libinput = libinput_udev_create_context (&libinput_interface,
seat_impl, udev); seat_impl, udev);
if (seat_impl->libinput == NULL)
{
g_critical ("Failed to create the libinput object.");
seat_impl->input_thread_initialized = TRUE;
return NULL;
}
if (libinput_udev_assign_seat (seat_impl->libinput, seat_impl->seat_id) == -1)
{
g_critical ("Failed to assign a seat to the libinput object.");
libinput_unref (seat_impl->libinput);
seat_impl->libinput = NULL;
seat_impl->input_thread_initialized = TRUE;
return NULL;
}
udev_unref (udev); udev_unref (udev);
if (libinput == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to create the libinput object.");
return FALSE;
}
if (libinput_udev_assign_seat (libinput, seat_impl->seat_id) == -1)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to assign a seat to the libinput object.");
libinput_unref (seat_impl->libinput);
return FALSE;
}
seat_impl->libinput = libinput;
source = meta_event_source_new (seat_impl);
seat_impl->event_source = source;
return TRUE;
}
static gpointer
input_thread (MetaSeatImpl *seat_impl)
{
struct xkb_keymap *xkb_keymap;
g_main_context_push_thread_default (seat_impl->input_context);
if (!(seat_impl->flags & META_SEAT_NATIVE_FLAG_NO_LIBINPUT))
{
g_autoptr (GError) error = NULL;
if (!init_libinput (seat_impl, &error))
{
g_critical ("Failed to initialize seat: %s", error->message);
seat_impl->input_thread_initialized = TRUE;
return NULL;
}
}
seat_impl->input_settings = meta_input_settings_native_new_in_impl (seat_impl); seat_impl->input_settings = meta_input_settings_native_new_in_impl (seat_impl);
g_signal_connect_object (seat_impl->input_settings, "kbd-a11y-changed", g_signal_connect_object (seat_impl->input_settings, "kbd-a11y-changed",
G_CALLBACK (kbd_a11y_changed_cb), seat_impl, 0); G_CALLBACK (kbd_a11y_changed_cb), seat_impl, 0);
source = meta_event_source_new (seat_impl);
seat_impl->event_source = source;
seat_impl->keymap = g_object_new (META_TYPE_KEYMAP_NATIVE, NULL); seat_impl->keymap = g_object_new (META_TYPE_KEYMAP_NATIVE, NULL);
xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (seat_impl->keymap); xkb_keymap = meta_keymap_native_get_keyboard_map_in_impl (seat_impl->keymap);
@ -2804,6 +2831,9 @@ meta_seat_impl_set_property (GObject *object,
case PROP_SEAT_ID: case PROP_SEAT_ID:
seat_impl->seat_id = g_value_dup_string (value); seat_impl->seat_id = g_value_dup_string (value);
break; break;
case PROP_FLAGS:
seat_impl->flags = g_value_get_flags (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@ -3050,6 +3080,15 @@ meta_seat_impl_class_init (MetaSeatImplClass *klass)
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY); G_PARAM_CONSTRUCT_ONLY);
props[PROP_FLAGS] =
g_param_spec_flags ("flags",
"Flags",
"Flags",
META_TYPE_SEAT_NATIVE_FLAG,
META_SEAT_NATIVE_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
signals[KBD_A11Y_FLAGS_CHANGED] = signals[KBD_A11Y_FLAGS_CHANGED] =
g_signal_new ("kbd-a11y-flags-changed", g_signal_new ("kbd-a11y-flags-changed",
G_TYPE_FROM_CLASS (object_class), G_TYPE_FROM_CLASS (object_class),
@ -3463,12 +3502,14 @@ meta_seat_impl_set_viewports (MetaSeatImpl *seat_impl,
MetaSeatImpl * MetaSeatImpl *
meta_seat_impl_new (MetaSeatNative *seat_native, meta_seat_impl_new (MetaSeatNative *seat_native,
const char *seat_id) const char *seat_id,
MetaSeatNativeFlag flags)
{ {
return g_initable_new (META_TYPE_SEAT_IMPL, return g_initable_new (META_TYPE_SEAT_IMPL,
NULL, NULL, NULL, NULL,
"seat", seat_native, "seat", seat_native,
"seat-id", seat_id, "seat-id", seat_id,
"flags", flags,
NULL); NULL);
} }

View File

@ -67,6 +67,7 @@ struct _MetaSeatImpl
MetaSeatNative *seat_native; MetaSeatNative *seat_native;
char *seat_id; char *seat_id;
MetaSeatNativeFlag flags;
MetaEventSource *event_source; MetaEventSource *event_source;
struct libinput *libinput; struct libinput *libinput;
GRWLock state_lock; GRWLock state_lock;
@ -127,7 +128,8 @@ G_DECLARE_FINAL_TYPE (MetaSeatImpl, meta_seat_impl,
META, SEAT_IMPL, GObject) META, SEAT_IMPL, GObject)
MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native, MetaSeatImpl * meta_seat_impl_new (MetaSeatNative *seat_native,
const char *seat_id); const char *seat_id,
MetaSeatNativeFlag flags);
void meta_seat_impl_destroy (MetaSeatImpl *seat_impl); void meta_seat_impl_destroy (MetaSeatImpl *seat_impl);

View File

@ -37,10 +37,13 @@
#include "clutter/clutter-mutter.h" #include "clutter/clutter-mutter.h"
#include "core/bell.h" #include "core/bell.h"
#include "meta-private-enum-types.h"
enum enum
{ {
PROP_0, PROP_0,
PROP_SEAT_ID, PROP_SEAT_ID,
PROP_FLAGS,
N_PROPS, N_PROPS,
/* This property is overridden */ /* This property is overridden */
@ -153,7 +156,7 @@ meta_seat_native_constructed (GObject *object)
{ {
MetaSeatNative *seat = META_SEAT_NATIVE (object); MetaSeatNative *seat = META_SEAT_NATIVE (object);
seat->impl = meta_seat_impl_new (seat, seat->seat_id); seat->impl = meta_seat_impl_new (seat, seat->seat_id, seat->flags);
g_signal_connect (seat->impl, "kbd-a11y-flags-changed", g_signal_connect (seat->impl, "kbd-a11y-flags-changed",
G_CALLBACK (proxy_kbd_a11y_flags_changed), seat); G_CALLBACK (proxy_kbd_a11y_flags_changed), seat);
g_signal_connect (seat->impl, "kbd-a11y-mods-state-changed", g_signal_connect (seat->impl, "kbd-a11y-mods-state-changed",
@ -187,6 +190,9 @@ meta_seat_native_set_property (GObject *object,
case PROP_SEAT_ID: case PROP_SEAT_ID:
seat_native->seat_id = g_value_dup_string (value); seat_native->seat_id = g_value_dup_string (value);
break; break;
case PROP_FLAGS:
seat_native->flags = g_value_get_flags (value);
break;
case PROP_TOUCH_MODE: case PROP_TOUCH_MODE:
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -209,6 +215,9 @@ meta_seat_native_get_property (GObject *object,
case PROP_TOUCH_MODE: case PROP_TOUCH_MODE:
g_value_set_boolean (value, seat_native->touch_mode); g_value_set_boolean (value, seat_native->touch_mode);
break; break;
case PROP_FLAGS:
g_value_set_flags (value, seat_native->flags);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
} }
@ -393,6 +402,15 @@ meta_seat_native_class_init (MetaSeatNativeClass *klass)
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY); G_PARAM_CONSTRUCT_ONLY);
props[PROP_FLAGS] =
g_param_spec_flags ("flags",
"Flags",
"Flags",
META_TYPE_SEAT_NATIVE_FLAG,
META_SEAT_NATIVE_FLAG_NONE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, props); g_object_class_install_properties (object_class, N_PROPS, props);
g_object_class_override_property (object_class, PROP_TOUCH_MODE, g_object_class_override_property (object_class, PROP_TOUCH_MODE,

View File

@ -44,6 +44,7 @@ struct _MetaSeatNative
MetaSeatImpl *impl; MetaSeatImpl *impl;
char *seat_id; char *seat_id;
MetaSeatNativeFlag flags;
GList *devices; GList *devices;
struct xkb_keymap *xkb_keymap; struct xkb_keymap *xkb_keymap;

View File

@ -744,13 +744,25 @@ if have_wayland_eglstream
] ]
endif endif
mutter_built_sources = [] mutter_private_enum_sources = []
if have_remote_desktop if have_remote_desktop
mutter_private_enum_types = gnome.mkenums('meta-private-enum-types', mutter_private_enum_sources += [
sources: [
'backends/meta-screen-cast.h', 'backends/meta-screen-cast.h',
], ]
endif
if have_native_backend
mutter_private_enum_sources += [
'backends/native/meta-backend-native-types.h',
]
endif
mutter_built_sources = []
if mutter_private_enum_sources.length() > 0
mutter_private_enum_types = gnome.mkenums('meta-private-enum-types',
sources: mutter_private_enum_sources,
c_template: 'meta-private-enum-types.c.in', c_template: 'meta-private-enum-types.c.in',
h_template: 'meta-private-enum-types.h.in', h_template: 'meta-private-enum-types.h.in',
) )