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