From 55251aa986fc034e131dff12f2f7693e9b8d0a2e Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 20 Nov 2012 16:59:20 -0500 Subject: [PATCH] compositor: Use XInput2 to grab the pointer/keyboard https://bugzilla.gnome.org/show_bug.cgi?id=688779 --- src/compositor/compositor.c | 49 +++++++++++++++++++++++++------------ src/core/display.c | 14 ++++------- src/meta/common.h | 4 +++ 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index c6a85aa46..e3c90e11d 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -358,14 +358,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, + META_VIRTUAL_CORE_POINTER_ID, + grab_window, + timestamp, cursor, - timestamp); + XIGrabModeAsync, XIGrabModeAsync, + False, /* owner_events */ + &mask); if (result != Success) goto fail; @@ -374,10 +383,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, + META_VIRTUAL_CORE_KEYBOARD_ID, + grab_window, + timestamp, + None, + XIGrabModeAsync, XIGrabModeAsync, + False, /* owner_events */ + &mask); if (result != Success) goto fail; @@ -397,9 +416,9 @@ meta_begin_modal_for_plugin (MetaScreen *screen, fail: if (pointer_grabbed) - XUngrabPointer (xdpy, timestamp); + XIUngrabDevice (xdpy, META_VIRTUAL_CORE_POINTER_ID, timestamp); if (keyboard_grabbed) - XUngrabKeyboard (xdpy, timestamp); + XIUngrabDevice (xdpy, META_VIRTUAL_CORE_KEYBOARD_ID, timestamp); return FALSE; } @@ -415,8 +434,8 @@ meta_end_modal_for_plugin (MetaScreen *screen, g_return_if_fail (compositor->modal_plugin == plugin); - XUngrabPointer (xdpy, timestamp); - XUngrabKeyboard (xdpy, timestamp); + XIUngrabDevice (xdpy, META_VIRTUAL_CORE_POINTER_ID, timestamp); + XIUngrabDevice (xdpy, META_VIRTUAL_CORE_KEYBOARD_ID, timestamp); display->grab_op = META_GRAB_OP_NONE; display->grab_window = NULL; diff --git a/src/core/display.c b/src/core/display.c index f557ade81..a989a0589 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -74,10 +74,6 @@ #include #include -/* 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 || \ @@ -1816,19 +1812,19 @@ get_input_event (MetaDisplay *display, case XI_Motion: case XI_ButtonPress: 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; case XI_KeyPress: 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; case XI_FocusIn: 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; case XI_Enter: 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; default: break; @@ -2877,7 +2873,7 @@ event_callback (XEvent *event, break; case XkbNewKeyboardNotify: 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); break; } diff --git a/src/meta/common.h b/src/meta/common.h index f32a0a633..ab54aff08 100644 --- a/src/meta/common.h +++ b/src/meta/common.h @@ -35,6 +35,10 @@ #include #include +/* 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 enum