]> Dogcows Code - chaz/openbox/blob - openbox/grab.c
not using CurrentTime anywhere
[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 g_message("GRABBING KEYBOARD %d", kgrabs);
19 XGrabKeyboard(ob_display, ob_root, 0, GrabModeAsync, GrabModeSync,
20 event_lasttime);
21 } else
22 g_message("NOT GRABBING KEYBOARD %d", kgrabs);
23 } else if (kgrabs > 0) {
24 if (--kgrabs == 0) {
25 g_message("UNGRABBING KEYBOARD %d", kgrabs);
26 XUngrabKeyboard(ob_display, event_lasttime);
27 } else
28 g_message("NOT UNGRABBING KEYBOARD %d", kgrabs);
29 }
30 }
31
32 void grab_pointer(gboolean grab, Cursor cur)
33 {
34 if (grab) {
35 if (pgrabs++ == 0)
36 XGrabPointer(ob_display, ob_root, False, 0, GrabModeAsync,
37 GrabModeAsync, FALSE, cur, event_lasttime);
38 } else if (pgrabs > 0) {
39 if (--pgrabs == 0)
40 XUngrabPointer(ob_display, event_lasttime);
41 }
42 }
43
44 void grab_server(gboolean grab)
45 {
46 if (grab) {
47 if (sgrabs++ == 0) {
48 XGrabServer(ob_display);
49 XSync(ob_display, FALSE);
50 }
51 } else if (sgrabs > 0) {
52 if (--sgrabs == 0) {
53 XUngrabServer(ob_display);
54 XFlush(ob_display);
55 }
56 }
57 }
58
59 void grab_startup()
60 {
61 guint i = 0;
62
63 kgrabs = pgrabs = sgrabs = 0;
64
65 mask_list[i++] = 0;
66 mask_list[i++] = LockMask;
67 mask_list[i++] = NumLockMask;
68 mask_list[i++] = LockMask | NumLockMask;
69 mask_list[i++] = ScrollLockMask;
70 mask_list[i++] = ScrollLockMask | LockMask;
71 mask_list[i++] = ScrollLockMask | NumLockMask;
72 mask_list[i++] = ScrollLockMask | LockMask | NumLockMask;
73 g_assert(i == MASK_LIST_SIZE);
74 }
75
76 void grab_shutdown()
77 {
78 while (kgrabs) grab_keyboard(FALSE);
79 while (pgrabs) grab_pointer(FALSE, None);
80 while (sgrabs) grab_server(FALSE);
81 }
82
83 void grab_button(guint button, guint state, Window win, guint mask,
84 int pointer_mode)
85 {
86 guint i;
87
88 for (i = 0; i < MASK_LIST_SIZE; ++i)
89 XGrabButton(ob_display, button, state | mask_list[i], win, FALSE, mask,
90 pointer_mode, GrabModeAsync, None, None);
91 }
92
93 void ungrab_button(guint button, guint state, Window win)
94 {
95 guint i;
96
97 for (i = 0; i < MASK_LIST_SIZE; ++i)
98 XUngrabButton(ob_display, button, state | mask_list[i], win);
99 }
100
101 void grab_key(guint keycode, guint state, int keyboard_mode)
102 {
103 guint i;
104
105 for (i = 0; i < MASK_LIST_SIZE; ++i)
106 XGrabKey(ob_display, keycode, state | mask_list[i], ob_root, FALSE,
107 GrabModeAsync, keyboard_mode);
108 }
109
110 void ungrab_all_keys()
111 {
112 XUngrabKey(ob_display, AnyKey, AnyModifier, ob_root);
113 }
This page took 0.038887 seconds and 5 git commands to generate.