]>
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 Ben 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.
29 #define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
30 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
32 #define MASK_LIST_SIZE 8
34 /*! A list of all possible combinations of keyboard lock masks */
35 static guint mask_list
[MASK_LIST_SIZE
];
36 static guint kgrabs
= 0;
37 static guint pgrabs
= 0;
38 /*! The time at which the last grab was made */
39 static Time grab_time
= CurrentTime
;
41 gboolean
grab_on_keyboard()
46 gboolean
grab_on_pointer()
51 gboolean
grab_keyboard(gboolean grab
)
57 ret
= XGrabKeyboard(ob_display
, RootWindow(ob_display
, ob_screen
),
58 FALSE
, GrabModeAsync
, GrabModeAsync
,
59 event_curtime
) == Success
;
63 grab_time
= event_curtime
;
66 } else if (kgrabs
> 0) {
68 Time t
= event_curtime
;
69 if (t
!= 0 && t
< grab_time
)
71 XUngrabKeyboard(ob_display
, t
);
79 gboolean
grab_pointer(gboolean grab
, ObCursor cur
)
85 ret
= XGrabPointer(ob_display
, screen_support_win
,
86 False
, GRAB_PTR_MASK
, GrabModeAsync
,
88 ob_cursor(cur
), event_curtime
) == Success
;
92 grab_time
= event_curtime
;
95 } else if (pgrabs
> 0) {
97 Time t
= event_curtime
;
98 if (t
!= 0 && t
< grab_time
)
100 XUngrabPointer(ob_display
, event_curtime
);
107 gboolean
grab_pointer_window(gboolean grab
, ObCursor cur
, Window win
)
109 gboolean ret
= FALSE
;
113 ret
= XGrabPointer(ob_display
, win
, False
, GRAB_PTR_MASK
,
114 GrabModeAsync
, GrabModeAsync
, None
,
116 event_curtime
) == Success
;
120 grab_time
= event_curtime
;
123 } else if (pgrabs
> 0) {
125 Time t
= event_curtime
;
126 if (t
!= 0 && t
< grab_time
)
128 XUngrabPointer(ob_display
, event_curtime
);
135 gint
grab_server(gboolean grab
)
137 static guint sgrabs
= 0;
140 XGrabServer(ob_display
);
141 XSync(ob_display
, FALSE
);
143 } else if (sgrabs
> 0) {
145 XUngrabServer(ob_display
);
152 void grab_startup(gboolean reconfig
)
156 if (reconfig
) return;
159 mask_list
[i
++] = LockMask
;
160 mask_list
[i
++] = NumLockMask
;
161 mask_list
[i
++] = LockMask
| NumLockMask
;
162 mask_list
[i
++] = ScrollLockMask
;
163 mask_list
[i
++] = ScrollLockMask
| LockMask
;
164 mask_list
[i
++] = ScrollLockMask
| NumLockMask
;
165 mask_list
[i
++] = ScrollLockMask
| LockMask
| NumLockMask
;
166 g_assert(i
== MASK_LIST_SIZE
);
169 void grab_shutdown(gboolean reconfig
)
171 if (reconfig
) return;
173 while (grab_keyboard(FALSE
));
174 while (grab_pointer(FALSE
, OB_CURSOR_NONE
));
175 while (grab_pointer_window(FALSE
, OB_CURSOR_NONE
, None
));
176 while (grab_server(FALSE
));
179 void grab_button_full(guint button
, guint state
, Window win
, guint mask
,
180 gint pointer_mode
, ObCursor cur
)
184 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
185 xerror_occured
= FALSE
;
186 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
187 XGrabButton(ob_display
, button
, state
| mask_list
[i
], win
, FALSE
, mask
,
188 pointer_mode
, GrabModeSync
, None
, ob_cursor(cur
));
189 xerror_set_ignore(FALSE
);
191 g_warning("failed to grab button %d modifiers %d", button
, state
);
194 void grab_button(guint button
, guint state
, Window win
, guint mask
)
196 grab_button_full(button
, state
, win
, mask
, GrabModeAsync
, OB_CURSOR_NONE
);
199 void ungrab_button(guint button
, guint state
, Window win
)
203 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
204 XUngrabButton(ob_display
, button
, state
| mask_list
[i
], win
);
207 void grab_key(guint keycode
, guint state
, Window win
, gint keyboard_mode
)
211 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
212 xerror_occured
= FALSE
;
213 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
214 XGrabKey(ob_display
, keycode
, state
| mask_list
[i
], win
, FALSE
,
215 GrabModeAsync
, keyboard_mode
);
216 xerror_set_ignore(FALSE
);
218 g_warning("failed to grab keycode %d modifiers %d", keycode
, state
);
221 void ungrab_all_keys(Window win
)
223 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, win
);
This page took 0.04721 seconds and 5 git commands to generate.