]>
Dogcows Code - chaz/openbox/blob - openbox/grab.c
8 #define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
9 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
11 #define MASK_LIST_SIZE 8
13 /*! A list of all possible combinations of keyboard lock masks */
14 static unsigned int mask_list
[MASK_LIST_SIZE
];
16 gboolean
grab_keyboard(gboolean grab
)
18 static guint kgrabs
= 0;
23 ret
= XGrabKeyboard(ob_display
, ob_root
, FALSE
, GrabModeAsync
,
24 GrabModeAsync
, event_lasttime
) == Success
;
27 } else if (kgrabs
> 0) {
29 XUngrabKeyboard(ob_display
, event_lasttime
);
35 gboolean
grab_pointer(gboolean grab
, Cursor cur
)
37 static guint pgrabs
= 0;
42 ret
= XGrabPointer(ob_display
, ob_root
, False
, GRAB_PTR_MASK
,
43 GrabModeAsync
, GrabModeAsync
, FALSE
, cur
,
44 event_lasttime
) == Success
;
47 } else if (pgrabs
> 0) {
49 XUngrabPointer(ob_display
, event_lasttime
);
55 gboolean
grab_pointer_window(gboolean grab
, Cursor cur
, Window win
)
57 static guint pgrabs
= 0;
62 ret
= XGrabPointer(ob_display
, win
, False
, GRAB_PTR_MASK
,
63 GrabModeAsync
, GrabModeAsync
, TRUE
, cur
,
64 event_lasttime
) == Success
;
67 } else if (pgrabs
> 0) {
69 XUngrabPointer(ob_display
, event_lasttime
);
75 int grab_server(gboolean grab
)
77 static guint sgrabs
= 0;
80 XGrabServer(ob_display
);
81 XSync(ob_display
, FALSE
);
83 } else if (sgrabs
> 0) {
85 XUngrabServer(ob_display
);
97 mask_list
[i
++] = LockMask
;
98 mask_list
[i
++] = NumLockMask
;
99 mask_list
[i
++] = LockMask
| NumLockMask
;
100 mask_list
[i
++] = ScrollLockMask
;
101 mask_list
[i
++] = ScrollLockMask
| LockMask
;
102 mask_list
[i
++] = ScrollLockMask
| NumLockMask
;
103 mask_list
[i
++] = ScrollLockMask
| LockMask
| NumLockMask
;
104 g_assert(i
== MASK_LIST_SIZE
);
109 while (grab_keyboard(FALSE
));
110 while (grab_pointer(FALSE
, None
));
111 while (grab_pointer_window(FALSE
, None
, None
));
112 while (grab_server(FALSE
));
115 void grab_button_full(guint button
, guint state
, Window win
, guint mask
,
116 int pointer_mode
, Cursor cursor
)
120 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
121 XGrabButton(ob_display
, button
, state
| mask_list
[i
], win
, FALSE
, mask
,
122 pointer_mode
, GrabModeSync
, None
, cursor
);
125 void grab_button(guint button
, guint state
, Window win
, guint mask
)
127 grab_button_full(button
, state
, win
, mask
, GrabModeAsync
, None
);
130 void ungrab_button(guint button
, guint state
, Window win
)
134 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
135 XUngrabButton(ob_display
, button
, state
| mask_list
[i
], win
);
138 void grab_key(guint keycode
, guint state
, Window win
, int keyboard_mode
)
142 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
143 xerror_occured
= FALSE
;
144 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
145 XGrabKey(ob_display
, keycode
, state
| mask_list
[i
], win
, FALSE
,
146 GrabModeSync
, keyboard_mode
);
147 xerror_set_ignore(FALSE
);
149 g_warning("failed to grab keycode %d modifiers %d", keycode
, state
);
152 void ungrab_all_keys(Window win
)
154 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, win
);
This page took 0.040192 seconds and 4 git commands to generate.