]>
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 static Time
ungrab_time()
43 Time t
= event_curtime
;
44 if (!(t
== CurrentTime
|| event_time_after(t
, grab_time
)))
45 /* When the time moves backward on the server, then we can't use
46 the grab time because that will be in the future. So instead we
47 have to use CurrentTime.
49 "XUngrabPointer does not release the pointer if the specified time
50 is earlier than the last-pointer-grab time or is later than the
51 current X server time."
53 t
= CurrentTime
; /*grab_time;*/
57 gboolean
grab_on_keyboard()
62 gboolean
grab_on_pointer()
67 gboolean
grab_keyboard(gboolean grab
)
73 ret
= XGrabKeyboard(ob_display
, RootWindow(ob_display
, ob_screen
),
74 False
, GrabModeAsync
, GrabModeAsync
,
75 event_curtime
) == Success
;
79 grab_time
= event_curtime
;
82 } else if (kgrabs
> 0) {
84 XUngrabKeyboard(ob_display
, ungrab_time());
92 gboolean
grab_pointer(gboolean grab
, gboolean owner_events
, ObCursor cur
)
98 ret
= XGrabPointer(ob_display
, screen_support_win
, owner_events
,
100 GrabModeAsync
, GrabModeAsync
, None
,
101 ob_cursor(cur
), event_curtime
) == Success
;
105 grab_time
= event_curtime
;
108 } else if (pgrabs
> 0) {
110 XUngrabPointer(ob_display
, ungrab_time());
117 gint
grab_server(gboolean grab
)
119 static guint sgrabs
= 0;
122 XGrabServer(ob_display
);
123 XSync(ob_display
, FALSE
);
125 } else if (sgrabs
> 0) {
127 XUngrabServer(ob_display
);
134 void grab_startup(gboolean reconfig
)
138 if (reconfig
) return;
141 mask_list
[i
++] = LockMask
;
142 mask_list
[i
++] = NumLockMask
;
143 mask_list
[i
++] = LockMask
| NumLockMask
;
144 mask_list
[i
++] = ScrollLockMask
;
145 mask_list
[i
++] = ScrollLockMask
| LockMask
;
146 mask_list
[i
++] = ScrollLockMask
| NumLockMask
;
147 mask_list
[i
++] = ScrollLockMask
| LockMask
| NumLockMask
;
148 g_assert(i
== MASK_LIST_SIZE
);
151 void grab_shutdown(gboolean reconfig
)
153 if (reconfig
) return;
155 while (grab_keyboard(FALSE
));
156 while (grab_pointer(FALSE
, FALSE
, OB_CURSOR_NONE
));
157 while (grab_server(FALSE
));
160 void grab_button_full(guint button
, guint state
, Window win
, guint mask
,
161 gint pointer_mode
, ObCursor cur
)
165 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
166 xerror_occured
= FALSE
;
167 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
168 XGrabButton(ob_display
, button
, state
| mask_list
[i
], win
, FALSE
, mask
,
169 pointer_mode
, GrabModeSync
, None
, ob_cursor(cur
));
170 xerror_set_ignore(FALSE
);
172 g_warning("failed to grab button %d modifiers %d", button
, state
);
175 void grab_button(guint button
, guint state
, Window win
, guint mask
)
177 grab_button_full(button
, state
, win
, mask
, GrabModeAsync
, OB_CURSOR_NONE
);
180 void ungrab_button(guint button
, guint state
, Window win
)
184 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
185 XUngrabButton(ob_display
, button
, state
| mask_list
[i
], win
);
188 void grab_key(guint keycode
, guint state
, Window win
, gint keyboard_mode
)
192 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
193 xerror_occured
= FALSE
;
194 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
195 XGrabKey(ob_display
, keycode
, state
| mask_list
[i
], win
, FALSE
,
196 GrabModeAsync
, keyboard_mode
);
197 xerror_set_ignore(FALSE
);
199 g_warning("failed to grab keycode %d modifiers %d", keycode
, state
);
202 void ungrab_all_keys(Window win
)
204 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, win
);
This page took 0.03989 seconds and 4 git commands to generate.