backend: Take over seat ownership from the clutter backend

Having the clutter backend owning and managing creates complication for
implementing graceful shutdown, so move it to the real backend.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1775>
This commit is contained in:
Jonas Ådahl 2021-03-12 08:31:50 +01:00 committed by Marge Bot
parent 16b63451a3
commit 6ecd911dd0
9 changed files with 96 additions and 105 deletions

View File

@ -73,7 +73,6 @@ struct _ClutterBackendClass
ClutterStageWindow * (* create_stage) (ClutterBackend *backend,
ClutterStage *wrapper,
GError **error);
void (* init_events) (ClutterBackend *backend);
void (* init_features) (ClutterBackend *backend);
void (* add_options) (ClutterBackend *backend,
GOptionGroup *group);
@ -116,7 +115,6 @@ gboolean _clutter_backend_pre_parse (Clutter
gboolean _clutter_backend_post_parse (ClutterBackend *backend,
GError **error);
void _clutter_backend_init_events (ClutterBackend *backend);
CLUTTER_EXPORT
gboolean _clutter_backend_translate_event (ClutterBackend *backend,
gpointer native,

View File

@ -445,12 +445,6 @@ _clutter_create_backend (void)
return retval;
}
static void
clutter_backend_real_init_events (ClutterBackend *backend)
{
g_error ("Unknown input backend");
}
static void
clutter_backend_class_init (ClutterBackendClass *klass)
{
@ -513,7 +507,6 @@ clutter_backend_class_init (ClutterBackendClass *klass)
klass->resolution_changed = clutter_backend_real_resolution_changed;
klass->font_changed = clutter_backend_real_font_changed;
klass->init_events = clutter_backend_real_init_events;
klass->create_context = clutter_backend_real_create_context;
klass->get_features = clutter_backend_real_get_features;
}
@ -652,17 +645,6 @@ _clutter_backend_get_features (ClutterBackend *backend)
return 0;
}
void
_clutter_backend_init_events (ClutterBackend *backend)
{
ClutterBackendClass *klass;
g_assert (CLUTTER_IS_BACKEND (backend));
klass = CLUTTER_BACKEND_GET_CLASS (backend);
klass->init_events (backend);
}
gfloat
_clutter_backend_get_units_per_em (ClutterBackend *backend,
PangoFontDescription *font_desc)

View File

@ -608,9 +608,6 @@ clutter_init_real (GError **error)
clutter_text_direction = clutter_get_text_direction ();
/* Initiate event collection */
_clutter_backend_init_events (ctx->backend);
clutter_is_initialized = TRUE;
ctx->is_initialized = TRUE;

View File

@ -71,6 +71,9 @@ struct _MetaBackendClass
GError **error);
MetaInputSettings * (* get_input_settings) (MetaBackend *backend);
ClutterSeat * (* create_default_seat) (MetaBackend *backend,
GError **error);
gboolean (* grab_device) (MetaBackend *backend,
int device_id,
uint32_t timestamp);
@ -122,6 +125,8 @@ void meta_backend_init_wayland (MetaBackend *backend);
ClutterBackend * meta_backend_get_clutter_backend (MetaBackend *backend);
ClutterSeat * meta_backend_get_default_seat (MetaBackend *bakcend);
MetaIdleMonitor * meta_backend_get_idle_monitor (MetaBackend *backend,
ClutterInputDevice *device);
void meta_backend_foreach_device_monitor (MetaBackend *backend,

View File

@ -149,6 +149,7 @@ struct _MetaBackendPrivate
#endif
ClutterBackend *clutter_backend;
ClutterSeat *default_seat;
ClutterActor *stage;
GList *gpus;
@ -244,6 +245,7 @@ meta_backend_dispose (GObject *object)
g_clear_object (&priv->profiler);
#endif
g_clear_object (&priv->default_seat);
g_clear_object (&priv->clutter_backend);
G_OBJECT_CLASS (meta_backend_parent_class)->dispose (object);
@ -1047,10 +1049,18 @@ meta_get_clutter_backend (void)
return meta_backend_get_clutter_backend (backend);
}
static ClutterSeat *
meta_backend_create_default_seat (MetaBackend *backend,
GError **error)
{
return META_BACKEND_GET_CLASS (backend)->create_default_seat (backend, error);
}
static gboolean
init_clutter (MetaBackend *backend,
GError **error)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
MetaBackendSource *backend_source;
GSource *source;
@ -1063,6 +1073,10 @@ init_clutter (MetaBackend *backend,
return FALSE;
}
priv->default_seat = meta_backend_create_default_seat (backend, error);
if (!priv->default_seat)
return FALSE;
source = g_source_new (&clutter_source_funcs, sizeof (MetaBackendSource));
backend_source = (MetaBackendSource *) source;
backend_source->backend = backend;
@ -1393,6 +1407,14 @@ meta_backend_get_stage (MetaBackend *backend)
return priv->stage;
}
ClutterSeat *
meta_backend_get_default_seat (MetaBackend *backend)
{
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
return priv->default_seat;
}
static gboolean
update_last_device (MetaBackend *backend)
{

View File

@ -126,6 +126,29 @@ meta_backend_native_create_clutter_backend (MetaBackend *backend)
return g_object_new (META_TYPE_CLUTTER_BACKEND_NATIVE, NULL);
}
static ClutterSeat *
meta_backend_native_create_default_seat (MetaBackend *backend,
GError **error)
{
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
const char *seat_id;
MetaSeatNativeFlag flags;
seat_id = meta_backend_native_get_seat_id (backend_native);
if (meta_backend_native_is_headless (backend_native))
flags = META_SEAT_NATIVE_FLAG_NO_LIBINPUT;
else
flags = META_SEAT_NATIVE_FLAG_NONE;
return CLUTTER_SEAT (g_object_new (META_TYPE_SEAT_NATIVE,
"backend", clutter_backend,
"seat-id", seat_id,
"flags", flags,
NULL));
}
#ifdef HAVE_REMOTE_DESKTOP
static void
maybe_disable_screen_cast_dma_bufs (MetaBackendNative *native)
@ -597,6 +620,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
object_class->dispose = meta_backend_native_dispose;
backend_class->create_clutter_backend = meta_backend_native_create_clutter_backend;
backend_class->create_default_seat = meta_backend_native_create_default_seat;
backend_class->post_init = meta_backend_native_post_init;

View File

@ -54,8 +54,6 @@
struct _MetaClutterBackendNative
{
ClutterBackend parent;
MetaSeatNative *main_seat;
};
G_DEFINE_TYPE (MetaClutterBackendNative, meta_clutter_backend_native,
@ -82,37 +80,12 @@ meta_clutter_backend_native_create_stage (ClutterBackend *clutter_backend,
NULL);
}
static void
meta_clutter_backend_native_init_events (ClutterBackend *clutter_backend)
{
MetaClutterBackendNative *clutter_backend_native =
META_CLUTTER_BACKEND_NATIVE (clutter_backend);
MetaBackend *backend = meta_get_backend ();
MetaBackendNative *backend_native = META_BACKEND_NATIVE (backend);
const char *seat_id;
MetaSeatNativeFlag flags;
seat_id = meta_backend_native_get_seat_id (backend_native);
if (meta_backend_native_is_headless (backend_native))
flags = META_SEAT_NATIVE_FLAG_NO_LIBINPUT;
else
flags = META_SEAT_NATIVE_FLAG_NONE;
clutter_backend_native->main_seat = g_object_new (META_TYPE_SEAT_NATIVE,
"backend", clutter_backend,
"seat-id", seat_id,
"flags", flags,
NULL);
}
static ClutterSeat *
meta_clutter_backend_native_get_default_seat (ClutterBackend *clutter_backend)
{
MetaClutterBackendNative *clutter_backend_native =
META_CLUTTER_BACKEND_NATIVE (clutter_backend);
MetaBackend *backend = meta_get_backend ();
return CLUTTER_SEAT (clutter_backend_native->main_seat);
return meta_backend_get_default_seat (backend);
}
static gboolean
@ -121,17 +94,6 @@ meta_clutter_backend_native_is_display_server (ClutterBackend *clutter_backend)
return TRUE;
}
static void
meta_clutter_backend_native_finalize (GObject *object)
{
MetaClutterBackendNative *clutter_backend_native =
META_CLUTTER_BACKEND_NATIVE (object);
g_clear_object (&clutter_backend_native->main_seat);
G_OBJECT_CLASS (meta_clutter_backend_native_parent_class)->finalize (object);
}
static void
meta_clutter_backend_native_init (MetaClutterBackendNative *clutter_backend_nativen)
{
@ -140,14 +102,10 @@ meta_clutter_backend_native_init (MetaClutterBackendNative *clutter_backend_nati
static void
meta_clutter_backend_native_class_init (MetaClutterBackendNativeClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
ClutterBackendClass *clutter_backend_class = CLUTTER_BACKEND_CLASS (klass);
object_class->finalize = meta_clutter_backend_native_finalize;
clutter_backend_class->get_renderer = meta_clutter_backend_native_get_renderer;
clutter_backend_class->create_stage = meta_clutter_backend_native_create_stage;
clutter_backend_class->init_events = meta_clutter_backend_native_init_events;
clutter_backend_class->get_default_seat = meta_clutter_backend_native_get_default_seat;
clutter_backend_class->is_display_server = meta_clutter_backend_native_is_display_server;
}

View File

@ -624,6 +624,42 @@ meta_backend_x11_create_clutter_backend (MetaBackend *backend)
return g_object_new (META_TYPE_CLUTTER_BACKEND_X11, NULL);
}
static ClutterSeat *
meta_backend_x11_create_default_seat (MetaBackend *backend,
GError **error)
{
MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
int event_base, first_event, first_error;
int major, minor;
MetaSeatX11 *seat_x11;
if (!XQueryExtension (priv->xdisplay,
"XInputExtension",
&event_base,
&first_event,
&first_error))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to query XInputExtension");
return NULL;
}
major = 2;
minor = 3;
if (XIQueryVersion (priv->xdisplay, &major, &minor) == BadRequest)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Incompatible XInputExtension version");
return NULL;
}
seat_x11 = meta_seat_x11_new (event_base,
META_VIRTUAL_CORE_POINTER_ID,
META_VIRTUAL_CORE_KEYBOARD_ID);
return CLUTTER_SEAT (seat_x11);
}
static gboolean
meta_backend_x11_grab_device (MetaBackend *backend,
int device_id,
@ -894,6 +930,7 @@ meta_backend_x11_class_init (MetaBackendX11Class *klass)
object_class->dispose = meta_backend_x11_dispose;
object_class->finalize = meta_backend_x11_finalize;
backend_class->create_clutter_backend = meta_backend_x11_create_clutter_backend;
backend_class->create_default_seat = meta_backend_x11_create_default_seat;
backend_class->post_init = meta_backend_x11_post_init;
backend_class->grab_device = meta_backend_x11_grab_device;
backend_class->ungrab_device = meta_backend_x11_ungrab_device;

View File

@ -41,7 +41,6 @@
struct _MetaClutterBackendX11
{
ClutterBackendX11 parent;
MetaSeatX11 *core_seat;
};
G_DEFINE_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
@ -82,10 +81,10 @@ meta_clutter_backend_x11_translate_event (ClutterBackend *clutter_backend,
gpointer native,
ClutterEvent *event)
{
MetaClutterBackendX11 *clutter_backend_x11 =
META_CLUTTER_BACKEND_X11 (clutter_backend);
MetaBackend *backend = meta_get_backend ();
MetaStageX11 *stage_x11;
ClutterBackendClass *clutter_backend_class;
ClutterSeat *seat;
clutter_backend_class =
CLUTTER_BACKEND_CLASS (meta_clutter_backend_x11_parent_class);
@ -97,49 +96,19 @@ meta_clutter_backend_x11_translate_event (ClutterBackend *clutter_backend,
if (meta_stage_x11_translate_event (stage_x11, native, event))
return TRUE;
if (meta_seat_x11_translate_event (clutter_backend_x11->core_seat,
native, event))
seat = meta_backend_get_default_seat (backend);
if (meta_seat_x11_translate_event (META_SEAT_X11 (seat), native, event))
return TRUE;
return FALSE;
}
static void
meta_clutter_backend_x11_init_events (ClutterBackend *backend)
{
MetaClutterBackendX11 *backend_x11 = META_CLUTTER_BACKEND_X11 (backend);
int event_base, first_event, first_error;
if (XQueryExtension (clutter_x11_get_default_display (),
"XInputExtension",
&event_base,
&first_event,
&first_error))
{
int major = 2;
int minor = 3;
if (XIQueryVersion (clutter_x11_get_default_display (),
&major, &minor) != BadRequest)
{
backend_x11->core_seat =
meta_seat_x11_new (event_base,
META_VIRTUAL_CORE_POINTER_ID,
META_VIRTUAL_CORE_KEYBOARD_ID);
}
}
if (!backend_x11->core_seat)
g_error ("No XInput 2.3 support");
}
static ClutterSeat *
meta_clutter_backend_x11_get_default_seat (ClutterBackend *clutter_backend)
{
MetaClutterBackendX11 *clutter_backend_x11 =
META_CLUTTER_BACKEND_X11 (clutter_backend);
MetaBackend *backend = meta_get_backend ();
return CLUTTER_SEAT (clutter_backend_x11->core_seat);
return meta_backend_get_default_seat (backend);
}
static gboolean
@ -161,7 +130,6 @@ meta_clutter_backend_x11_class_init (MetaClutterBackendX11Class *klass)
clutter_backend_class->get_renderer = meta_clutter_backend_x11_get_renderer;
clutter_backend_class->create_stage = meta_clutter_backend_x11_create_stage;
clutter_backend_class->translate_event = meta_clutter_backend_x11_translate_event;
clutter_backend_class->init_events = meta_clutter_backend_x11_init_events;
clutter_backend_class->get_default_seat = meta_clutter_backend_x11_get_default_seat;
clutter_backend_class->is_display_server = meta_clutter_backend_x11_is_display_server;
}