[mutter/gnome-3-8] screen: Allow reusing the current position when quering the monitor



commit 79ea9f0b0f8d08ed6c819df834848942ae65afb7
Author: Adel Gadllah <adel gadllah gmail com>
Date:   Sun Jun 23 21:16:52 2013 +0200

    screen: Allow reusing the current position when quering the monitor
    
    Add new api (meta_screen_get_current_monitor_for_pos and
    meta_screen_get_current_monitor_info_for_pos) that allow querying the monitor
    without a roundtrip by reusing the passed in cursor position.

 src/core/screen-private.h |    3 ++
 src/core/screen.c         |   82 +++++++++++++++++++++++++++++++++------------
 src/meta/screen.h         |    3 ++
 3 files changed, 66 insertions(+), 22 deletions(-)
---
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index 56a0be4..83adb83 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -187,6 +187,9 @@ MetaWindow*   meta_screen_get_mouse_window     (MetaScreen                 *scre
                                                 MetaWindow                 *not_this_one);
 
 const MetaMonitorInfo* meta_screen_get_current_monitor_info   (MetaScreen    *screen);
+const MetaMonitorInfo* meta_screen_get_current_monitor_info_for_pos   (MetaScreen    *screen,
+                                                                       int x,
+                                                                       int y);
 const MetaMonitorInfo* meta_screen_get_monitor_for_rect   (MetaScreen    *screen,
                                                            MetaRectangle *rect);
 const MetaMonitorInfo* meta_screen_get_monitor_for_window (MetaScreen    *screen,
diff --git a/src/core/screen.c b/src/core/screen.c
index 3bab340..200724a 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -2216,6 +2216,65 @@ meta_screen_get_current_monitor_info (MetaScreen *screen)
     return &screen->monitor_infos[monitor_index];
 }
 
+const MetaMonitorInfo*
+meta_screen_get_current_monitor_info_for_pos (MetaScreen *screen,
+                                              int x,
+                                              int y)
+{
+    int monitor_index;
+    monitor_index = meta_screen_get_current_monitor_for_pos (screen, x, y);
+    return &screen->monitor_infos[monitor_index];
+}
+
+
+/**
+ * meta_screen_get_current_monitor_for_pos:
+ * @screen: a #MetaScreen
+ * @x: The x coordinate
+ * @y: The y coordinate
+ *
+ * Gets the index of the monitor that contains the passed coordinates.
+ *
+ * Return value: a monitor index
+ */
+int
+meta_screen_get_current_monitor_for_pos (MetaScreen *screen,
+                                         int x,
+                                         int y)
+{
+  if (screen->n_monitor_infos == 1)
+    return 0;
+  else if (screen->display->monitor_cache_invalidated)
+    {
+      int i;
+      MetaRectangle pointer_position;
+      pointer_position.x = x;
+      pointer_position.y = y;
+      pointer_position.width = pointer_position.height = 1;
+
+      screen->display->monitor_cache_invalidated = FALSE;
+      screen->last_monitor_index = 0;
+
+      for (i = 0; i < screen->n_monitor_infos; i++)
+        {
+          if (meta_rectangle_contains_rect (&screen->monitor_infos[i].rect,
+                                            &pointer_position))
+            {
+              screen->last_monitor_index = i;
+              break;
+            }
+        }
+
+      meta_topic (META_DEBUG_XINERAMA,
+                  "Rechecked current monitor, now %d\n",
+                  screen->last_monitor_index);
+
+    }
+
+    return screen->last_monitor_index;
+}
+
+
 /**
  * meta_screen_get_current_monitor:
  * @screen: a #MetaScreen
@@ -2241,11 +2300,7 @@ meta_screen_get_current_monitor (MetaScreen *screen)
       XIButtonState buttons;
       XIModifierState mods;
       XIGroupState group;
-      int i;
-      MetaRectangle pointer_position;
 
-      screen->display->monitor_cache_invalidated = FALSE;
-      
       XIQueryPointer (screen->display->xdisplay,
                       META_VIRTUAL_CORE_POINTER_ID,
                       screen->xroot,
@@ -2260,24 +2315,7 @@ meta_screen_get_current_monitor (MetaScreen *screen)
                       &group);
       free (buttons.mask);
 
-      pointer_position.x = root_x_return;
-      pointer_position.y = root_y_return;
-      pointer_position.width = pointer_position.height = 1;
-
-      screen->last_monitor_index = 0;
-      for (i = 0; i < screen->n_monitor_infos; i++)
-        {
-          if (meta_rectangle_contains_rect (&screen->monitor_infos[i].rect,
-                                            &pointer_position))
-            {
-              screen->last_monitor_index = i;
-              break;
-            }
-        }
-      
-      meta_topic (META_DEBUG_XINERAMA,
-                  "Rechecked current monitor, now %d\n",
-                  screen->last_monitor_index);
+      meta_screen_get_current_monitor_for_pos (screen, root_x_return, root_y_return);
     }
 
   return screen->last_monitor_index;
diff --git a/src/meta/screen.h b/src/meta/screen.h
index 8c120fa..aec9afa 100644
--- a/src/meta/screen.h
+++ b/src/meta/screen.h
@@ -78,6 +78,9 @@ MetaWorkspace * meta_screen_get_active_workspace (MetaScreen *screen);
 int  meta_screen_get_n_monitors       (MetaScreen    *screen);
 int  meta_screen_get_primary_monitor  (MetaScreen    *screen);
 int  meta_screen_get_current_monitor  (MetaScreen    *screen);
+int  meta_screen_get_current_monitor_for_pos  (MetaScreen    *screen,
+                                               int x,
+                                               int y);
 void meta_screen_get_monitor_geometry (MetaScreen    *screen,
                                        int            monitor,
                                        MetaRectangle *geometry);


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