]> Dogcows Code - chaz/openbox/blob - openbox/grab.c
grab all lock keys
[chaz/openbox] / openbox / grab.c
1 #include "openbox.h"
2 #include "event.h"
3
4 #include <glib.h>
5 #include <X11/Xlib.h>
6
7 static guint kgrabs, pgrabs, sgrabs;
8
9 #define MASK_LIST_SIZE 8
10
11 /*! A list of all possible combinations of keyboard lock masks */
12 static unsigned int mask_list[MASK_LIST_SIZE];
13
14 void grab_keyboard(gboolean grab)
15 {
16 if (grab) {
17 if (kgrabs++ == 0)
18 XGrabKeyboard(ob_display, ob_root, 0, GrabModeAsync, GrabModeSync,
19 CurrentTime);
20 } else if (kgrabs > 0) {
21 if (--kgrabs == 0)
22 XUngrabKeyboard(ob_display, CurrentTime);
23 }
24 }
25
26 void grab_pointer(gboolean grab, Cursor cur)
27 {
28 if (grab) {
29 if (pgrabs++ == 0)
30 XGrabPointer(ob_display, ob_root, False, 0, GrabModeAsync,
31 GrabModeAsync, FALSE, cur, CurrentTime);
32 } else if (pgrabs > 0) {
33 if (--pgrabs == 0)
34 XUngrabPointer(ob_display, CurrentTime);
35 }
36 }
37
38 void grab_server(gboolean grab)
39 {
40 if (grab) {
41 if (sgrabs++ == 0) {
42 XGrabServer(ob_display);
43 XSync(ob_display, FALSE);
44 }
45 } else if (sgrabs > 0) {
46 if (--sgrabs == 0) {
47 XUngrabServer(ob_display);
48 XFlush(ob_display);
49 }
50 }
51 }
52
53 void grab_startup()
54 {
55 guint i = 0;
56
57 kgrabs = pgrabs = sgrabs = 0;
58
59 mask_list[i++] = 0;
60 mask_list[i++] = LockMask;
61 mask_list[i++] = NumLockMask;
62 mask_list[i++] = LockMask | NumLockMask;
63 mask_list[i++] = ScrollLockMask;
64 mask_list[i++] = ScrollLockMask | LockMask;
65 mask_list[i++] = ScrollLockMask | NumLockMask;
66 mask_list[i++] = ScrollLockMask | LockMask | NumLockMask;
67 g_assert(i == MASK_LIST_SIZE);
68 }
69
70 void grab_shutdown()
71 {
72 while (kgrabs) grab_keyboard(FALSE);
73 while (pgrabs) grab_pointer(FALSE, None);
74 while (sgrabs) grab_server(FALSE);
75 }
76
77 void grab_button(guint button, guint state, Window win, guint mask,
78 int pointer_mode)
79 {
80 guint i;
81
82 for (i = 0; i < MASK_LIST_SIZE; ++i)
83 XGrabButton(ob_display, button, state | mask_list[i], win, FALSE, mask,
84 pointer_mode, GrabModeAsync, None, None);
85 }
86
87 void ungrab_button(guint button, guint state, Window win)
88 {
89 guint i;
90
91 for (i = 0; i < MASK_LIST_SIZE; ++i)
92 XUngrabButton(ob_display, button, state | mask_list[i], win);
93 }
94
95 void grab_key(guint keycode, guint state, int keyboard_mode)
96 {
97 guint i;
98
99 for (i = 0; i < MASK_LIST_SIZE; ++i)
100 XGrabKey(ob_display, keycode, state | mask_list[i], ob_root, FALSE,
101 GrabModeAsync, keyboard_mode);
102 }
103
104 void ungrab_all_keys()
105 {
106 XUngrabKey(ob_display, AnyKey, AnyModifier, ob_root);
107 }
This page took 0.042927 seconds and 5 git commands to generate.