]>
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) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
28 #define GRAB_PTR_MASK (ButtonPressMask | ButtonReleaseMask | PointerMotionMask)
29 #define GRAB_KEY_MASK (KeyPressMask | KeyReleaseMask)
31 #define MASK_LIST_SIZE 8
33 /*! A list of all possible combinations of keyboard lock masks */
34 static unsigned int mask_list
[MASK_LIST_SIZE
];
35 static guint kgrabs
= 0;
36 static guint pgrabs
= 0;
38 gboolean
grab_on_keyboard()
43 gboolean
grab_on_pointer()
48 gboolean
grab_keyboard(gboolean grab
)
54 ret
= XGrabKeyboard(ob_display
, RootWindow(ob_display
, ob_screen
),
55 FALSE
, GrabModeAsync
, GrabModeAsync
,
56 event_lasttime
) == Success
;
59 } else if (kgrabs
> 0) {
61 XUngrabKeyboard(ob_display
, event_lasttime
);
68 gboolean
grab_pointer(gboolean grab
, ObCursor cur
)
74 ret
= XGrabPointer(ob_display
, screen_support_win
,
75 False
, GRAB_PTR_MASK
, GrabModeAsync
,
77 ob_cursor(cur
), event_lasttime
) == Success
;
80 } else if (pgrabs
> 0) {
82 XUngrabPointer(ob_display
, event_lasttime
);
89 gboolean
grab_pointer_window(gboolean grab
, ObCursor cur
, Window win
)
95 ret
= XGrabPointer(ob_display
, win
, False
, GRAB_PTR_MASK
,
96 GrabModeAsync
, GrabModeAsync
, TRUE
,
98 event_lasttime
) == Success
;
101 } else if (pgrabs
> 0) {
103 XUngrabPointer(ob_display
, event_lasttime
);
110 gint
grab_server(gboolean grab
)
112 static guint sgrabs
= 0;
115 XGrabServer(ob_display
);
116 XSync(ob_display
, FALSE
);
118 } else if (sgrabs
> 0) {
120 XUngrabServer(ob_display
);
127 void grab_startup(gboolean reconfig
)
131 if (reconfig
) return;
134 mask_list
[i
++] = LockMask
;
135 mask_list
[i
++] = NumLockMask
;
136 mask_list
[i
++] = LockMask
| NumLockMask
;
137 mask_list
[i
++] = ScrollLockMask
;
138 mask_list
[i
++] = ScrollLockMask
| LockMask
;
139 mask_list
[i
++] = ScrollLockMask
| NumLockMask
;
140 mask_list
[i
++] = ScrollLockMask
| LockMask
| NumLockMask
;
141 g_assert(i
== MASK_LIST_SIZE
);
144 void grab_shutdown(gboolean reconfig
)
146 if (reconfig
) return;
148 while (grab_keyboard(FALSE
));
149 while (grab_pointer(FALSE
, OB_CURSOR_NONE
));
150 while (grab_pointer_window(FALSE
, OB_CURSOR_NONE
, None
));
151 while (grab_server(FALSE
));
154 void grab_button_full(guint button
, guint state
, Window win
, guint mask
,
155 int pointer_mode
, ObCursor cur
)
159 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
160 xerror_occured
= FALSE
;
161 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
162 XGrabButton(ob_display
, button
, state
| mask_list
[i
], win
, FALSE
, mask
,
163 pointer_mode
, GrabModeSync
, None
, ob_cursor(cur
));
164 xerror_set_ignore(FALSE
);
166 g_warning("failed to grab button %d modifiers %d", button
, state
);
169 void grab_button(guint button
, guint state
, Window win
, guint mask
)
171 grab_button_full(button
, state
, win
, mask
, GrabModeAsync
, OB_CURSOR_NONE
);
174 void ungrab_button(guint button
, guint state
, Window win
)
178 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
179 XUngrabButton(ob_display
, button
, state
| mask_list
[i
], win
);
182 void grab_key(guint keycode
, guint state
, Window win
, int keyboard_mode
)
186 xerror_set_ignore(TRUE
); /* can get BadAccess' from these */
187 xerror_occured
= FALSE
;
188 for (i
= 0; i
< MASK_LIST_SIZE
; ++i
)
189 XGrabKey(ob_display
, keycode
, state
| mask_list
[i
], win
, FALSE
,
190 GrabModeAsync
, keyboard_mode
);
191 xerror_set_ignore(FALSE
);
193 g_warning("failed to grab keycode %d modifiers %d", keycode
, state
);
196 void ungrab_all_keys(Window win
)
198 XUngrabKey(ob_display
, AnyKey
, AnyModifier
, win
);
This page took 0.040187 seconds and 4 git commands to generate.