Xinqi Bao's Git
344a0cc9f1d86a36000b3fdd819bd226764b824a
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
9 #include <X11/keysym.h>
10 #include <X11/Xatom.h>
15 static void configurerequest(XEvent
*e
);
16 static void destroynotify(XEvent
*e
);
17 static void enternotify(XEvent
*e
);
18 static void leavenotify(XEvent
*e
);
19 static void expose(XEvent
*e
);
20 static void keymapnotify(XEvent
*e
);
21 static void maprequest(XEvent
*e
);
22 static void propertynotify(XEvent
*e
);
23 static void unmapnotify(XEvent
*e
);
25 void (*handler
[LASTEvent
]) (XEvent
*) = {
26 [ConfigureRequest
] = configurerequest
,
27 [DestroyNotify
] = destroynotify
,
28 [EnterNotify
] = enternotify
,
29 [LeaveNotify
] = leavenotify
,
31 [KeyPress
] = keypress
,
32 [KeymapNotify
] = keymapnotify
,
33 [MapRequest
] = maprequest
,
34 [PropertyNotify
] = propertynotify
,
35 [UnmapNotify
] = unmapnotify
39 flush_events(long even_mask
)
43 while(XCheckMaskEvent(dpy
, even_mask
, &ev
)) n
++;
48 configurerequest(XEvent
*e
)
50 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
54 c
= getclient(ev
->window
);
55 ev
->value_mask
&= ~CWSibling
;
57 if(ev
->value_mask
& CWX
)
58 c
->r
[RFloat
].x
= ev
->x
;
59 if(ev
->value_mask
& CWY
)
60 c
->r
[RFloat
].y
= ev
->y
;
61 if(ev
->value_mask
& CWWidth
)
62 c
->r
[RFloat
].width
= ev
->width
;
63 if(ev
->value_mask
& CWHeight
)
64 c
->r
[RFloat
].height
= ev
->height
;
65 if(ev
->value_mask
& CWBorderWidth
)
66 c
->border
= ev
->border_width
;
72 wc
.height
= ev
->height
;
75 wc
.stack_mode
= Above
;
76 ev
->value_mask
&= ~CWStackMode
;
77 ev
->value_mask
|= CWBorderWidth
;
78 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
83 destroynotify(XEvent
*e
)
86 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
88 if((c
= getclient(ev
->window
)))
93 enternotify(XEvent
*e
)
95 XCrossingEvent
*ev
= &e
->xcrossing
;
98 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
101 if((c
= getclient(ev
->window
)))
103 else if(ev
->window
== root
) {
110 leavenotify(XEvent
*e
)
112 XCrossingEvent
*ev
= &e
->xcrossing
;
114 if((ev
->window
== root
) && !ev
->same_screen
) {
123 XExposeEvent
*ev
= &e
->xexpose
;
126 if(ev
->window
== barwin
)
132 keymapnotify(XEvent
*e
)
138 maprequest(XEvent
*e
)
140 XMapRequestEvent
*ev
= &e
->xmaprequest
;
141 static XWindowAttributes wa
;
143 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
146 if(wa
.override_redirect
) {
147 XSelectInput(dpy
, ev
->window
,
148 (StructureNotifyMask
| PropertyChangeMask
));
152 if(!getclient(ev
->window
))
153 manage(ev
->window
, &wa
);
157 propertynotify(XEvent
*e
)
159 XPropertyEvent
*ev
= &e
->xproperty
;
163 if(ev
->state
== PropertyDelete
)
166 if(ev
->atom
== wm_atom
[WMProtocols
]) {
167 c
->proto
= win_proto(c
->win
);
170 if((c
= getclient(ev
->window
))) {
173 case XA_WM_TRANSIENT_FOR
:
174 XGetTransientForHint(dpy
, c
->win
, &c
->trans
);
176 case XA_WM_NORMAL_HINTS
:
177 if(!XGetWMNormalHints(dpy
, c
->win
, &c
->size
, &msize
)
179 c
->size
.flags
= PSize
;
180 if(c
->size
.flags
& PMinSize
&& c
->size
.flags
& PMaxSize
181 && c
->size
.min_width
== c
->size
.max_width
182 && c
->size
.min_height
== c
->size
.max_height
)
185 c
->fixedsize
= False
;
188 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== net_atom
[NetWMName
]) {
195 unmapnotify(XEvent
*e
)
198 XUnmapEvent
*ev
= &e
->xunmap
;
200 if((c
= getclient(ev
->window
)))