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