From 9a3b178da1a39b1cb19841beac31c907fd65b856 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Wed, 25 Feb 2015 17:01:10 +0100 Subject: [PATCH] backend-native: Ensure the pointer is visible on monitors-changed Otherwise the pointer might be "lost" outside the visible area. Note that the constraining code only ensures the pointer doesn't leave the visible area but if the pointer is already outside because the rug was pulled under it then it doesn't do anything. https://bugzilla.gnome.org/show_bug.cgi?id=745121 --- src/backends/native/meta-backend-native.c | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 5d1f0b149..92031a60d 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -179,15 +179,46 @@ 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 (check_all_screen_monitors (monitors, n_monitors, point.x, point.y)) + 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); } static MetaIdleMonitor *