From c6e6ed87c537deee99998694d2b593228bc91efa Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 27 Mar 2015 15:50:59 +0100 Subject: [PATCH] backends: Center pointer on primary monitor on startup This seems nicer/tidier than the current X11 (center on the span of all monitors) or native (so close to the activities corner it's hard not to trigger it) platform behaviors. This code also takes over the native-specific pointer warping that happens when the pointer was over a removed output. https://bugzilla.gnome.org/show_bug.cgi?id=746896 --- src/backends/meta-backend.c | 27 ++++++++++++++++++ src/backends/native/meta-backend-native.c | 34 ----------------------- 2 files changed, 27 insertions(+), 34 deletions(-) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index f55a4a02a..4a88c89d1 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -92,12 +92,37 @@ meta_backend_sync_screen_size (MetaBackend *backend) META_BACKEND_GET_CLASS (backend)->update_screen_size (backend, width, height); } +static void +center_pointer (MetaBackend *backend) +{ + MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); + MetaMonitorInfo *monitors, *primary; + guint n_monitors; + + monitors = meta_monitor_manager_get_monitor_infos (priv->monitor_manager, &n_monitors); + primary = &monitors[meta_monitor_manager_get_primary_index (priv->monitor_manager)]; + meta_backend_warp_pointer (backend, + primary->rect.x + primary->rect.width / 2, + primary->rect.y + primary->rect.height / 2); +} + static void on_monitors_changed (MetaMonitorManager *monitors, gpointer user_data) { MetaBackend *backend = META_BACKEND (user_data); + ClutterDeviceManager *manager = clutter_device_manager_get_default (); + ClutterInputDevice *device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE); + ClutterPoint point; + meta_backend_sync_screen_size (backend); + + if (clutter_input_device_get_coords (device, NULL, &point)) + { + /* If we're outside all monitors, warp the pointer back inside */ + if (meta_monitor_manager_get_monitor_at_point (monitors, point.x, point.y) < 0) + center_pointer (backend); + } } static MetaIdleMonitor * @@ -283,6 +308,8 @@ meta_backend_real_post_init (MetaBackend *backend) } priv->input_settings = meta_input_settings_create (); + + center_pointer (backend); } static MetaCursorRenderer * diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 9f2cb9b19..b33c936a8 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -152,49 +152,15 @@ pointer_constrain_callback (ClutterInputDevice *device, constrain_all_screen_monitors(device, monitors, n_monitors, new_x, new_y); } -static void -on_monitors_changed (MetaMonitorManager *monitor_manager, - MetaBackend *backend) -{ - ClutterDeviceManager *manager = clutter_device_manager_get_default (); - ClutterInputDevice *device = clutter_device_manager_get_core_device (manager, CLUTTER_POINTER_DEVICE); - MetaMonitorInfo *monitors, *primary; - unsigned int n_monitors; - ClutterPoint point; - - if (!clutter_input_device_get_coords (device, NULL, &point)) - return; - - monitors = meta_monitor_manager_get_monitor_infos (monitor_manager, &n_monitors); - - /* if we're inside a monitor, we're fine */ - if (meta_monitor_manager_get_monitor_at_point (monitor_manager, point.x, point.y) >= 0) - return; - - /* warp the pointer to the primary monitor so it isn't lost */ - primary = &monitors[meta_monitor_manager_get_primary_index (monitor_manager)]; - meta_backend_warp_pointer (backend, - primary->rect.x + primary->rect.width / 2, - primary->rect.y + primary->rect.height / 2); -} - static void meta_backend_native_post_init (MetaBackend *backend) { - MetaMonitorManager *monitor_manager; ClutterDeviceManager *manager = clutter_device_manager_get_default (); META_BACKEND_CLASS (meta_backend_native_parent_class)->post_init (backend); clutter_evdev_set_pointer_constrain_callback (manager, pointer_constrain_callback, NULL, NULL); - - monitor_manager = meta_backend_get_monitor_manager (backend); - g_signal_connect_object (monitor_manager, "monitors-changed", - G_CALLBACK (on_monitors_changed), backend, G_CONNECT_AFTER); - - /* make sure the pointer is in the visible area after init */ - on_monitors_changed (monitor_manager, backend); } static MetaIdleMonitor *