[gtk+/xi2: 973/1239] GdkDeviceXI2: Use XIQueryPointer, seems to be fixed in Xorg.



commit 92b15bd5098f96fb077d29824bda67f373b839f2
Author: Carlos Garnacho <carlos gnome org>
Date:   Mon Aug 31 20:54:54 2009 +0200

    GdkDeviceXI2: Use XIQueryPointer, seems to be fixed in Xorg.
    
    Code to translate state to GdkModifierType has been moved to
    gdkdevice-xi2.[ch].

 gdk/x11/gdkdevice-xi2.c        |  127 +++++++++++++++++++++++++++++-----------
 gdk/x11/gdkdevice-xi2.h        |    2 +
 gdk/x11/gdkdevicemanager-xi2.c |   58 ++-----------------
 3 files changed, 100 insertions(+), 87 deletions(-)
---
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index 39e2a94..864f2ee 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -22,7 +22,7 @@
 #include "gdkintl.h"
 #include "gdkx.h"
 
-
+#define BIT_IS_ON(ptr, bit) (((unsigned char *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
 #define GDK_DEVICE_XI2_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDK_TYPE_DEVICE_XI2, GdkDeviceXI2Private))
 
 typedef struct GdkDeviceXI2Private GdkDeviceXI2Private;
@@ -226,11 +226,10 @@ gdk_device_xi2_query_state (GdkDevice        *device,
   GdkDisplay *display;
   GdkDeviceXI2Private *priv;
   Window xroot_window, xchild_window;
-  int xroot_x, xroot_y, xwin_x, xwin_y;
+  gdouble xroot_x, xroot_y, xwin_x, xwin_y;
   XIButtonState button_state;
   XIModifierState mod_state;
   XIGroupState group_state;
-  unsigned int xmask;
 
   if (!window || GDK_WINDOW_DESTROYED (window))
     return FALSE;
@@ -238,16 +237,18 @@ gdk_device_xi2_query_state (GdkDevice        *device,
   priv = GDK_DEVICE_XI2_GET_PRIVATE (device);
   display = gdk_drawable_get_display (window);
 
-  /* FIXME: XIQueryPointer crashes ATM, use when Xorg is fixed */
-  if (!XQueryPointer (GDK_WINDOW_XDISPLAY (window),
-                      GDK_WINDOW_XID (window),
-                      &xroot_window,
-                      &xchild_window,
-                      &xroot_x,
-                      &xroot_y,
-                      &xwin_x,
-                      &xwin_y,
-                      &xmask))
+  if (!XIQueryPointer (GDK_WINDOW_XDISPLAY (window),
+                       priv->device_id,
+                       GDK_WINDOW_XID (window),
+                       &xroot_window,
+                       &xchild_window,
+                       &xroot_x,
+                       &xroot_y,
+                       &xwin_x,
+                       &xwin_y,
+                       &button_state,
+                       &mod_state,
+                       &group_state))
     {
       return FALSE;
     }
@@ -259,19 +260,19 @@ gdk_device_xi2_query_state (GdkDevice        *device,
     *child_window = gdk_window_lookup_for_display (display, xchild_window);
 
   if (root_x)
-    *root_x = xroot_x;
+    *root_x = (gint) xroot_x;
 
   if (root_y)
-    *root_y = xroot_y;
+    *root_y = (gint) xroot_y;
 
   if (win_x)
-    *win_x = xwin_x;
+    *win_x = (gint) xwin_x;
 
   if (win_y)
-    *win_y = xwin_y;
+    *win_y = (gint) xwin_y;
 
   if (mask)
-    *mask = xmask;
+    *mask = gdk_device_xi2_translate_state (&mod_state, &button_state);
 
   return TRUE;
 }
@@ -343,14 +344,18 @@ gdk_device_xi2_window_at_position (GdkDevice       *device,
                                    gint            *win_y,
                                    GdkModifierType *mask)
 {
+  GdkDeviceXI2Private *priv;
   GdkDisplay *display;
   GdkScreen *screen;
   Display *xdisplay;
   GdkWindow *window;
   Window xwindow, root, child, last = None;
-  int xroot_x, xroot_y, xwin_x, xwin_y;
-  unsigned int xmask;
+  gdouble xroot_x, xroot_y, xwin_x, xwin_y;
+  XIButtonState button_state;
+  XIModifierState mod_state;
+  XIGroupState group_state;
 
+  priv = GDK_DEVICE_XI2_GET_PRIVATE (device);
   display = gdk_device_get_display (device);
   screen = gdk_display_get_default_screen (display);
 
@@ -364,12 +369,15 @@ gdk_device_xi2_window_at_position (GdkDevice       *device,
   xdisplay = GDK_SCREEN_XDISPLAY (screen);
   xwindow = GDK_SCREEN_XROOTWIN (screen);
 
-  /* FIXME: XIQueryPointer crashes ATM, use when Xorg is fixed */
-  XQueryPointer (xdisplay, xwindow,
-                 &root, &child,
-                 &xroot_x, &xroot_y,
-                 &xwin_x, &xwin_y,
-                 &xmask);
+  XIQueryPointer (xdisplay,
+                  priv->device_id,
+                  xwindow,
+                  &root, &child,
+                  &xroot_x, &xroot_y,
+                  &xwin_x, &xwin_y,
+                  &button_state,
+                  &mod_state,
+                  &group_state);
 
   if (root == xwindow)
     xwindow = child;
@@ -379,11 +387,15 @@ gdk_device_xi2_window_at_position (GdkDevice       *device,
   while (xwindow)
     {
       last = xwindow;
-      XQueryPointer (xdisplay, xwindow,
-                     &root, &xwindow,
-                     &xroot_x, &xroot_y,
-                     &xwin_x, &xwin_y,
-                     &xmask);
+      XIQueryPointer (xdisplay,
+                      priv->device_id,
+                      xwindow,
+                      &root, &xwindow,
+                      &xroot_x, &xroot_y,
+                      &xwin_x, &xwin_y,
+                      &button_state,
+                      &mod_state,
+                      &group_state);
     }
 
   gdk_x11_display_ungrab (display);
@@ -391,13 +403,13 @@ gdk_device_xi2_window_at_position (GdkDevice       *device,
   window = gdk_window_lookup_for_display (display, last);
 
   if (win_x)
-    *win_x = (window) ? xwin_x : -1;
+    *win_x = (window) ? (gint) xwin_x : -1;
 
   if (win_y)
-    *win_y = (window) ? xwin_y : -1;
+    *win_y = (window) ? (gint) xwin_y : -1;
 
   if (mask)
-    *mask = xmask;
+    *mask = gdk_device_xi2_translate_state (&mod_state, &button_state);
 
   return window;
 }
@@ -457,3 +469,50 @@ gdk_device_xi2_translate_event_mask (GdkEventMask  event_mask,
 
   return mask;
 }
+
+guint
+gdk_device_xi2_translate_state (XIModifierState *mods_state,
+                                XIButtonState   *buttons_state)
+{
+  guint state = 0;
+
+  if (mods_state)
+    state = (guint) mods_state->effective;
+
+  if (buttons_state)
+    {
+      gint len, i;
+
+      /* We're only interested in the first 5 buttons */
+      len = MIN (5, buttons_state->mask_len * 8);
+
+      for (i = 0; i < len; i++)
+        {
+          if (!BIT_IS_ON (buttons_state->mask, i))
+            continue;
+
+          switch (i)
+            {
+            case 1:
+              state |= GDK_BUTTON1_MASK;
+              break;
+            case 2:
+              state |= GDK_BUTTON2_MASK;
+              break;
+            case 3:
+              state |= GDK_BUTTON3_MASK;
+              break;
+            case 4:
+              state |= GDK_BUTTON4_MASK;
+              break;
+            case 5:
+              state |= GDK_BUTTON5_MASK;
+              break;
+            default:
+              break;
+            }
+        }
+    }
+
+  return state;
+}
diff --git a/gdk/x11/gdkdevice-xi2.h b/gdk/x11/gdkdevice-xi2.h
index a55070a..2d2f031 100644
--- a/gdk/x11/gdkdevice-xi2.h
+++ b/gdk/x11/gdkdevice-xi2.h
@@ -48,6 +48,8 @@ GType gdk_device_xi2_get_type (void) G_GNUC_CONST;
 
 guchar * gdk_device_xi2_translate_event_mask (GdkEventMask  event_mask,
                                               int          *len);
+guint    gdk_device_xi2_translate_state      (XIModifierState *mods_state,
+                                              XIButtonState   *buttons_state);
 
 
 G_END_DECLS
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 7bddc9e..5785bfb 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -24,7 +24,6 @@
 #include "gdkkeysyms.h"
 #include "gdkx.h"
 
-#define BIT_IS_ON(ptr, bit) (((unsigned char *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
 #define HAS_FOCUS(toplevel) ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
 
 
@@ -472,53 +471,6 @@ translate_notify_type (int detail)
     }
 }
 
-static guint
-translate_state (XIModifierState *mods_state,
-                 XIButtonState   *buttons_state)
-{
-  guint state = 0;
-
-  if (mods_state)
-    state = (guint) mods_state->effective;
-
-  if (buttons_state)
-    {
-      gint len, i;
-
-      /* We're only interested in the first 5 buttons */
-      len = MIN (5, buttons_state->mask_len * 8);
-
-      for (i = 0; i < len; i++)
-        {
-          if (!BIT_IS_ON (buttons_state->mask, i))
-            continue;
-
-          switch (i)
-            {
-            case 1:
-              state |= GDK_BUTTON1_MASK;
-              break;
-            case 2:
-              state |= GDK_BUTTON2_MASK;
-              break;
-            case 3:
-              state |= GDK_BUTTON3_MASK;
-              break;
-            case 4:
-              state |= GDK_BUTTON4_MASK;
-              break;
-            case 5:
-              state |= GDK_BUTTON5_MASK;
-              break;
-            default:
-              break;
-            }
-        }
-    }
-
-  return state;
-}
-
 static gboolean
 set_screen_from_root (GdkDisplay *display,
 		      GdkEvent   *event,
@@ -879,7 +831,7 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
         event->key.window = window;
 
         event->key.time = xev->time;
-        event->key.state = translate_state (&xev->mods, &xev->buttons);
+        event->key.state = gdk_device_xi2_translate_state (&xev->mods, &xev->buttons);
         event->key.group = _gdk_x11_get_group_for_state (display, event->key.state);
 
         event->key.hardware_keycode = xev->detail;
@@ -937,7 +889,7 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
             event->scroll.device = g_hash_table_lookup (device_manager->id_table,
                                                         GUINT_TO_POINTER (xev->deviceid));
 
-            event->scroll.state = translate_state (&xev->mods, &xev->buttons);
+            event->scroll.state = gdk_device_xi2_translate_state (&xev->mods, &xev->buttons);
             break;
           default:
             event->button.type = (ev->evtype == XI_ButtonPress) ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE;
@@ -958,7 +910,7 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
                                                  event->button.window,
                                                  &xev->valuators);
 
-            event->button.state = translate_state (&xev->mods, &xev->buttons);
+            event->button.state = gdk_device_xi2_translate_state (&xev->mods, &xev->buttons);
             event->button.button = xev->detail;
           }
 
@@ -989,7 +941,7 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
         event->motion.device = g_hash_table_lookup (device_manager->id_table,
                                                     GINT_TO_POINTER (xev->deviceid));
 
-        event->motion.state = translate_state (&xev->mods, &xev->buttons);
+        event->motion.state = gdk_device_xi2_translate_state (&xev->mods, &xev->buttons);
 
         /* FIXME: There doesn't seem to be motion hints in XI */
         event->motion.is_hint = FALSE;
@@ -1022,7 +974,7 @@ gdk_device_manager_xi2_translate_event (GdkEventTranslator *translator,
 
         event->crossing.mode = translate_crossing_mode (xev->mode);
         event->crossing.detail = translate_notify_type (xev->detail);
-        event->crossing.state = translate_state (&xev->mods, &xev->buttons);
+        event->crossing.state = gdk_device_xi2_translate_state (&xev->mods, &xev->buttons);
       }
       break;
     case XI_FocusIn:



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