Xinqi Bao's Git
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 buttonpress(XEvent
*e
);
16 static void configurerequest(XEvent
*e
);
17 static void destroynotify(XEvent
*e
);
18 static void enternotify(XEvent
*e
);
19 static void leavenotify(XEvent
*e
);
20 static void expose(XEvent
*e
);
21 static void keymapnotify(XEvent
*e
);
22 static void maprequest(XEvent
*e
);
23 static void propertynotify(XEvent
*e
);
24 static void unmapnotify(XEvent
*e
);
26 void (*handler
[LASTEvent
]) (XEvent
*) = {
27 [ButtonPress
] = buttonpress
,
28 [ConfigureRequest
] = configurerequest
,
29 [DestroyNotify
] = destroynotify
,
30 [EnterNotify
] = enternotify
,
31 [LeaveNotify
] = leavenotify
,
33 [KeyPress
] = keypress
,
34 [KeymapNotify
] = keymapnotify
,
35 [MapRequest
] = maprequest
,
36 [PropertyNotify
] = propertynotify
,
37 [UnmapNotify
] = unmapnotify
41 discard_events(long even_mask
)
45 while(XCheckMaskEvent(dpy
, even_mask
, &ev
)) n
++;
50 buttonpress(XEvent
*e
)
52 XButtonPressedEvent
*ev
= &e
->xbutton
;
55 if((c
= getclient(ev
->window
))) {
63 XLowerWindow(dpy
, c
->win
);
73 configurerequest(XEvent
*e
)
75 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
79 ev
->value_mask
&= ~CWSibling
;
80 if((c
= getclient(ev
->window
))) {
81 if(ev
->value_mask
& CWX
)
82 c
->r
[RFloat
].x
= ev
->x
;
83 if(ev
->value_mask
& CWY
)
84 c
->r
[RFloat
].y
= ev
->y
;
85 if(ev
->value_mask
& CWWidth
)
86 c
->r
[RFloat
].width
= ev
->width
;
87 if(ev
->value_mask
& CWHeight
)
88 c
->r
[RFloat
].height
= ev
->height
;
89 if(ev
->value_mask
& CWBorderWidth
)
90 c
->border
= ev
->border_width
;
96 wc
.height
= ev
->height
;
99 wc
.stack_mode
= Above
;
100 ev
->value_mask
&= ~CWStackMode
;
101 ev
->value_mask
|= CWBorderWidth
;
102 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
107 destroynotify(XEvent
*e
)
110 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
112 if((c
= getclient(ev
->window
)))
117 enternotify(XEvent
*e
)
119 XCrossingEvent
*ev
= &e
->xcrossing
;
122 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
125 if((c
= getclient(ev
->window
)))
127 else if(ev
->window
== root
) {
134 leavenotify(XEvent
*e
)
136 XCrossingEvent
*ev
= &e
->xcrossing
;
138 if((ev
->window
== root
) && !ev
->same_screen
) {
147 XExposeEvent
*ev
= &e
->xexpose
;
150 if(ev
->window
== barwin
)
156 keymapnotify(XEvent
*e
)
162 maprequest(XEvent
*e
)
164 XMapRequestEvent
*ev
= &e
->xmaprequest
;
165 static XWindowAttributes wa
;
167 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
170 if(wa
.override_redirect
) {
171 XSelectInput(dpy
, ev
->window
,
172 (StructureNotifyMask
| PropertyChangeMask
));
176 if(!getclient(ev
->window
))
177 manage(ev
->window
, &wa
);
181 propertynotify(XEvent
*e
)
183 XPropertyEvent
*ev
= &e
->xproperty
;
187 if(ev
->state
== PropertyDelete
)
190 if(ev
->atom
== wm_atom
[WMProtocols
]) {
191 c
->proto
= win_proto(c
->win
);
194 if((c
= getclient(ev
->window
))) {
197 case XA_WM_TRANSIENT_FOR
:
198 XGetTransientForHint(dpy
, c
->win
, &c
->trans
);
200 case XA_WM_NORMAL_HINTS
:
201 if(!XGetWMNormalHints(dpy
, c
->win
, &c
->size
, &msize
)
203 c
->size
.flags
= PSize
;
204 if(c
->size
.flags
& PMinSize
&& c
->size
.flags
& PMaxSize
205 && c
->size
.min_width
== c
->size
.max_width
206 && c
->size
.min_height
== c
->size
.max_height
)
209 c
->fixedsize
= False
;
212 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== net_atom
[NetWMName
]) {
219 unmapnotify(XEvent
*e
)
222 XUnmapEvent
*ev
= &e
->xunmap
;
224 if((c
= getclient(ev
->window
)))