[mutter] backends: Add meta_monitor_manager_get_monitor_at_point()



commit 8188cddcf7a4079924923a1d0885c2e5a8d581f3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 27 15:48:49 2015 +0100

    backends: Add meta_monitor_manager_get_monitor_at_point()
    
    This function returns the monitor_info index corresponding to the given
    coordinates, or -1 if none is found at that point. The native backend
    has been changed in places where it could make use of this function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=746896

 src/backends/meta-monitor-manager-private.h |    4 +++
 src/backends/meta-monitor-manager.c         |   24 ++++++++++++++++++++
 src/backends/native/meta-backend-native.c   |   31 +-------------------------
 3 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/src/backends/meta-monitor-manager-private.h b/src/backends/meta-monitor-manager-private.h
index bbfaf58..5a6740c 100644
--- a/src/backends/meta-monitor-manager-private.h
+++ b/src/backends/meta-monitor-manager-private.h
@@ -370,6 +370,10 @@ gboolean           meta_monitor_manager_get_monitor_matrix (MetaMonitorManager *
                                                             MetaOutput         *output,
                                                             gfloat              matrix[6]);
 
+gint               meta_monitor_manager_get_monitor_at_point (MetaMonitorManager *manager,
+                                                              gfloat              x,
+                                                              gfloat              y);
+
 /* Returns true if transform causes width and height to be inverted
    This is true for the odd transforms in the enum */
 static inline gboolean
diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c
index 0276ba5..7fa5139 100644
--- a/src/backends/meta-monitor-manager.c
+++ b/src/backends/meta-monitor-manager.c
@@ -1368,3 +1368,27 @@ meta_monitor_manager_get_monitor_for_output (MetaMonitorManager *manager,
 
   return -1;
 }
+
+gint
+meta_monitor_manager_get_monitor_at_point (MetaMonitorManager *manager,
+                                           gfloat              x,
+                                           gfloat              y)
+{
+  unsigned int i;
+
+  for (i = 0; i < manager->n_monitor_infos; i++)
+    {
+      MetaMonitorInfo *monitor = &manager->monitor_infos[i];
+      int left, right, top, bottom;
+
+      left = monitor->rect.x;
+      right = left + monitor->rect.width;
+      top = monitor->rect.y;
+      bottom = top + monitor->rect.height;
+
+      if ((x >= left) && (x < right) && (y >= top) && (y < bottom))
+       return i;
+    }
+
+  return -1;
+}
diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c
index b820bc8..9f2cb9b 100644
--- a/src/backends/native/meta-backend-native.c
+++ b/src/backends/native/meta-backend-native.c
@@ -84,31 +84,6 @@ constrain_to_barriers (ClutterInputDevice *device,
  *
  */
 
-static gboolean
-check_all_screen_monitors(MetaMonitorInfo *monitors,
-                         unsigned         n_monitors,
-                         float            x,
-                         float            y)
-{
-  unsigned int i;
-
-  for (i = 0; i < n_monitors; i++)
-    {
-      MetaMonitorInfo *monitor = &monitors[i];
-      int left, right, top, bottom;
-
-      left = monitor->rect.x;
-      right = left + monitor->rect.width;
-      top = monitor->rect.y;
-      bottom = top + monitor->rect.height;
-
-      if ((x >= left) && (x < right) && (y >= top) && (y < bottom))
-       return TRUE;
-    }
-
-  return FALSE;
-}
-
 static void
 constrain_all_screen_monitors (ClutterInputDevice *device,
                               MetaMonitorInfo    *monitors,
@@ -162,7 +137,6 @@ pointer_constrain_callback (ClutterInputDevice *device,
   MetaMonitorManager *monitor_manager;
   MetaMonitorInfo *monitors;
   unsigned int n_monitors;
-  gboolean ret;
 
   /* Constrain to barriers */
   constrain_to_barriers (device, time, new_x, new_y);
@@ -171,8 +145,7 @@ pointer_constrain_callback (ClutterInputDevice *device,
   monitors = meta_monitor_manager_get_monitor_infos (monitor_manager, &n_monitors);
 
   /* if we're moving inside a monitor, we're fine */
-  ret = check_all_screen_monitors(monitors, n_monitors, *new_x, *new_y);
-  if (ret == TRUE)
+  if (meta_monitor_manager_get_monitor_at_point (monitor_manager, *new_x, *new_y) >= 0)
     return;
 
   /* if we're trying to escape, clamp to the CRTC we're coming from */
@@ -195,7 +168,7 @@ on_monitors_changed (MetaMonitorManager *monitor_manager,
   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))
+  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 */


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