compositor: Use XInput2 to grab the pointer/keyboard

https://bugzilla.gnome.org/show_bug.cgi?id=688779
This commit is contained in:
Jasper St. Pierre 2012-11-20 16:59:20 -05:00
parent 946a42f13e
commit 55251aa986
3 changed files with 43 additions and 24 deletions

View File

@ -358,14 +358,23 @@ meta_begin_modal_for_plugin (MetaScreen *screen,
if ((options & META_MODAL_POINTER_ALREADY_GRABBED) == 0) if ((options & META_MODAL_POINTER_ALREADY_GRABBED) == 0)
{ {
result = XGrabPointer (xdpy, grab_window, unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
False, /* owner_events */ XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
(ButtonPressMask | ButtonReleaseMask |
EnterWindowMask | LeaveWindowMask | PointerMotionMask), XISetMask (mask.mask, XI_ButtonPress);
GrabModeAsync, GrabModeAsync, XISetMask (mask.mask, XI_ButtonRelease);
None, /* confine to */ XISetMask (mask.mask, XI_Enter);
XISetMask (mask.mask, XI_Leave);
XISetMask (mask.mask, XI_Motion);
result = XIGrabDevice (xdpy,
META_VIRTUAL_CORE_POINTER_ID,
grab_window,
timestamp,
cursor, cursor,
timestamp); XIGrabModeAsync, XIGrabModeAsync,
False, /* owner_events */
&mask);
if (result != Success) if (result != Success)
goto fail; goto fail;
@ -374,10 +383,20 @@ meta_begin_modal_for_plugin (MetaScreen *screen,
if ((options & META_MODAL_KEYBOARD_ALREADY_GRABBED) == 0) if ((options & META_MODAL_KEYBOARD_ALREADY_GRABBED) == 0)
{ {
result = XGrabKeyboard (xdpy, grab_window, unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
False, /* owner_events */ XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
GrabModeAsync, GrabModeAsync,
timestamp); XISetMask (mask.mask, XI_KeyPress);
XISetMask (mask.mask, XI_KeyRelease);
result = XIGrabDevice (xdpy,
META_VIRTUAL_CORE_KEYBOARD_ID,
grab_window,
timestamp,
None,
XIGrabModeAsync, XIGrabModeAsync,
False, /* owner_events */
&mask);
if (result != Success) if (result != Success)
goto fail; goto fail;
@ -397,9 +416,9 @@ meta_begin_modal_for_plugin (MetaScreen *screen,
fail: fail:
if (pointer_grabbed) if (pointer_grabbed)
XUngrabPointer (xdpy, timestamp); XIUngrabDevice (xdpy, META_VIRTUAL_CORE_POINTER_ID, timestamp);
if (keyboard_grabbed) if (keyboard_grabbed)
XUngrabKeyboard (xdpy, timestamp); XIUngrabDevice (xdpy, META_VIRTUAL_CORE_KEYBOARD_ID, timestamp);
return FALSE; return FALSE;
} }
@ -415,8 +434,8 @@ meta_end_modal_for_plugin (MetaScreen *screen,
g_return_if_fail (compositor->modal_plugin == plugin); g_return_if_fail (compositor->modal_plugin == plugin);
XUngrabPointer (xdpy, timestamp); XIUngrabDevice (xdpy, META_VIRTUAL_CORE_POINTER_ID, timestamp);
XUngrabKeyboard (xdpy, timestamp); XIUngrabDevice (xdpy, META_VIRTUAL_CORE_KEYBOARD_ID, timestamp);
display->grab_op = META_GRAB_OP_NONE; display->grab_op = META_GRAB_OP_NONE;
display->grab_window = NULL; display->grab_window = NULL;

View File

@ -74,10 +74,6 @@
#include <string.h> #include <string.h>
#include <unistd.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) \ #define GRAB_OP_IS_WINDOW_SWITCH(g) \
(g == META_GRAB_OP_KEYBOARD_TABBING_NORMAL || \ (g == META_GRAB_OP_KEYBOARD_TABBING_NORMAL || \
g == META_GRAB_OP_KEYBOARD_TABBING_DOCK || \ g == META_GRAB_OP_KEYBOARD_TABBING_DOCK || \
@ -1816,19 +1812,19 @@ get_input_event (MetaDisplay *display,
case XI_Motion: case XI_Motion:
case XI_ButtonPress: case XI_ButtonPress:
case XI_ButtonRelease: case XI_ButtonRelease:
if (((XIDeviceEvent *) input_event)->deviceid == VIRTUAL_CORE_POINTER_ID) if (((XIDeviceEvent *) input_event)->deviceid == META_VIRTUAL_CORE_POINTER_ID)
return input_event; return input_event;
case XI_KeyPress: case XI_KeyPress:
case XI_KeyRelease: case XI_KeyRelease:
if (((XIDeviceEvent *) input_event)->deviceid == VIRTUAL_CORE_KEYBOARD_ID) if (((XIDeviceEvent *) input_event)->deviceid == META_VIRTUAL_CORE_KEYBOARD_ID)
return input_event; return input_event;
case XI_FocusIn: case XI_FocusIn:
case XI_FocusOut: case XI_FocusOut:
if (((XIEnterEvent *) input_event)->deviceid == VIRTUAL_CORE_KEYBOARD_ID) if (((XIEnterEvent *) input_event)->deviceid == META_VIRTUAL_CORE_KEYBOARD_ID)
return input_event; return input_event;
case XI_Enter: case XI_Enter:
case XI_Leave: case XI_Leave:
if (((XIEnterEvent *) input_event)->deviceid == VIRTUAL_CORE_POINTER_ID) if (((XIEnterEvent *) input_event)->deviceid == META_VIRTUAL_CORE_POINTER_ID)
return input_event; return input_event;
default: default:
break; break;
@ -2877,7 +2873,7 @@ event_callback (XEvent *event,
break; break;
case XkbNewKeyboardNotify: case XkbNewKeyboardNotify:
case XkbMapNotify: case XkbMapNotify:
if (xkb_ev->device == VIRTUAL_CORE_KEYBOARD_ID) if (xkb_ev->device == META_VIRTUAL_CORE_KEYBOARD_ID)
meta_display_process_mapping_event (display, event); meta_display_process_mapping_event (display, event);
break; break;
} }

View File

@ -35,6 +35,10 @@
#include <glib.h> #include <glib.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
/* This is set in stone and also hard-coded in GDK. */
#define META_VIRTUAL_CORE_POINTER_ID 2
#define META_VIRTUAL_CORE_KEYBOARD_ID 3
typedef struct _MetaResizePopup MetaResizePopup; typedef struct _MetaResizePopup MetaResizePopup;
typedef enum typedef enum