[mutter/wayland] Use MetaCursorTracker to query the pointer position



commit bee59ec0e1bc426143f9553d0629dfe9d495775a
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sun Mar 2 23:27:50 2014 +0100

    Use MetaCursorTracker to query the pointer position
    
    Functionally equivalent in the X11 case, but also correct for
    Wayland (where the X server doesn't have the updated pointer
    position).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=725525

 src/core/meta-cursor-tracker.c |   19 +++++++++-----
 src/core/screen.c              |   54 ++++++---------------------------------
 src/core/window-x11.c          |   31 ++++++-----------------
 src/core/window.c              |   28 ++++++--------------
 4 files changed, 37 insertions(+), 95 deletions(-)
---
diff --git a/src/core/meta-cursor-tracker.c b/src/core/meta-cursor-tracker.c
index 32e8608..250d07e 100644
--- a/src/core/meta-cursor-tracker.c
+++ b/src/core/meta-cursor-tracker.c
@@ -1076,10 +1076,12 @@ get_pointer_position_gdk (int         *x,
   gmanager = gdk_display_get_device_manager (gdk_display_get_default ());
   gdevice = gdk_device_manager_get_client_pointer (gmanager);
 
-  gdk_device_get_position (gdevice, &gscreen, x, y);
-  gdk_device_get_state (gdevice,
-                        gdk_screen_get_root_window (gscreen),
-                        NULL, (GdkModifierType*)mods);
+  if (x || y)
+    gdk_device_get_position (gdevice, &gscreen, x, y);
+  if (mods)
+    gdk_device_get_state (gdevice,
+                          gdk_screen_get_root_window (gscreen),
+                          NULL, (GdkModifierType*)mods);
 }
 
 static void
@@ -1095,9 +1097,12 @@ get_pointer_position_clutter (int         *x,
   cdevice = clutter_device_manager_get_core_device (cmanager, CLUTTER_POINTER_DEVICE);
 
   clutter_input_device_get_coords (cdevice, NULL, &point);
-  *x = point.x;
-  *y = point.y;
-  *mods = clutter_input_device_get_modifier_state (cdevice);
+  if (x)
+    *x = point.x;
+  if (y)
+    *y = point.y;
+  if (mods)
+    *mods = clutter_input_device_get_modifier_state (cdevice);
 }
 
 void
diff --git a/src/core/screen.c b/src/core/screen.c
index cf127ac..f1700c5 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -1514,38 +1514,19 @@ meta_screen_get_mouse_window (MetaScreen  *screen,
                               MetaWindow  *not_this_one)
 {
   MetaWindow *window;
-  Window root_return, child_return;
-  double root_x_return, root_y_return;
-  double win_x_return, win_y_return;
-  XIButtonState buttons;
-  XIModifierState mods;
-  XIGroupState group;
+  int x, y;
 
   if (not_this_one)
     meta_topic (META_DEBUG_FOCUS,
                 "Focusing mouse window excluding %s\n", not_this_one->desc);
 
-  meta_error_trap_push (screen->display);
-  XIQueryPointer (screen->display->xdisplay,
-                  META_VIRTUAL_CORE_POINTER_ID,
-                  screen->xroot,
-                  &root_return,
-                  &child_return,
-                  &root_x_return,
-                  &root_y_return,
-                  &win_x_return,
-                  &win_y_return,
-                  &buttons,
-                  &mods,
-                  &group);
-  meta_error_trap_pop (screen->display);
-  free (buttons.mask);
+  meta_cursor_tracker_get_pointer (screen->cursor_tracker,
+                                   &x, &y, NULL);
 
   window = meta_stack_get_default_focus_window_at_point (screen->stack,
                                                          screen->active_workspace,
                                                          not_this_one,
-                                                         root_x_return,
-                                                         root_y_return);
+                                                         x, y);
 
   return window;
 }
@@ -1827,28 +1808,11 @@ meta_screen_get_current_monitor (MetaScreen *screen)
   
   if (screen->display->monitor_cache_invalidated)
     {
-      Window root_return, child_return;
-      double win_x_return, win_y_return;
-      double root_x_return, root_y_return;
-      XIButtonState buttons;
-      XIModifierState mods;
-      XIGroupState group;
-
-      XIQueryPointer (screen->display->xdisplay,
-                      META_VIRTUAL_CORE_POINTER_ID,
-                      screen->xroot,
-                      &root_return,
-                      &child_return,
-                      &root_x_return,
-                      &root_y_return,
-                      &win_x_return,
-                      &win_y_return,
-                      &buttons,
-                      &mods,
-                      &group);
-      free (buttons.mask);
-
-      meta_screen_get_current_monitor_for_pos (screen, root_x_return, root_y_return);
+      int x, y;
+
+      meta_cursor_tracker_get_pointer (screen->cursor_tracker,
+                                       &x, &y, NULL);
+      meta_screen_get_current_monitor_for_pos (screen, x, y);
     }
 
   return screen->last_monitor_index;
diff --git a/src/core/window-x11.c b/src/core/window-x11.c
index 6c1e7e2..1d47345 100644
--- a/src/core/window-x11.c
+++ b/src/core/window-x11.c
@@ -38,6 +38,7 @@
 #include <meta/common.h>
 #include <meta/errors.h>
 #include <meta/prefs.h>
+#include <meta/meta-cursor-tracker.h>
 
 #include "window-private.h"
 #include "window-props.h"
@@ -673,35 +674,19 @@ meta_window_x11_property_notify (MetaWindow *window,
 static int
 query_pressed_buttons (MetaWindow *window)
 {
-  double x, y, query_root_x, query_root_y;
-  Window root, child;
-  XIButtonState buttons;
-  XIModifierState mods;
-  XIGroupState group;
+  ClutterModifierType mods;
   int button = 0;
 
-  meta_error_trap_push (window->display);
-  XIQueryPointer (window->display->xdisplay,
-                  META_VIRTUAL_CORE_POINTER_ID,
-                  window->xwindow,
-                  &root, &child,
-                  &query_root_x, &query_root_y,
-                  &x, &y,
-                  &buttons, &mods, &group);
-
-  if (meta_error_trap_pop_with_return (window->display) != Success)
-    goto out;
-
-  if (XIMaskIsSet (buttons.mask, Button1))
+  meta_cursor_tracker_get_pointer (window->screen->cursor_tracker,
+                                   NULL, NULL, &mods);
+
+  if (mods & CLUTTER_BUTTON1_MASK)
     button |= 1 << 1;
-  if (XIMaskIsSet (buttons.mask, Button2))
+  if (mods & CLUTTER_BUTTON2_MASK)
     button |= 1 << 2;
-  if (XIMaskIsSet (buttons.mask, Button3))
+  if (mods & CLUTTER_BUTTON3_MASK)
     button |= 1 << 3;
 
-  free (buttons.mask);
-
- out:
   return button;
 }
 
diff --git a/src/core/window.c b/src/core/window.c
index b506634..a530a0c 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -10343,25 +10343,15 @@ window_focus_on_pointer_rest_callback (gpointer data)
   MetaWindow *window = focus_data->window;
   MetaDisplay *display = window->display;
   MetaScreen *screen = window->screen;
-  Window root, child;
-  double root_x, root_y, x, y;
+  int root_x, root_y;
   guint32 timestamp;
-  XIButtonState buttons;
-  XIModifierState mods;
-  XIGroupState group;
+  ClutterActor *child;
 
   if (meta_prefs_get_focus_mode () == G_DESKTOP_FOCUS_MODE_CLICK)
     goto out;
 
-  meta_error_trap_push (display);
-  XIQueryPointer (display->xdisplay,
-                  META_VIRTUAL_CORE_POINTER_ID,
-                  screen->xroot,
-                  &root, &child,
-                  &root_x, &root_y, &x, &y,
-                  &buttons, &mods, &group);
-  meta_error_trap_pop (display);
-  free (buttons.mask);
+  meta_cursor_tracker_get_pointer (screen->cursor_tracker,
+                                   &root_x, &root_y, NULL);
 
   if (root_x != focus_data->pointer_x ||
       root_y != focus_data->pointer_y)
@@ -10371,17 +10361,15 @@ window_focus_on_pointer_rest_callback (gpointer data)
       return TRUE;
     }
 
-  /* Explicitly check for the overlay window, as get_focus_window_at_point()
-   * may return windows that extend underneath the chrome (like
-   * override-redirect or DESKTOP windows)
-   */
-  if (child == meta_get_overlay_window (screen))
+  child = clutter_stage_get_actor_at_pos (CLUTTER_STAGE (clutter_stage_get_default ()),
+                                          CLUTTER_PICK_REACTIVE, root_x, root_y);
+  if (!META_IS_SURFACE_ACTOR (child))
     goto out;
 
   window =
     meta_stack_get_default_focus_window_at_point (screen->stack,
                                                   screen->active_workspace,
-                                                  None, root_x, root_y);
+                                                  NULL, root_x, root_y);
 
   if (window == NULL)
     goto out;


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