Xinqi Bao's Git
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
7 #include <X11/keysym.h>
15 void (*func
)(Arg
*arg
);
21 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
24 movemouse(Client
*c
) {
25 int x1
, y1
, ocx
, ocy
, di
;
32 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
33 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
36 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
38 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
, &ev
);
45 c
->x
= ocx
+ (ev
.xmotion
.x
- x1
);
46 c
->y
= ocy
+ (ev
.xmotion
.y
- y1
);
47 resize(c
, False
, TopLeft
);
50 XUngrabPointer(dpy
, CurrentTime
);
57 resizemouse(Client
*c
) {
65 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
66 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
69 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
, c
->h
);
71 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
, &ev
);
78 if((nw
= abs(ocx
- ev
.xmotion
.x
)))
80 if((nh
= abs(ocy
- ev
.xmotion
.y
)))
82 c
->x
= (ocx
<= ev
.xmotion
.x
) ? ocx
: ocx
- c
->w
;
83 c
->y
= (ocy
<= ev
.xmotion
.y
) ? ocy
: ocy
- c
->h
;
84 if(ocx
<= ev
.xmotion
.x
)
85 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopLeft
: BotLeft
;
87 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopRight
: BotRight
;
88 resize(c
, True
, sticky
);
91 XUngrabPointer(dpy
, CurrentTime
);
98 buttonpress(XEvent
*e
) {
102 XButtonPressedEvent
*ev
= &e
->xbutton
;
104 if(barwin
== ev
->window
) {
106 for(a
.i
= 0; a
.i
< ntags
; a
.i
++) {
107 x
+= textw(tags
[a
.i
]);
109 if(ev
->button
== Button1
) {
110 if(ev
->state
& MODKEY
)
115 else if(ev
->button
== Button3
) {
116 if(ev
->state
& MODKEY
)
124 if(ev
->x
< x
+ bmw
) {
125 if(ev
->button
== Button1
)
129 else if((c
= getclient(ev
->window
))) {
131 if(CLEANMASK(ev
->state
) != MODKEY
)
133 if(ev
->button
== Button1
&& (arrange
== dofloat
|| c
->isfloat
)) {
137 else if(ev
->button
== Button2
)
139 else if(ev
->button
== Button3
&& (arrange
== dofloat
|| c
->isfloat
)) {
147 configurerequest(XEvent
*e
) {
148 unsigned long newmask
;
150 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
154 if((c
= getclient(ev
->window
))) {
157 if(ev
->value_mask
& CWX
)
159 if(ev
->value_mask
& CWY
)
161 if(ev
->value_mask
& CWWidth
)
163 if(ev
->value_mask
& CWHeight
)
165 if(ev
->value_mask
& CWBorderWidth
)
166 c
->border
= ev
->border_width
;
172 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
174 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
176 synev
.type
= ConfigureNotify
;
177 synev
.xconfigure
.display
= dpy
;
178 synev
.xconfigure
.event
= c
->win
;
179 synev
.xconfigure
.window
= c
->win
;
180 synev
.xconfigure
.x
= c
->x
;
181 synev
.xconfigure
.y
= c
->y
;
182 synev
.xconfigure
.width
= c
->w
;
183 synev
.xconfigure
.height
= c
->h
;
184 synev
.xconfigure
.border_width
= c
->border
;
185 synev
.xconfigure
.above
= None
;
186 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
190 resize(c
, False
, TopLeft
);
197 wc
.width
= ev
->width
;
198 wc
.height
= ev
->height
;
199 wc
.border_width
= ev
->border_width
;
200 wc
.sibling
= ev
->above
;
201 wc
.stack_mode
= ev
->detail
;
202 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
208 destroynotify(XEvent
*e
) {
210 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
212 if((c
= getclient(ev
->window
)))
217 enternotify(XEvent
*e
) {
219 XCrossingEvent
*ev
= &e
->xcrossing
;
221 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
224 if(((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
))) && isvisible(c
))
226 else if(ev
->window
== root
) {
228 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
236 XExposeEvent
*ev
= &e
->xexpose
;
239 if(barwin
== ev
->window
)
241 else if((c
= getctitle(ev
->window
)))
247 keypress(XEvent
*e
) {
248 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
251 XKeyEvent
*ev
= &e
->xkey
;
253 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
254 for(i
= 0; i
< len
; i
++) {
255 if(keysym
== key
[i
].keysym
256 && CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
259 key
[i
].func(&key
[i
].arg
);
266 leavenotify(XEvent
*e
) {
267 XCrossingEvent
*ev
= &e
->xcrossing
;
269 if((ev
->window
== root
) && !ev
->same_screen
) {
276 mappingnotify(XEvent
*e
) {
277 XMappingEvent
*ev
= &e
->xmapping
;
279 XRefreshKeyboardMapping(ev
);
280 if(ev
->request
== MappingKeyboard
)
285 maprequest(XEvent
*e
) {
286 static XWindowAttributes wa
;
287 XMapRequestEvent
*ev
= &e
->xmaprequest
;
289 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
292 if(wa
.override_redirect
) {
293 XSelectInput(dpy
, ev
->window
,
294 (StructureNotifyMask
| PropertyChangeMask
));
298 if(!getclient(ev
->window
))
299 manage(ev
->window
, &wa
);
303 propertynotify(XEvent
*e
) {
306 XPropertyEvent
*ev
= &e
->xproperty
;
308 if(ev
->state
== PropertyDelete
)
311 if((c
= getclient(ev
->window
))) {
312 if(ev
->atom
== wmatom
[WMProtocols
]) {
313 c
->proto
= getproto(c
->win
);
318 case XA_WM_TRANSIENT_FOR
:
319 XGetTransientForHint(dpy
, c
->win
, &trans
);
320 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
323 case XA_WM_NORMAL_HINTS
:
327 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
335 unmapnotify(XEvent
*e
) {
337 XUnmapEvent
*ev
= &e
->xunmap
;
339 if((c
= getclient(ev
->window
)))
345 void (*handler
[LASTEvent
]) (XEvent
*) = {
346 [ButtonPress
] = buttonpress
,
347 [ConfigureRequest
] = configurerequest
,
348 [DestroyNotify
] = destroynotify
,
349 [EnterNotify
] = enternotify
,
350 [LeaveNotify
] = leavenotify
,
352 [KeyPress
] = keypress
,
353 [MappingNotify
] = mappingnotify
,
354 [MapRequest
] = maprequest
,
355 [PropertyNotify
] = propertynotify
,
356 [UnmapNotify
] = unmapnotify
361 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
365 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
366 for(i
= 0; i
< len
; i
++) {
367 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
368 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
369 GrabModeAsync
, GrabModeAsync
);
370 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
371 GrabModeAsync
, GrabModeAsync
);
372 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
373 GrabModeAsync
, GrabModeAsync
);
374 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
375 GrabModeAsync
, GrabModeAsync
);
383 while(XPending(dpy
)) {
384 XNextEvent(dpy
, &ev
);
386 (handler
[ev
.type
])(&ev
); /* call handler */