[mutter/wip/xinput2b: 25/31] keybindings: Grab keyboard with XI2



commit bc3fe42dfbe676aab6c6c1e12cd815042836ee26
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Nov 20 17:11:13 2012 -0500

    keybindings: Grab keyboard with XI2
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688779

 src/core/keybindings.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 38ebae9..4be3cee 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -37,6 +37,7 @@
 #include "place.h"
 #include <meta/prefs.h>
 #include <meta/util.h>
+#include "core.h"
 
 #include <X11/keysym.h>
 #include <string.h>
@@ -1055,22 +1056,32 @@ grab_keyboard (MetaDisplay *display,
 {
   int result;
   int grab_status;
-  
+
+  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);
+
   /* Grab the keyboard, so we get key releases and all key
    * presses
    */
   meta_error_trap_push_with_return (display);
 
-  grab_status = XGrabKeyboard (display->xdisplay,
-                               xwindow, True,
-                               GrabModeAsync, GrabModeAsync,
-                               timestamp);
-  
-  if (grab_status != GrabSuccess)
+  grab_status = XIGrabDevice (display->xdisplay,
+                              VIRTUAL_CORE_KEYBOARD_ID,
+                              xwindow,
+                              timestamp,
+                              None,
+                              GrabModeAsync, GrabModeAsync,
+                              True, /* owner_events */
+                              &mask);
+
+  if (grab_status != Success)
     {
       meta_error_trap_pop_with_return (display);
       meta_topic (META_DEBUG_KEYBINDINGS,
-                  "XGrabKeyboard() returned failure status %s time %u\n",
+                  "XIGrabDevice() returned failure status %s time %u\n",
                   grab_status_to_string (grab_status),
                   timestamp);
       return FALSE;
@@ -1081,7 +1092,7 @@ grab_keyboard (MetaDisplay *display,
       if (result != Success)
         {
           meta_topic (META_DEBUG_KEYBINDINGS,
-                      "XGrabKeyboard() resulted in an error\n");
+                      "XIGrabDevice() resulted in an error\n");
           return FALSE;
         }
     }
@@ -1099,7 +1110,7 @@ ungrab_keyboard (MetaDisplay *display, guint32 timestamp)
   meta_topic (META_DEBUG_KEYBINDINGS,
               "Ungrabbing keyboard with timestamp %u\n",
               timestamp);
-  XUngrabKeyboard (display->xdisplay, timestamp);
+  XIUngrabDevice (display->xdisplay, VIRTUAL_CORE_KEYBOARD_ID, timestamp);
   meta_error_trap_pop (display);
 }
 



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