X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fgrab.c;h=5e6209e0561cb7dc70326328e6e0148d73910d12;hb=5f42ecfacbbf0bcfe43137c51a20b60d8ea368e3;hp=3bba14b3a434ca30edb3c6051cd456a571004e2e;hpb=598c5d6c07118517b47d7c416a79dc9743271aa8;p=chaz%2Fopenbox diff --git a/openbox/grab.c b/openbox/grab.c index 3bba14b3..5e6209e0 100644 --- a/openbox/grab.c +++ b/openbox/grab.c @@ -1,18 +1,32 @@ #include "openbox.h" +#include "event.h" +#include "xerror.h" + #include #include -static guint kgrabs, pgrabs; +static guint kgrabs, pgrabs, sgrabs; + +#define MASK_LIST_SIZE 8 + +/*! A list of all possible combinations of keyboard lock masks */ +static unsigned int mask_list[MASK_LIST_SIZE]; void grab_keyboard(gboolean grab) { if (grab) { - if (kgrabs++ == 0) + if (kgrabs++ == 0) { + g_message("GRABBING KEYBOARD %d", kgrabs); XGrabKeyboard(ob_display, ob_root, 0, GrabModeAsync, GrabModeSync, - CurrentTime); + event_lasttime); + } else + g_message("NOT GRABBING KEYBOARD %d", kgrabs); } else if (kgrabs > 0) { - if (--kgrabs == 0) - XUngrabKeyboard(ob_display, CurrentTime); + if (--kgrabs == 0) { + g_message("UNGRABBING KEYBOARD %d", kgrabs); + XUngrabKeyboard(ob_display, event_lasttime); + } else + g_message("NOT UNGRABBING KEYBOARD %d", kgrabs); } } @@ -21,20 +35,85 @@ void grab_pointer(gboolean grab, Cursor cur) if (grab) { if (pgrabs++ == 0) XGrabPointer(ob_display, ob_root, False, 0, GrabModeAsync, - GrabModeSync, FALSE, cur, CurrentTime); + GrabModeAsync, FALSE, cur, event_lasttime); } else if (pgrabs > 0) { if (--pgrabs == 0) - XUngrabPointer(ob_display, CurrentTime); + XUngrabPointer(ob_display, event_lasttime); + } +} + +void grab_server(gboolean grab) +{ + if (grab) { + if (sgrabs++ == 0) { + XGrabServer(ob_display); + XSync(ob_display, FALSE); + } + } else if (sgrabs > 0) { + if (--sgrabs == 0) { + XUngrabServer(ob_display); + XFlush(ob_display); + } } } void grab_startup() { - kgrabs = pgrabs = 0; + guint i = 0; + + kgrabs = pgrabs = sgrabs = 0; + + mask_list[i++] = 0; + mask_list[i++] = LockMask; + mask_list[i++] = NumLockMask; + mask_list[i++] = LockMask | NumLockMask; + mask_list[i++] = ScrollLockMask; + mask_list[i++] = ScrollLockMask | LockMask; + mask_list[i++] = ScrollLockMask | NumLockMask; + mask_list[i++] = ScrollLockMask | LockMask | NumLockMask; + g_assert(i == MASK_LIST_SIZE); } void grab_shutdown() { while (kgrabs) grab_keyboard(FALSE); while (pgrabs) grab_pointer(FALSE, None); + while (sgrabs) grab_server(FALSE); +} + +void grab_button(guint button, guint state, Window win, guint mask, + int pointer_mode) +{ + guint i; + + for (i = 0; i < MASK_LIST_SIZE; ++i) + XGrabButton(ob_display, button, state | mask_list[i], win, FALSE, mask, + pointer_mode, GrabModeSync, None, None); +} + +void ungrab_button(guint button, guint state, Window win) +{ + guint i; + + for (i = 0; i < MASK_LIST_SIZE; ++i) + XUngrabButton(ob_display, button, state | mask_list[i], win); +} + +void grab_key(guint keycode, guint state, int keyboard_mode) +{ + guint i; + + xerror_set_ignore(TRUE); /* can get BadAccess' from these */ + xerror_occured = FALSE; + for (i = 0; i < MASK_LIST_SIZE; ++i) + XGrabKey(ob_display, keycode, state | mask_list[i], ob_root, FALSE, + GrabModeSync, keyboard_mode); + xerror_set_ignore(FALSE); + if (xerror_occured) + g_warning("failed to grab keycode %d modifiers %d", keycode, state); +} + +void ungrab_all_keys() +{ + XUngrabKey(ob_display, AnyKey, AnyModifier, ob_root); }