This repository has been archived by the owner on Jul 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
event_utils.c
302 lines (264 loc) · 6.58 KB
/
event_utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
* Various util-ish functions for event handling.
*
* Many, probably most, are internal to the event code, but a few are
* used elsewhere.
*/
#include "ctwm.h"
#include <stdio.h>
#include "event_handlers.h"
#include "event_internal.h"
#include "events.h"
#include "list.h"
#include "otp.h"
#include "screen.h"
#include "vscreen.h"
#include "win_iconify.h"
#include "workspace_manager.h"
static ScreenInfo *FindScreenInfo(Window w);
void
AutoRaiseWindow(TwmWindow *tmp)
{
OtpRaise(tmp, WinWin);
if(ActiveMenu && ActiveMenu->w) {
XRaiseWindow(dpy, ActiveMenu->w);
}
XSync(dpy, 0);
enter_win = NULL;
enter_flag = true;
raise_win = tmp;
WMapRaise(tmp);
}
void
SetRaiseWindow(TwmWindow *tmp)
{
enter_flag = true;
enter_win = NULL;
raise_win = tmp;
leave_win = NULL;
leave_flag = false;
lower_win = NULL;
XSync(dpy, 0);
}
void
AutoPopupMaybe(TwmWindow *tmp)
{
if(LookInList(Scr->AutoPopupL, tmp->name, &tmp->class)
|| Scr->AutoPopup) {
if(OCCUPY(tmp, Scr->currentvs->wsw->currentwspc)) {
if(!tmp->mapped) {
DeIconify(tmp);
SetRaiseWindow(tmp);
}
}
else {
tmp->mapped = true;
}
}
}
void
AutoLowerWindow(TwmWindow *tmp)
{
OtpLower(tmp, WinWin);
if(ActiveMenu && ActiveMenu->w) {
XRaiseWindow(dpy, ActiveMenu->w);
}
XSync(dpy, 0);
enter_win = NULL;
enter_flag = false;
raise_win = NULL;
leave_win = NULL;
leave_flag = true;
lower_win = tmp;
WMapLower(tmp);
}
/*
* WindowOfEvent - return the window about which this event is concerned; this
* window may not be the same as XEvent.xany.window (the first window listed
* in the structure).
*/
Window
WindowOfEvent(XEvent *e)
{
/*
* Each window subfield is marked with whether or not it is the same as
* XEvent.xany.window or is different (which is the case for some of the
* notify events).
*/
switch(e->type) {
case KeyPress:
case KeyRelease:
return e->xkey.window; /* same */
case ButtonPress:
case ButtonRelease:
return e->xbutton.window; /* same */
case MotionNotify:
return e->xmotion.window; /* same */
case EnterNotify:
case LeaveNotify:
return e->xcrossing.window; /* same */
case FocusIn:
case FocusOut:
return e->xfocus.window; /* same */
case KeymapNotify:
return e->xkeymap.window; /* same */
case Expose:
return e->xexpose.window; /* same */
case GraphicsExpose:
return e->xgraphicsexpose.drawable; /* same */
case NoExpose:
return e->xnoexpose.drawable; /* same */
case VisibilityNotify:
return e->xvisibility.window; /* same */
case CreateNotify:
return e->xcreatewindow.window; /* DIFF */
case DestroyNotify:
return e->xdestroywindow.window; /* DIFF */
case UnmapNotify:
return e->xunmap.window; /* DIFF */
case MapNotify:
return e->xmap.window; /* DIFF */
case MapRequest:
return e->xmaprequest.window; /* DIFF */
case ReparentNotify:
return e->xreparent.window; /* DIFF */
case ConfigureNotify:
return e->xconfigure.window; /* DIFF */
case ConfigureRequest:
return e->xconfigurerequest.window; /* DIFF */
case GravityNotify:
return e->xgravity.window; /* DIFF */
case ResizeRequest:
return e->xresizerequest.window; /* same */
case CirculateNotify:
return e->xcirculate.window; /* DIFF */
case CirculateRequest:
return e->xcirculaterequest.window; /* DIFF */
case PropertyNotify:
return e->xproperty.window; /* same */
case SelectionClear:
return e->xselectionclear.window; /* same */
case SelectionRequest:
return e->xselectionrequest.requestor; /* DIFF */
case SelectionNotify:
return e->xselection.requestor; /* same */
case ColormapNotify:
return e->xcolormap.window; /* same */
case ClientMessage:
return e->xclient.window; /* same */
case MappingNotify:
return None;
}
return None;
}
void
FixRootEvent(XEvent *e)
{
if(Scr->Root == Scr->RealRoot) {
return;
}
switch(e->type) {
case KeyPress:
case KeyRelease:
e->xkey.x_root -= Scr->rootx;
e->xkey.y_root -= Scr->rooty;
e->xkey.root = Scr->Root;
break;
case ButtonPress:
case ButtonRelease:
e->xbutton.x_root -= Scr->rootx;
e->xbutton.y_root -= Scr->rooty;
e->xbutton.root = Scr->Root;
break;
case MotionNotify:
e->xmotion.x_root -= Scr->rootx;
e->xmotion.y_root -= Scr->rooty;
e->xmotion.root = Scr->Root;
break;
case EnterNotify:
case LeaveNotify:
e->xcrossing.x_root -= Scr->rootx;
e->xcrossing.y_root -= Scr->rooty;
e->xcrossing.root = Scr->Root;
break;
default:
break;
}
}
/* Move this next to GetTwmWindow()? */
ScreenInfo *
GetTwmScreen(XEvent *event)
{
ScreenInfo *scr;
if(XFindContext(dpy, event->xany.window, ScreenContext,
(XPointer *)&scr) == XCNOENT) {
scr = FindScreenInfo(WindowOfEvent(event));
}
return scr;
}
/***********************************************************************
*
* Procedure:
* FindScreenInfo - get ScreenInfo struct associated with a given window
*
* Returned Value:
* ScreenInfo struct
*
* Inputs:
* w - the window
*
***********************************************************************
*/
static ScreenInfo *
FindScreenInfo(Window w)
{
XWindowAttributes attr;
int scrnum;
attr.screen = NULL;
if(XGetWindowAttributes(dpy, w, &attr)) {
for(scrnum = 0; scrnum < NumScreens; scrnum++) {
if(ScreenList[scrnum] != NULL &&
(ScreenOfDisplay(dpy, ScreenList[scrnum]->screen) ==
attr.screen)) {
return ScreenList[scrnum];
}
}
}
return NULL;
}
void
SynthesiseFocusOut(Window w)
{
XEvent event;
#ifdef TRACE_FOCUS
fprintf(stderr, "Synthesizing FocusOut on %x\n", w);
#endif
event.type = FocusOut;
event.xfocus.window = w;
event.xfocus.mode = NotifyNormal;
event.xfocus.detail = NotifyPointer;
XPutBackEvent(dpy, &event);
}
void
SynthesiseFocusIn(Window w)
{
XEvent event;
#ifdef TRACE_FOCUS
fprintf(stderr, "Synthesizing FocusIn on %x\n", w);
#endif
event.type = FocusIn;
event.xfocus.window = w;
event.xfocus.mode = NotifyNormal;
event.xfocus.detail = NotifyPointer;
XPutBackEvent(dpy, &event);
}
/*
* This is actually never called anywhere in event code, but it digs into
* the innards of events to do somewhat scary things.
*/
void
SimulateMapRequest(Window w)
{
Event.xmaprequest.window = w;
HandleMapRequest();
}