[mutter] backend-native: Ensure the pointer is visible on monitors-changed



commit 9a3b178da1a39b1cb19841beac31c907fd65b856
Author: Rui Matos <tiagomatos gmail com>
Date:   Wed Feb 25 17:01:10 2015 +0100

    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 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index 5d1f0b1..92031a6 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -180,14 +180,45 @@ pointer_constrain_callback (ClutterInputDevice *device,
 }
 
 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 *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]