]>
Dogcows Code - chaz/openbox/blob - openbox/grab.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 grab.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
31 #define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
32 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
34 #define MASK_LIST_SIZE 8
36 /*! A list of all possible combinations of keyboard lock masks */
37 static guint mask_list
[MASK_LIST_SIZE
];
38 static guint kgrabs
= 0;
39 static guint pgrabs
= 0;
40 /*! The time at which the last grab was made */
41 static Time grab_time
= CurrentTime
;
43 static Time
ungrab_time()
45 Time t
= event_curtime
;
46 if (grab_time
== CurrentTime
||
47 !(t
== CurrentTime
|| event_time_after(t
, grab_time
)))
48 /* When the time moves backward on the server, then we can't use
49 the grab time because that will be in the future. So instead we
50 have to use CurrentTime.
52 "XUngrabPointer does not release the pointer if the specified time
53 is earlier than the last-pointer-grab time or is later than the
54 current X server time."
56 t
= CurrentTime
; /*grab_time;*/
60 gboolean
grab_on_keyboard()
65 gboolean
grab_on_pointer()
70 gboolean
grab_keyboard(gboolean grab
)
76 ret
= XGrabKeyboard(ob_display
, RootWindow(ob_display
, ob_screen
),
77 False
, GrabModeAsync
, GrabModeAsync
,
78 event_curtime
) == Success
;
82 grab_time
= event_curtime
;
85 } else if (kgrabs
> 0) {
87 XUngrabKeyboard(ob_display
, ungrab_time());
95 gboolean
grab_pointer(gboolean grab
, gboolean owner_events
, ObCursor cur
)
101 ret
= XGrabPointer(ob_display
, screen_support_win
, owner_events
,
103 GrabModeAsync
, GrabModeAsync
, None
,
104 ob_cursor(cur
), event_curtime
) == Success
;
108 grab_time
= event_curtime
;
111 } else if (pgrabs
> 0) {
113 XUngrabPointer(ob_display
, ungrab_time());
120 gint
grab_server(gboolean grab
)
122 static guint sgrabs
= 0;
125 XGrabServer(ob_display
);
126 XSync(ob_display
, FALSE
);
128 } else if (sgrabs
> 0) {
130 XUngrabServer(ob_display
);
137 void grab_startup(gboolean reconfig
)
140 guint num
, caps
, scroll
;
142 num
= modkeys_key_to_mask(OB_MODKEY_KEY_NUMLOCK
);
143 caps
= modkeys_key_to_mask(OB_MODKEY_KEY_CAPSLOCK
);
144 scroll
= modkeys_key_to_mask(OB_MODKEY_KEY_SCROLLLOCK
);
147 mask_list
[i
++] = num
;
148 mask_list
[i
++] = caps
;
149 mask_list
[i
++] = scroll
;
150 mask_list
[i
++] = num
| caps
;
151 mask_list
[i
++] = num
| scroll
;
152 mask_list
[i
++] = caps
| scroll
;
153 mask_list
[i
++] = num
| caps
| scroll
;
154 g_assert(i
== MASK_LIST_SIZE
);
157 void grab_shutdown(gboolean reconfig
)
159 if (reconfig
) return;
161 while (grab_keyboard(FALSE
));
162 while (grab_pointer(FALSE
, FALSE
, OB_CURSOR_NONE
));
163 while (grab_server(FALSE
));
166 void grab_button_full(guint button
, guint state
, Window win
, guint mask
,
167 gint pointer_mode
, ObCursor cur
)
171 xerror_set_ignore(TRUE
); /* can get BadAccess from these */
172 xerror_occured
= FALSE
;
173 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
174 XGrabButton(ob_display
, button
, state
| mask_list
[i
], win
, False
, mask
,
175 pointer_mode
, GrabModeAsync
, None
, ob_cursor(cur
));
176 xerror_set_ignore(FALSE
);
178 ob_debug("Failed to grab button %d modifiers %d", button
, state
);
181 void ungrab_button(guint button
, guint state
, Window win
)
185 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
186 XUngrabButton(ob_display
, button
, state
| mask_list
[i
], win
);
189 void grab_key(guint keycode
, guint state
, Window win
, gint keyboard_mode
)
193 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
194 xerror_occured
= FALSE
;
195 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
196 XGrabKey(ob_display
, keycode
, state
| mask_list
[i
], win
, FALSE
,
197 GrabModeAsync
, keyboard_mode
);
198 xerror_set_ignore(FALSE
);
200 ob_debug("Failed to grab keycode %d modifiers %d", keycode
, state
);
203 void ungrab_all_keys(Window win
)
205 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, win
);
This page took 0.041632 seconds and 4 git commands to generate.