[mutter/wip/xinput2b: 11/19] compositor: Use XInput2 to grab the pointer/keyboard



commit 85992817956f3f547945898f3a03c40b626b6d78
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Nov 20 16:59:20 2012 -0500

    compositor: Use XInput2 to grab the pointer/keyboard
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688779

 src/compositor/compositor.c |   50 ++++++++++++++++++++++++++++++-------------
 src/core/core.h             |    3 ++
 src/core/display.c          |    6 +---
 3 files changed, 40 insertions(+), 19 deletions(-)
---
diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c
index c6a85aa..3427ee1 100644
--- a/src/compositor/compositor.c
+++ b/src/compositor/compositor.c
@@ -18,6 +18,7 @@
 #include "meta-background-actor-private.h"
 #include "window-private.h" /* to check window->hidden */
 #include "display-private.h" /* for meta_display_lookup_x_window() */
+#include "core.h"
 #include <X11/extensions/shape.h>
 #include <X11/extensions/Xcomposite.h>
 
@@ -358,14 +359,23 @@ meta_begin_modal_for_plugin (MetaScreen       *screen,
 
   if ((options & META_MODAL_POINTER_ALREADY_GRABBED) == 0)
     {
-      result = XGrabPointer (xdpy, grab_window,
-                             False, /* owner_events */
-                             (ButtonPressMask | ButtonReleaseMask |
-                              EnterWindowMask | LeaveWindowMask | PointerMotionMask),
-                             GrabModeAsync, GrabModeAsync,
-                             None, /* confine to */
+      unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
+      XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
+
+      XISetMask (mask.mask, XI_ButtonPress);
+      XISetMask (mask.mask, XI_ButtonRelease);
+      XISetMask (mask.mask, XI_Enter);
+      XISetMask (mask.mask, XI_Leave);
+      XISetMask (mask.mask, XI_Motion);
+
+      result = XIGrabDevice (xdpy,
+                             VIRTUAL_CORE_POINTER_ID,
+                             grab_window,
+                             timestamp,
                              cursor,
-                             timestamp);
+                             GrabModeAsync, GrabModeAsync,
+                             False, /* owner_events */
+                             &mask);
       if (result != Success)
         goto fail;
 
@@ -374,10 +384,20 @@ meta_begin_modal_for_plugin (MetaScreen       *screen,
 
   if ((options & META_MODAL_KEYBOARD_ALREADY_GRABBED) == 0)
     {
-      result = XGrabKeyboard (xdpy, grab_window,
-                              False, /* owner_events */
-                              GrabModeAsync, GrabModeAsync,
-                              timestamp);
+      unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
+      XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
+
+      XISetMask (mask.mask, XI_KeyPress);
+      XISetMask (mask.mask, XI_KeyRelease);
+
+      result = XIGrabDevice (xdpy,
+                             VIRTUAL_CORE_KEYBOARD_ID,
+                             grab_window,
+                             timestamp,
+                             None,
+                             GrabModeAsync, GrabModeAsync,
+                             False, /* owner_events */
+                             &mask);
 
       if (result != Success)
         goto fail;
@@ -397,9 +417,9 @@ meta_begin_modal_for_plugin (MetaScreen       *screen,
 
  fail:
   if (pointer_grabbed)
-    XUngrabPointer (xdpy, timestamp);
+    XIUngrabDevice (xdpy, VIRTUAL_CORE_POINTER_ID, timestamp);
   if (keyboard_grabbed)
-    XUngrabKeyboard (xdpy, timestamp);
+    XIUngrabDevice (xdpy, VIRTUAL_CORE_KEYBOARD_ID, timestamp);
 
   return FALSE;
 }
@@ -415,8 +435,8 @@ meta_end_modal_for_plugin (MetaScreen     *screen,
 
   g_return_if_fail (compositor->modal_plugin == plugin);
 
-  XUngrabPointer (xdpy, timestamp);
-  XUngrabKeyboard (xdpy, timestamp);
+  XIUngrabDevice (xdpy, VIRTUAL_CORE_POINTER_ID, timestamp);
+  XIUngrabDevice (xdpy, VIRTUAL_CORE_KEYBOARD_ID, timestamp);
 
   display->grab_op = META_GRAB_OP_NONE;
   display->grab_window = NULL;
diff --git a/src/core/core.h b/src/core/core.h
index 12451bd..9ce9c18 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -29,6 +29,9 @@
 #include <gdk/gdkx.h>
 #include <meta/common.h>
 
+#define VIRTUAL_CORE_POINTER_ID 2
+#define VIRTUAL_CORE_KEYBOARD_ID 3
+
 typedef enum
 {
   META_CORE_GET_END = 0,
diff --git a/src/core/display.c b/src/core/display.c
index 944dbc4..05d7e19 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -53,6 +53,8 @@
 #include <meta/compositor-mutter.h>
 #include <X11/Xatom.h>
 #include <X11/cursorfont.h>
+#include "core.h"
+
 #include "mutter-enum-types.h"
 
 #ifdef HAVE_RANDR
@@ -74,10 +76,6 @@
 #include <string.h>
 #include <unistd.h>
 
-/* This is set in stone and also hard-coded in GDK. */
-#define VIRTUAL_CORE_POINTER_ID 2
-#define VIRTUAL_CORE_KEYBOARD_ID 3
-
 #define GRAB_OP_IS_WINDOW_SWITCH(g)                     \
         (g == META_GRAB_OP_KEYBOARD_TABBING_NORMAL  ||  \
          g == META_GRAB_OP_KEYBOARD_TABBING_DOCK    ||  \



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