[mutter/wip/multitouchr: 42/73] screen: make "monitor under pointer" logic work for several devices



commit e138726ded34659af674f0a7d7cfc8ce8ed2efb0
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Jul 3 21:29:12 2011 +0200

    screen: make "monitor under pointer" logic work for several devices

 src/core/keybindings.c    |    4 +++-
 src/core/place.c          |   22 +++++++++++-----------
 src/core/screen-private.h |    3 ++-
 src/core/screen.c         |   37 +++++++++++++++++++------------------
 src/core/window-private.h |    3 ++-
 src/core/window.c         |   11 ++++++-----
 src/meta/screen.h         |    3 ++-
 7 files changed, 45 insertions(+), 38 deletions(-)
---
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 056be30..6f7d60e 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -3378,6 +3378,8 @@ handle_toggle_tiled (MetaDisplay    *display,
                      gpointer        dummy)
 {
   MetaTileMode mode = binding->handler->data;
+  MetaDevice *device = meta_input_event_get_device (display, event);
+  MetaDevice *pointer = meta_device_get_paired_device (device);
 
   if ((META_WINDOW_TILED_LEFT (window) && mode == META_TILE_LEFT) ||
       (META_WINDOW_TILED_RIGHT (window) && mode == META_TILE_RIGHT))
@@ -3394,7 +3396,7 @@ handle_toggle_tiled (MetaDisplay    *display,
         meta_window_unmaximize (window, META_MAXIMIZE_VERTICAL |
                                         META_MAXIMIZE_HORIZONTAL);
     }
-  else if (meta_window_can_tile_side_by_side (window))
+  else if (meta_window_can_tile_side_by_side (window, pointer))
     {
       window->tile_monitor_number = window->monitor->number;
       window->tile_mode = mode;
diff --git a/src/core/place.c b/src/core/place.c
index ec28c11..ac141ea 100644
--- a/src/core/place.c
+++ b/src/core/place.c
@@ -90,6 +90,7 @@ northwestcmp (gconstpointer a, gconstpointer b)
 
 static void
 find_next_cascade (MetaWindow *window,
+                   MetaDevice *pointer,
                    MetaFrameBorders *borders,
                    /* visible windows on relevant workspaces */
                    GList      *windows,
@@ -136,7 +137,7 @@ find_next_cascade (MetaWindow *window,
    * of NW corner of window frame.
    */
 
-  current = meta_screen_get_current_monitor (window->screen);
+  current = meta_screen_get_current_monitor (window->screen, pointer);
   meta_window_get_work_area_for_monitor (window, current, &work_area);
 
   cascade_x = MAX (0, work_area.x);
@@ -667,6 +668,7 @@ meta_window_place (MetaWindow        *window,
 {
   GList *windows;
   const MetaMonitorInfo *xi;
+  MetaDevice *pointer, *keyboard;
 
   /* frame member variables should NEVER be used in here, only
    * MetaFrameBorders. But remember borders == NULL
@@ -678,7 +680,9 @@ meta_window_place (MetaWindow        *window,
   meta_topic (META_DEBUG_PLACEMENT, "Placing window %s\n", window->desc);
 
   windows = NULL;
-  
+  pointer = meta_window_guess_grab_pointer (window);
+  keyboard = meta_device_get_paired_device (pointer);
+
   switch (window->type)
     {
       /* Run placement algorithm on these. */
@@ -822,7 +826,7 @@ meta_window_place (MetaWindow        *window,
       int w, h;
 
       /* Warning, this function is a round trip! */
-      xi = meta_screen_get_current_monitor_info (window->screen);
+      xi = meta_screen_get_current_monitor_info (window->screen, pointer);
 
       w = xi->rect.width;
       h = xi->rect.height;
@@ -867,8 +871,8 @@ meta_window_place (MetaWindow        *window,
   }
 
   /* Warning, this is a round trip! */
-  xi = meta_screen_get_current_monitor_info (window->screen);
-  
+  xi = meta_screen_get_current_monitor_info (window->screen, pointer);
+
   /* "Origin" placement algorithm */
   x = xi->rect.x;
   y = xi->rect.y;
@@ -906,8 +910,8 @@ meta_window_place (MetaWindow        *window,
   /* If no placement has been done, revert to cascade to avoid 
    * fully overlapping window (e.g. starting multiple terminals)
    * */
-  if (x == xi->rect.x && y == xi->rect.y)  
-    find_next_cascade (window, borders, windows, x, y, &x, &y);
+  if (x == xi->rect.x && y == xi->rect.y)
+    find_next_cascade (window, pointer, borders, windows, x, y, &x, &y);
 
  done_check_denied_focus:
   /* If the window is being denied focus and isn't a transient of the
@@ -920,12 +924,8 @@ meta_window_place (MetaWindow        *window,
       gboolean       found_fit;
       MetaWindow    *focus_window;
       MetaRectangle  overlap;
-      MetaDevice    *pointer, *keyboard;
       MetaFocusInfo *focus_info;
 
-      pointer = meta_window_guess_grab_pointer (window);
-      keyboard = meta_device_get_paired_device (pointer);
-
       focus_info = meta_display_get_focus_info (window->display, keyboard);
       g_assert (focus_info != NULL);
 
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index 4576f28..fe6cd3f 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -184,7 +184,8 @@ void          meta_screen_tile_preview_hide            (MetaScreen    *screen);
 MetaWindow*   meta_screen_get_mouse_window     (MetaScreen                 *screen,
                                                 MetaWindow                 *not_this_one);
 
-const MetaMonitorInfo* meta_screen_get_current_monitor_info   (MetaScreen    *screen);
+const MetaMonitorInfo* meta_screen_get_current_monitor_info   (MetaScreen    *screen,
+                                                               MetaDevice    *pointer);
 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 a5dbbea..0860e92 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -41,6 +41,7 @@
 #include "xprops.h"
 #include <meta/compositor.h>
 #include "mutter-enum-types.h"
+#include "device-pointer.h"
 
 #include <X11/extensions/Xinerama.h>
 
@@ -2071,6 +2072,7 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
   const MetaMonitorInfo* current;
   const MetaMonitorInfo* tmp;
   GQueue* monitor_queue;
+  MetaDevice *pointer;
   int* visited;
   int cur = 0;
   int i;
@@ -2078,6 +2080,9 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
   *n_monitors = screen->n_monitor_infos;
   *monitors_list = g_new (int, screen->n_monitor_infos);
 
+  pointer = meta_device_map_lookup (screen->display->device_map,
+                                    META_CORE_POINTER_ID);
+
   /* we calculate a natural ordering by which to choose monitors for
    * window placement.  We start at the current monitor, and perform
    * a breadth-first search of the monitors starting from that
@@ -2092,7 +2097,7 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
       visited[i] = FALSE;
     }
 
-  current = meta_screen_get_current_monitor_info (screen);
+  current = meta_screen_get_current_monitor_info (screen, pointer);
   monitor_queue = g_queue_new ();
   g_queue_push_tail (monitor_queue, (gpointer) current);
   visited[current->number] = TRUE;
@@ -2159,11 +2164,12 @@ meta_screen_get_natural_monitor_list (MetaScreen *screen,
 }
 
 const MetaMonitorInfo*
-meta_screen_get_current_monitor_info (MetaScreen *screen)
+meta_screen_get_current_monitor_info (MetaScreen *screen,
+                                      MetaDevice *pointer)
 {
-    int monitor_index;
-    monitor_index = meta_screen_get_current_monitor (screen);
-    return &screen->monitor_infos[monitor_index];
+  int monitor_index;
+  monitor_index = meta_screen_get_current_monitor (screen, pointer);
+  return &screen->monitor_infos[monitor_index];
 }
 
 /**
@@ -2175,7 +2181,8 @@ meta_screen_get_current_monitor_info (MetaScreen *screen)
  * Return value: a monitor index
  */
 int
-meta_screen_get_current_monitor (MetaScreen *screen)
+meta_screen_get_current_monitor (MetaScreen *screen,
+                                 MetaDevice *pointer)
 {
   if (screen->n_monitor_infos == 1)
     return 0;
@@ -2185,24 +2192,18 @@ meta_screen_get_current_monitor (MetaScreen *screen)
   
   if (screen->display->monitor_cache_invalidated)
     {
-      Window root_return, child_return;
-      int win_x_return, win_y_return;
-      unsigned int mask_return;
       int i;
       MetaRectangle pointer_position;
       
       screen->display->monitor_cache_invalidated = FALSE;
       
       pointer_position.width = pointer_position.height = 1;
-      XQueryPointer (screen->display->xdisplay,
-                     screen->xroot,
-                     &root_return,
-                     &child_return,
-                     &pointer_position.x,
-                     &pointer_position.y,
-                     &win_x_return,
-                     &win_y_return,
-                     &mask_return);
+      meta_device_pointer_query_position (META_DEVICE_POINTER (pointer),
+                                          screen->xroot,
+                                          NULL, NULL,
+                                          &pointer_position.x,
+                                          &pointer_position.y,
+                                          NULL, NULL, NULL);
 
       screen->last_monitor_index = 0;
       for (i = 0; i < screen->n_monitor_infos; i++)
diff --git a/src/core/window-private.h b/src/core/window-private.h
index 68015fb..f06c639 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -659,7 +659,8 @@ void meta_window_propagate_focus_appearance (MetaWindow *window,
                                              gboolean    focused);
 
 gboolean meta_window_should_attach_to_parent (MetaWindow *window);
-gboolean meta_window_can_tile_side_by_side   (MetaWindow *window);
+gboolean meta_window_can_tile_side_by_side   (MetaWindow *window,
+                                              MetaDevice *pointer);
 
 void meta_window_compute_tile_match (MetaWindow *window);
 
diff --git a/src/core/window.c b/src/core/window.c
index 1eeafd4..84317b2 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -3724,7 +3724,8 @@ meta_window_can_tile_maximized (MetaWindow *window)
 }
 
 gboolean
-meta_window_can_tile_side_by_side (MetaWindow *window)
+meta_window_can_tile_side_by_side (MetaWindow *window,
+                                   MetaDevice *pointer)
 {
   int monitor;
   MetaRectangle tile_area;
@@ -3733,7 +3734,7 @@ meta_window_can_tile_side_by_side (MetaWindow *window)
   if (!meta_window_can_tile_maximized (window))
     return FALSE;
 
-  monitor = meta_screen_get_current_monitor (window->screen);
+  monitor = meta_screen_get_current_monitor (window->screen, pointer);
   meta_window_get_work_area_for_monitor (window, monitor, &tile_area);
 
   /* Do not allow tiling in portrait orientation */
@@ -8778,7 +8779,7 @@ update_move (MetaWindow  *window,
        * refers to the monitor which contains the largest part of the window,
        * the latter to the one where the pointer is located.
        */
-      monitor = meta_screen_get_current_monitor_info (window->screen);
+      monitor = meta_screen_get_current_monitor_info (window->screen, device);
       meta_window_get_work_area_for_monitor (window,
                                              monitor->number,
                                              &work_area);
@@ -8786,10 +8787,10 @@ update_move (MetaWindow  *window,
       /* Check if the cursor is in a position which triggers tiling
        * and set tile_mode accordingly.
        */
-      if (meta_window_can_tile_side_by_side (window) &&
+      if (meta_window_can_tile_side_by_side (window, device) &&
           x >= monitor->rect.x && x < (work_area.x + shake_threshold))
         window->tile_mode = META_TILE_LEFT;
-      else if (meta_window_can_tile_side_by_side (window) &&
+      else if (meta_window_can_tile_side_by_side (window, device) &&
                x >= work_area.x + work_area.width - shake_threshold &&
                x < (monitor->rect.x + monitor->rect.width))
         window->tile_mode = META_TILE_RIGHT;
diff --git a/src/meta/screen.h b/src/meta/screen.h
index 4fd2391..b5a69e7 100644
--- a/src/meta/screen.h
+++ b/src/meta/screen.h
@@ -77,7 +77,8 @@ 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  (MetaScreen    *screen,
+                                       MetaDevice    *pointer);
 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]