diff --git a/clutter/clutter/clutter-backend-private.h b/clutter/clutter/clutter-backend-private.h index 76fab8ad4..2f67c77ba 100644 --- a/clutter/clutter/clutter-backend-private.h +++ b/clutter/clutter/clutter-backend-private.h @@ -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, diff --git a/clutter/clutter/clutter-backend.c b/clutter/clutter/clutter-backend.c index fb918d9bc..f49d93cac 100644 --- a/clutter/clutter/clutter-backend.c +++ b/clutter/clutter/clutter-backend.c @@ -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) diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index dd2198cca..2efe8e973 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -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; diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 0c328ffcc..b930462b2 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -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, diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 4eb0a8e7d..609f690ac 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -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) { diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 5231d432c..dbbedceae 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -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; diff --git a/src/backends/native/meta-clutter-backend-native.c b/src/backends/native/meta-clutter-backend-native.c index 2d6a6b1dd..a28ecea99 100644 --- a/src/backends/native/meta-clutter-backend-native.c +++ b/src/backends/native/meta-clutter-backend-native.c @@ -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; } diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c index ae1a91628..1f5f95dde 100644 --- a/src/backends/x11/meta-backend-x11.c +++ b/src/backends/x11/meta-backend-x11.c @@ -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; diff --git a/src/backends/x11/meta-clutter-backend-x11.c b/src/backends/x11/meta-clutter-backend-x11.c index ed6b035fc..b34ae9c0f 100644 --- a/src/backends/x11/meta-clutter-backend-x11.c +++ b/src/backends/x11/meta-clutter-backend-x11.c @@ -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; }