9 #define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
10 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
12 #define MASK_LIST_SIZE 8
14 /*! A list of all possible combinations of keyboard lock masks */
15 static unsigned int mask_list[MASK_LIST_SIZE];
17 gboolean grab_keyboard(gboolean grab)
19 static guint kgrabs = 0;
24 ret = XGrabKeyboard(ob_display, RootWindow(ob_display, ob_screen),
25 FALSE, GrabModeAsync, GrabModeAsync,
26 event_lasttime) == Success;
29 } else if (kgrabs > 0) {
31 XUngrabKeyboard(ob_display, event_lasttime);
38 gboolean grab_pointer(gboolean grab, ObCursor cur)
40 static guint pgrabs = 0;
45 ret = XGrabPointer(ob_display, RootWindow(ob_display, ob_screen),
46 False, GRAB_PTR_MASK, GrabModeAsync,
48 ob_cursor(cur), event_lasttime) == Success;
51 } else if (pgrabs > 0) {
53 XUngrabPointer(ob_display, event_lasttime);
59 gboolean grab_pointer_window(gboolean grab, ObCursor cur, Window win)
61 static guint pgrabs = 0;
66 ret = XGrabPointer(ob_display, win, False, GRAB_PTR_MASK,
67 GrabModeAsync, GrabModeAsync, TRUE,
69 event_lasttime) == Success;
72 } else if (pgrabs > 0) {
74 XUngrabPointer(ob_display, event_lasttime);
80 gint grab_server(gboolean grab)
82 static guint sgrabs = 0;
85 XGrabServer(ob_display);
86 XSync(ob_display, FALSE);
88 } else if (sgrabs > 0) {
90 XUngrabServer(ob_display);
97 void grab_startup(gboolean reconfig)
101 if (reconfig) return;
104 mask_list[i++] = LockMask;
105 mask_list[i++] = NumLockMask;
106 mask_list[i++] = LockMask | NumLockMask;
107 mask_list[i++] = ScrollLockMask;
108 mask_list[i++] = ScrollLockMask | LockMask;
109 mask_list[i++] = ScrollLockMask | NumLockMask;
110 mask_list[i++] = ScrollLockMask | LockMask | NumLockMask;
111 g_assert(i == MASK_LIST_SIZE);
114 void grab_shutdown(gboolean reconfig)
116 if (reconfig) return;
118 while (grab_keyboard(FALSE));
119 while (grab_pointer(FALSE, OB_CURSOR_NONE));
120 while (grab_pointer_window(FALSE, OB_CURSOR_NONE, None));
121 while (grab_server(FALSE));
124 void grab_button_full(guint button, guint state, Window win, guint mask,
125 int pointer_mode, ObCursor cur)
129 xerror_set_ignore(TRUE); /* can get BadAccess' from these */
130 xerror_occured = FALSE;
131 for (i = 0; i < MASK_LIST_SIZE; ++i)
132 XGrabButton(ob_display, button, state | mask_list[i], win, FALSE, mask,
133 pointer_mode, GrabModeSync, None, ob_cursor(cur));
134 xerror_set_ignore(FALSE);
136 g_warning("failed to grab button %d modifiers %d", button, state);
139 void grab_button(guint button, guint state, Window win, guint mask)
141 grab_button_full(button, state, win, mask, GrabModeAsync, OB_CURSOR_NONE);
144 void ungrab_button(guint button, guint state, Window win)
148 for (i = 0; i < MASK_LIST_SIZE; ++i)
149 XUngrabButton(ob_display, button, state | mask_list[i], win);
152 void grab_key(guint keycode, guint state, Window win, int keyboard_mode)
156 xerror_set_ignore(TRUE); /* can get BadAccess' from these */
157 xerror_occured = FALSE;
158 for (i = 0; i < MASK_LIST_SIZE; ++i)
159 XGrabKey(ob_display, keycode, state | mask_list[i], win, FALSE,
160 GrabModeAsync, keyboard_mode);
161 xerror_set_ignore(FALSE);
163 g_warning("failed to grab keycode %d modifiers %d", keycode, state);
166 void ungrab_all_keys(Window win)
168 XUngrabKey(ob_display, AnyKey, AnyModifier, win);