chiark / gitweb /
Imported Upstream version 1.0.0
[e16] / src / grabs.c
1 /*
2  * Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
3  * Copyright (C) 2004-2008 Kim Woelders
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to
7  * deal in the Software without restriction, including without limitation the
8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9  * sell copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies of the Software, its documentation and marketing & publicity
14  * materials, and acknowledgment shall be given in the documentation, materials
15  * and software packages that this Software was used.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20  * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #include "E.h"
25 #include "cursors.h"
26 #include "grabs.h"
27 #include "xwin.h"
28
29 int
30 GrabKeyboardSet(Win win)
31 {
32    int                 rc;
33
34    rc =
35       XGrabKeyboard(disp, WinGetXwin(win), False, GrabModeAsync, GrabModeAsync,
36                     CurrentTime);
37
38 #if 0
39    Eprintf("GrabKeyboardSet %#lx %d\n", WinGetXwin(win), rc);
40 #endif
41    return rc;
42 }
43
44 int
45 GrabKeyboardRelease(void)
46 {
47    int                 rc;
48
49    rc = XUngrabKeyboard(disp, CurrentTime);
50
51 #if 0
52    Eprintf("GrabKeyboardRelease %d\n", rc);
53 #endif
54    return rc;
55 }
56
57 int
58 GrabPointerSet(Win win, unsigned int csr, int confine)
59 {
60    int                 ret = -1;
61    Window              confine_to = (confine) ? WinGetXwin(VROOT) : None;
62
63    ret = XGrabPointer(disp, WinGetXwin(win), False,
64                       ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
65                       ButtonMotionMask | EnterWindowMask | LeaveWindowMask,
66                       GrabModeAsync, GrabModeAsync, confine_to, ECsrGet(csr),
67                       CurrentTime);
68
69    Mode.grabs.pointer_grab_window = WinGetXwin(win);
70    Mode.grabs.pointer_grab_active = 1;
71
72    if (EDebug(EDBUG_TYPE_GRABS))
73       Eprintf("GrabPointerSet: %#lx, ret=%d\n", Mode.grabs.pointer_grab_window,
74               ret);
75
76    return ret;
77 }
78
79 void
80 GrabPointerRelease(void)
81 {
82    XUngrabPointer(disp, CurrentTime);
83
84    if (EDebug(EDBUG_TYPE_GRABS))
85       Eprintf("GrabPointerRelease: %#lx\n", Mode.grabs.pointer_grab_window);
86
87    Mode.grabs.pointer_grab_active = 0;
88    Mode.grabs.pointer_grab_window = None;
89 }
90
91 void
92 GrabButtonSet(unsigned int button, unsigned int modifiers, Win win,
93               unsigned int event_mask, unsigned int csr, int confine)
94 {
95    Bool                owner_events = False;
96    int                 pointer_mode = GrabModeSync;
97    int                 keyboard_mode = GrabModeAsync;
98    Window              confine_to = (confine) ? WinGetXwin(win) : None;
99    int                 i;
100
101    if (modifiers == AnyModifier)
102      {
103         XGrabButton(disp, button, modifiers,
104                     WinGetXwin(win), owner_events, event_mask, pointer_mode,
105                     keyboard_mode, confine_to, ECsrGet(csr));
106         return;
107      }
108
109    for (i = 0; i < 8; i++)
110      {
111         if (i && !Mode.masks.mod_combos[i])
112            continue;
113         XGrabButton(disp, button, modifiers | Mode.masks.mod_combos[i],
114                     WinGetXwin(win), owner_events, event_mask, pointer_mode,
115                     keyboard_mode, confine_to, ECsrGet(csr));
116      }
117 }
118
119 void
120 GrabButtonRelease(unsigned int button, unsigned int modifiers, Win win)
121 {
122    int                 i;
123
124    if (modifiers == AnyModifier)
125      {
126         XUngrabButton(disp, button, modifiers, WinGetXwin(win));
127         return;
128      }
129
130    for (i = 0; i < 8; i++)
131      {
132         if (i && !Mode.masks.mod_combos[i])
133            continue;
134         XUngrabButton(disp, button, modifiers | Mode.masks.mod_combos[i],
135                       WinGetXwin(win));
136      }
137 }
138
139 void
140 GrabKeySet(unsigned int key, unsigned int modifiers, Win win)
141 {
142    Bool                owner_events = False;
143    int                 pointer_mode = GrabModeAsync;
144    int                 keyboard_mode = GrabModeSync;
145    int                 i;
146
147    if (modifiers == AnyModifier)
148      {
149         XGrabKey(disp, key, modifiers, WinGetXwin(win), owner_events,
150                  pointer_mode, keyboard_mode);
151         return;
152      }
153
154    for (i = 0; i < 8; i++)
155      {
156         if (i && !Mode.masks.mod_combos[i])
157            continue;
158         XGrabKey(disp, key, modifiers | Mode.masks.mod_combos[i],
159                  WinGetXwin(win), owner_events, pointer_mode, keyboard_mode);
160      }
161 }
162
163 void
164 GrabKeyRelease(unsigned int key, unsigned int modifiers, Win win)
165 {
166    int                 i;
167
168    if (modifiers == AnyModifier)
169      {
170         XUngrabKey(disp, key, modifiers, WinGetXwin(win));
171         return;
172      }
173
174    for (i = 0; i < 8; i++)
175      {
176         if (i && !Mode.masks.mod_combos[i])
177            continue;
178         XUngrabKey(disp, key, modifiers | Mode.masks.mod_combos[i],
179                    WinGetXwin(win));
180      }
181 }