From 4413b86a304b65708a71d829925d6a029f83f5fb Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 4 Oct 2019 21:57:26 +0200 Subject: [PATCH] backends: Replace ClutterDeviceManager usage in favor of ClutterSeat https://gitlab.gnome.org/GNOME/mutter/merge_requests/852 --- src/backends/meta-backend.c | 88 +++++++++++-------- src/backends/meta-cursor-tracker.c | 6 +- src/backends/meta-idle-monitor-dbus.c | 20 ++--- src/backends/meta-input-mapper.c | 14 +-- src/backends/meta-input-settings.c | 69 ++++++++------- src/backends/native/meta-backend-native.c | 5 +- .../native/meta-input-device-native.c | 1 - .../native/meta-input-settings-native.c | 1 - src/backends/native/meta-keymap-native.c | 2 +- src/backends/native/meta-launcher.c | 2 +- src/backends/x11/cm/meta-backend-x11-cm.c | 11 +-- 11 files changed, 114 insertions(+), 105 deletions(-) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 158d8986a..f5d915766 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -257,8 +257,8 @@ meta_backend_monitors_changed (MetaBackend *backend) MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); MetaMonitorManager *monitor_manager = meta_backend_get_monitor_manager (backend); - ClutterDeviceManager *manager = clutter_device_manager_get_default (); - ClutterInputDevice *device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE); + ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend); + ClutterInputDevice *device = clutter_seat_get_pointer (seat); graphene_point_t point; meta_backend_sync_screen_size (backend); @@ -352,9 +352,9 @@ meta_backend_monitor_device (MetaBackend *backend, } static void -on_device_added (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - gpointer user_data) +on_device_added (ClutterSeat *seat, + ClutterInputDevice *device, + gpointer user_data) { MetaBackend *backend = META_BACKEND (user_data); int device_id = clutter_input_device_get_device_id (device); @@ -370,15 +370,16 @@ device_is_slave_touchscreen (ClutterInputDevice *device) } static inline gboolean -check_has_pointing_device (ClutterDeviceManager *manager) +check_has_pointing_device (ClutterSeat *seat) { - const GSList *devices; + GList *l, *devices; + gboolean found = FALSE; - devices = clutter_device_manager_peek_devices (manager); + devices = clutter_seat_list_devices (seat); - for (; devices; devices = devices->next) + for (l = devices; l; l = l->next) { - ClutterInputDevice *device = devices->data; + ClutterInputDevice *device = l->data; if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) continue; @@ -386,35 +387,44 @@ check_has_pointing_device (ClutterDeviceManager *manager) clutter_input_device_get_device_type (device) == CLUTTER_KEYBOARD_DEVICE) continue; - return TRUE; + found = TRUE; + break; } - return FALSE; + g_list_free (devices); + + return found; } static inline gboolean -check_has_slave_touchscreen (ClutterDeviceManager *manager) +check_has_slave_touchscreen (ClutterSeat *seat) { - const GSList *devices; + GList *l, *devices; + gboolean found = FALSE; - devices = clutter_device_manager_peek_devices (manager); + devices = clutter_seat_list_devices (seat); - for (; devices; devices = devices->next) + for (l = devices; l; l = l->next) { - ClutterInputDevice *device = devices->data; + ClutterInputDevice *device = l->data; if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER && clutter_input_device_get_device_type (device) == CLUTTER_TOUCHSCREEN_DEVICE) - return TRUE; + { + found = TRUE; + break; + } } - return FALSE; + g_list_free (devices); + + return found; } static void -on_device_removed (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - gpointer user_data) +on_device_removed (ClutterSeat *seat, + ClutterInputDevice *device, + gpointer user_data) { MetaBackend *backend = META_BACKEND (user_data); MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); @@ -434,7 +444,7 @@ on_device_removed (ClutterDeviceManager *device_manager, priv->current_device = NULL; device_type = clutter_input_device_get_device_type (device); - has_touchscreen = check_has_slave_touchscreen (device_manager); + has_touchscreen = check_has_slave_touchscreen (seat); if (device_type == CLUTTER_TOUCHSCREEN_DEVICE && has_touchscreen) { @@ -443,7 +453,7 @@ on_device_removed (ClutterDeviceManager *device_manager, } else if (device_type != CLUTTER_KEYBOARD_DEVICE) { - has_pointing_device = check_has_pointing_device (device_manager); + has_pointing_device = check_has_pointing_device (seat); meta_cursor_tracker_set_pointer_visible (cursor_tracker, has_pointing_device && !has_touchscreen); @@ -452,33 +462,33 @@ on_device_removed (ClutterDeviceManager *device_manager, } static void -create_device_monitors (MetaBackend *backend, - ClutterDeviceManager *device_manager) +create_device_monitors (MetaBackend *backend, + ClutterSeat *seat) { - const GSList *devices; - const GSList *l; + GList *l, *devices; create_device_monitor (backend, META_IDLE_MONITOR_CORE_DEVICE); - devices = clutter_device_manager_peek_devices (device_manager); + devices = clutter_seat_list_devices (seat); for (l = devices; l; l = l->next) { ClutterInputDevice *device = l->data; meta_backend_monitor_device (backend, device); } + + g_list_free (devices); } static void -set_initial_pointer_visibility (MetaBackend *backend, - ClutterDeviceManager *device_manager) +set_initial_pointer_visibility (MetaBackend *backend, + ClutterSeat *seat) { MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); - const GSList *devices; - const GSList *l; + GList *l, *devices; gboolean has_touchscreen = FALSE; - devices = clutter_device_manager_peek_devices (device_manager); + devices = clutter_seat_list_devices (seat); for (l = devices; l; l = l->next) { ClutterInputDevice *device = l->data; @@ -486,6 +496,7 @@ set_initial_pointer_visibility (MetaBackend *backend, has_touchscreen |= device_is_slave_touchscreen (device); } + g_list_free (devices); meta_cursor_tracker_set_pointer_visible (priv->cursor_tracker, !has_touchscreen); } @@ -500,7 +511,6 @@ static void meta_backend_real_post_init (MetaBackend *backend) { MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); - ClutterDeviceManager *device_manager = clutter_device_manager_get_default (); ClutterSeat *seat = clutter_backend_get_default_seat (priv->clutter_backend); ClutterKeymap *keymap = clutter_seat_get_keymap (seat); @@ -518,14 +528,14 @@ meta_backend_real_post_init (MetaBackend *backend) g_hash_table_new_full (g_int_hash, g_int_equal, NULL, (GDestroyNotify) g_object_unref); - create_device_monitors (backend, device_manager); + create_device_monitors (backend, seat); - g_signal_connect_object (device_manager, "device-added", + g_signal_connect_object (seat, "device-added", G_CALLBACK (on_device_added), backend, 0); - g_signal_connect_object (device_manager, "device-removed", + g_signal_connect_object (seat, "device-removed", G_CALLBACK (on_device_removed), backend, 0); - set_initial_pointer_visibility (backend, device_manager); + set_initial_pointer_visibility (backend, seat); priv->input_settings = meta_backend_create_input_settings (backend); diff --git a/src/backends/meta-cursor-tracker.c b/src/backends/meta-cursor-tracker.c index ec95e62af..c2dff032e 100644 --- a/src/backends/meta-cursor-tracker.c +++ b/src/backends/meta-cursor-tracker.c @@ -405,12 +405,12 @@ get_pointer_position_clutter (int *x, int *y, int *mods) { - ClutterDeviceManager *cmanager; + ClutterSeat *seat; ClutterInputDevice *cdevice; graphene_point_t point; - cmanager = clutter_device_manager_get_default (); - cdevice = clutter_device_manager_get_core_device (cmanager, CLUTTER_POINTER_DEVICE); + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + cdevice = clutter_seat_get_pointer (seat); clutter_input_device_get_coords (cdevice, NULL, &point); if (x) diff --git a/src/backends/meta-idle-monitor-dbus.c b/src/backends/meta-idle-monitor-dbus.c index 2065f0177..8fcc2f25c 100644 --- a/src/backends/meta-idle-monitor-dbus.c +++ b/src/backends/meta-idle-monitor-dbus.c @@ -210,7 +210,7 @@ create_monitor_skeleton (GDBusObjectManagerServer *manager, } static void -on_device_added (ClutterDeviceManager *device_manager, +on_device_added (ClutterSeat *seat, ClutterInputDevice *device, GDBusObjectManagerServer *manager) { @@ -228,7 +228,7 @@ on_device_added (ClutterDeviceManager *device_manager, } static void -on_device_removed (ClutterDeviceManager *device_manager, +on_device_removed (ClutterSeat *seat, ClutterInputDevice *device, GDBusObjectManagerServer *manager) { @@ -247,9 +247,9 @@ on_bus_acquired (GDBusConnection *connection, gpointer user_data) { GDBusObjectManagerServer *manager; - ClutterDeviceManager *device_manager; MetaIdleMonitor *monitor; - GSList *devices, *iter; + ClutterSeat *seat; + GList *devices, *iter; char *path; manager = g_dbus_object_manager_server_new ("/org/gnome/Mutter/IdleMonitor"); @@ -261,17 +261,17 @@ on_bus_acquired (GDBusConnection *connection, create_monitor_skeleton (manager, monitor, path); g_free (path); - device_manager = clutter_device_manager_get_default (); - devices = clutter_device_manager_list_devices (device_manager); + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + devices = clutter_seat_list_devices (seat); for (iter = devices; iter; iter = iter->next) - on_device_added (device_manager, iter->data, manager); + on_device_added (seat, iter->data, manager); - g_slist_free (devices); + g_list_free (devices); - g_signal_connect_object (device_manager, "device-added", + g_signal_connect_object (seat, "device-added", G_CALLBACK (on_device_added), manager, 0); - g_signal_connect_object (device_manager, "device-removed", + g_signal_connect_object (seat, "device-removed", G_CALLBACK (on_device_removed), manager, 0); g_dbus_object_manager_server_set_connection (manager, connection); diff --git a/src/backends/meta-input-mapper.c b/src/backends/meta-input-mapper.c index fc4f3bd59..0e5a5f5c3 100644 --- a/src/backends/meta-input-mapper.c +++ b/src/backends/meta-input-mapper.c @@ -40,7 +40,7 @@ struct _MetaInputMapper { GObject parent_instance; MetaMonitorManager *monitor_manager; - ClutterDeviceManager *input_device_manager; + ClutterSeat *seat; GHashTable *input_devices; /* ClutterInputDevice -> MetaMapperInputInfo */ GHashTable *output_devices; /* MetaLogicalMonitor -> MetaMapperOutputInfo */ #ifdef HAVE_LIBGUDEV @@ -525,9 +525,9 @@ input_mapper_monitors_changed_cb (MetaMonitorManager *monitor_manager, } static void -input_mapper_device_removed_cb (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - MetaInputMapper *mapper) +input_mapper_device_removed_cb (ClutterSeat *seat, + ClutterInputDevice *device, + MetaInputMapper *mapper) { meta_input_mapper_remove_device (mapper, device); } @@ -540,7 +540,7 @@ meta_input_mapper_finalize (GObject *object) g_signal_handlers_disconnect_by_func (mapper->monitor_manager, input_mapper_monitors_changed_cb, mapper); - g_signal_handlers_disconnect_by_func (mapper->input_device_manager, + g_signal_handlers_disconnect_by_func (mapper->seat, input_mapper_device_removed_cb, mapper); @@ -568,8 +568,8 @@ meta_input_mapper_constructed (GObject *object) mapper->udev_client = g_udev_client_new (udev_subsystems); #endif - mapper->input_device_manager = clutter_device_manager_get_default (); - g_signal_connect (mapper->input_device_manager, "device-removed", + mapper->seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + g_signal_connect (mapper->seat, "device-removed", G_CALLBACK (input_mapper_device_removed_cb), mapper); backend = meta_get_backend (); diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 1d27aa003..08762ac72 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -67,7 +67,6 @@ struct _DeviceMappingInfo struct _MetaInputSettingsPrivate { - ClutterDeviceManager *device_manager; ClutterSeat *seat; MetaMonitorManager *monitor_manager; gulong monitors_changed_id; @@ -130,23 +129,23 @@ meta_input_settings_get_devices (MetaInputSettings *settings, ClutterInputDeviceType type) { MetaInputSettingsPrivate *priv; - const GSList *devices; + GList *l, *devices; GSList *list = NULL; priv = meta_input_settings_get_instance_private (settings); - devices = clutter_device_manager_peek_devices (priv->device_manager); + devices = clutter_seat_list_devices (priv->seat); - while (devices) + for (l = devices; l; l = l->next) { - ClutterInputDevice *device = devices->data; + ClutterInputDevice *device = l->data; if (clutter_input_device_get_device_type (device) == type && clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_MASTER) list = g_slist_prepend (list, device); - - devices = devices->next; } + g_list_free (devices); + return list; } @@ -383,10 +382,9 @@ update_pointer_accel_profile (MetaInputSettings *input_settings, { MetaInputSettingsPrivate *priv = meta_input_settings_get_instance_private (input_settings); - const GSList *devices; - const GSList *l; + GList *l, *devices; - devices = clutter_device_manager_peek_devices (priv->device_manager); + devices = clutter_seat_list_devices (priv->seat); for (l = devices; l; l = l->next) { device = l->data; @@ -398,6 +396,8 @@ update_pointer_accel_profile (MetaInputSettings *input_settings, do_update_pointer_accel_profile (input_settings, settings, device, profile); } + + g_list_free (devices); } } @@ -767,19 +767,19 @@ update_trackball_scroll_button (MetaInputSettings *input_settings, } else if (!device) { - const GSList *devices; + GList *l, *devices; - devices = clutter_device_manager_peek_devices (priv->device_manager); + devices = clutter_seat_list_devices (priv->seat); - while (devices) + for (l = devices; l; l = l->next) { device = devices->data; if (input_settings_class->is_trackball_device (input_settings, device)) input_settings_class->set_scroll_button (input_settings, device, button); - - devices = devices->next; } + + g_list_free (devices); } } @@ -1252,7 +1252,7 @@ load_keyboard_a11y_settings (MetaInputSettings *input_settings, ClutterSeat *seat = clutter_backend_get_default_seat (backend); guint i; - core_keyboard = clutter_device_manager_get_core_device (priv->device_manager, CLUTTER_KEYBOARD_DEVICE); + core_keyboard = clutter_seat_get_keyboard (priv->seat); if (device && device != core_keyboard) return; @@ -1351,15 +1351,14 @@ load_pointer_a11y_settings (MetaInputSettings *input_settings, ClutterPointerA11ySettings pointer_a11y_settings; ClutterInputDevice *core_pointer; GDesktopMouseDwellMode dwell_mode; - ClutterSeat *seat; guint i; - core_pointer = clutter_device_manager_get_core_device (priv->device_manager, CLUTTER_POINTER_DEVICE); + core_pointer = clutter_seat_get_pointer (priv->seat); if (device && device != core_pointer) return; - seat = clutter_input_device_get_seat (device); - clutter_seat_get_pointer_a11y_settings (seat, &pointer_a11y_settings); + clutter_seat_get_pointer_a11y_settings (CLUTTER_SEAT (priv->seat), + &pointer_a11y_settings); pointer_a11y_settings.controls = 0; for (i = 0; i < G_N_ELEMENTS (pointer_a11y_settings_flags_pair); i++) { @@ -1391,7 +1390,8 @@ load_pointer_a11y_settings (MetaInputSettings *input_settings, pointer_a11y_settings.dwell_gesture_secondary = pointer_a11y_dwell_direction_from_setting (input_settings, "dwell-gesture-secondary"); - clutter_seat_set_pointer_a11y_settings (seat, &pointer_a11y_settings); + clutter_seat_set_pointer_a11y_settings (CLUTTER_SEAT (priv->seat), + &pointer_a11y_settings); } static void @@ -1779,9 +1779,9 @@ evaluate_two_finger_scrolling (MetaInputSettings *input_settings, } static void -meta_input_settings_device_added (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - MetaInputSettings *input_settings) +meta_input_settings_device_added (ClutterSeat *seat, + ClutterInputDevice *device, + MetaInputSettings *input_settings) { if (clutter_input_device_get_device_mode (device) == CLUTTER_INPUT_MODE_MASTER) return; @@ -1793,9 +1793,9 @@ meta_input_settings_device_added (ClutterDeviceManager *device_manager, } static void -meta_input_settings_device_removed (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - MetaInputSettings *input_settings) +meta_input_settings_device_removed (ClutterSeat *seat, + ClutterInputDevice *device, + MetaInputSettings *input_settings) { MetaInputSettingsPrivate *priv; @@ -1846,7 +1846,7 @@ current_tool_info_free (CurrentToolInfo *info) } static void -meta_input_settings_tool_changed (ClutterDeviceManager *device_manager, +meta_input_settings_tool_changed (ClutterSeat *seat, ClutterInputDevice *device, ClutterInputDeviceTool *tool, MetaInputSettings *input_settings) @@ -1873,10 +1873,10 @@ static void check_mappable_devices (MetaInputSettings *input_settings) { MetaInputSettingsPrivate *priv; - const GSList *devices, *l; + GList *l, *devices; priv = meta_input_settings_get_instance_private (input_settings); - devices = clutter_device_manager_peek_devices (priv->device_manager); + devices = clutter_seat_list_devices (priv->seat); for (l = devices; l; l = l->next) { @@ -1887,6 +1887,8 @@ check_mappable_devices (MetaInputSettings *input_settings) check_add_mappable_device (input_settings, device); } + + g_list_free (devices); } static void @@ -1958,12 +1960,11 @@ meta_input_settings_init (MetaInputSettings *settings) priv = meta_input_settings_get_instance_private (settings); priv->seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); - priv->device_manager = clutter_device_manager_get_default (); - g_signal_connect (priv->device_manager, "device-added", + g_signal_connect (priv->seat, "device-added", G_CALLBACK (meta_input_settings_device_added), settings); - g_signal_connect (priv->device_manager, "device-removed", + g_signal_connect (priv->seat, "device-removed", G_CALLBACK (meta_input_settings_device_removed), settings); - g_signal_connect (priv->device_manager, "tool-changed", + g_signal_connect (priv->seat, "tool-changed", G_CALLBACK (meta_input_settings_tool_changed), settings); priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse"); diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index f24f440ef..8d827e7d7 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -50,7 +50,6 @@ #include "backends/native/meta-barrier-native.h" #include "backends/native/meta-clutter-backend-native.h" #include "backends/native/meta-cursor-renderer-native.h" -#include "backends/native/meta-device-manager-native.h" #include "backends/native/meta-event-native.h" #include "backends/native/meta-input-settings-native.h" #include "backends/native/meta-kms.h" @@ -409,8 +408,8 @@ meta_backend_native_warp_pointer (MetaBackend *backend, int x, int y) { - ClutterDeviceManager *manager = clutter_device_manager_get_default (); - ClutterInputDevice *device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE); + ClutterSeat *seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + ClutterInputDevice *device = clutter_seat_get_pointer (seat); MetaCursorTracker *cursor_tracker = meta_backend_get_cursor_tracker (backend); /* XXX */ diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c index 609c06000..c54e98b30 100644 --- a/src/backends/native/meta-input-device-native.c +++ b/src/backends/native/meta-input-device-native.c @@ -26,7 +26,6 @@ #include "backends/native/meta-input-device-tool-native.h" #include "backends/native/meta-input-device-native.h" -#include "backends/native/meta-device-manager-native.h" #include "backends/native/meta-seat-native.h" #include "clutter/clutter-mutter.h" diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c index fe5073bd8..a6a781746 100644 --- a/src/backends/native/meta-input-settings-native.c +++ b/src/backends/native/meta-input-settings-native.c @@ -28,7 +28,6 @@ #include "backends/meta-logical-monitor.h" #include "backends/native/meta-backend-native.h" -#include "backends/native/meta-device-manager-native.h" #include "backends/native/meta-input-device-native.h" #include "backends/native/meta-input-device-tool-native.h" #include "backends/native/meta-input-settings-native.h" diff --git a/src/backends/native/meta-keymap-native.c b/src/backends/native/meta-keymap-native.c index be2a9f5ab..e34c4454a 100644 --- a/src/backends/native/meta-keymap-native.c +++ b/src/backends/native/meta-keymap-native.c @@ -21,8 +21,8 @@ #include "config.h" -#include "backends/native/meta-device-manager-native.h" #include "backends/native/meta-keymap-native.h" +#include "backends/native/meta-seat-native.h" static const char *option_xkb_layout = "us"; static const char *option_xkb_variant = ""; diff --git a/src/backends/native/meta-launcher.c b/src/backends/native/meta-launcher.c index cfb3c4131..61fe19be0 100644 --- a/src/backends/native/meta-launcher.c +++ b/src/backends/native/meta-launcher.c @@ -39,8 +39,8 @@ #include "backends/native/meta-backend-native.h" #include "backends/native/meta-clutter-backend-native.h" #include "backends/native/meta-cursor-renderer-native.h" -#include "backends/native/meta-device-manager-native.h" #include "backends/native/meta-renderer-native.h" +#include "backends/native/meta-seat-native.h" #include "clutter/clutter.h" #include "meta-dbus-login1.h" diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c index bb1ba4b06..ab139a767 100644 --- a/src/backends/x11/cm/meta-backend-x11-cm.c +++ b/src/backends/x11/cm/meta-backend-x11-cm.c @@ -70,9 +70,9 @@ take_touch_grab (MetaBackend *backend) } static void -on_device_added (ClutterDeviceManager *device_manager, - ClutterInputDevice *device, - gpointer user_data) +on_device_added (ClutterSeat *seat, + ClutterInputDevice *device, + gpointer user_data) { MetaBackendX11 *x11 = META_BACKEND_X11 (user_data); @@ -85,11 +85,12 @@ meta_backend_x11_cm_post_init (MetaBackend *backend) { MetaBackendClass *parent_backend_class = META_BACKEND_CLASS (meta_backend_x11_cm_parent_class); + ClutterSeat *seat; parent_backend_class->post_init (backend); - g_signal_connect_object (clutter_device_manager_get_default (), - "device-added", + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + g_signal_connect_object (seat, "device-added", G_CALLBACK (on_device_added), backend, 0); take_touch_grab (backend);