[mutter] keybindings: Grab keyboard with XI2



commit afcdfd158f9308f00c813c52615ed4a9d345684b
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 |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)
---
diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index 3821790..3ba2670 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -1055,22 +1055,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,
+                              META_VIRTUAL_CORE_KEYBOARD_ID,
+                              xwindow,
+                              timestamp,
+                              None,
+                              XIGrabModeAsync, XIGrabModeAsync,
+                              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 +1091,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 +1109,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, META_VIRTUAL_CORE_KEYBOARD_ID, timestamp);
   meta_error_trap_pop (display);
 }
 



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