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
);
41 resize(c
, True
, TopLeft
);
42 XUngrabPointer(dpy
, CurrentTime
);
49 c
->x
= ocx
+ (ev
.xmotion
.x
- x1
);
50 c
->y
= ocy
+ (ev
.xmotion
.y
- y1
);
51 resize(c
, False
, TopLeft
);
58 resizemouse(Client
*c
) {
66 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
67 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
70 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
, c
->h
);
72 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
, &ev
);
75 resize(c
, True
, TopLeft
);
76 XUngrabPointer(dpy
, CurrentTime
);
83 if((nw
= abs(ocx
- ev
.xmotion
.x
)))
85 if((nh
= abs(ocy
- ev
.xmotion
.y
)))
87 c
->x
= (ocx
<= ev
.xmotion
.x
) ? ocx
: ocx
- c
->w
;
88 c
->y
= (ocy
<= ev
.xmotion
.y
) ? ocy
: ocy
- c
->h
;
89 if(ocx
<= ev
.xmotion
.x
)
90 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopLeft
: BotLeft
;
92 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopRight
: BotRight
;
93 resize(c
, True
, sticky
);
100 buttonpress(XEvent
*e
) {
104 XButtonPressedEvent
*ev
= &e
->xbutton
;
106 if(barwin
== ev
->window
) {
108 for(a
.i
= 0; a
.i
< ntags
; a
.i
++) {
109 x
+= textw(tags
[a
.i
]);
111 if(ev
->button
== Button1
) {
112 if(ev
->state
& MODKEY
)
117 else if(ev
->button
== Button3
) {
118 if(ev
->state
& MODKEY
)
126 if(ev
->x
< x
+ bmw
) {
127 if(ev
->button
== Button1
)
129 else if(ev
->button
== Button3
)
130 togglestackpos(NULL
);
133 else if((c
= getclient(ev
->window
))) {
135 if(CLEANMASK(ev
->state
) != MODKEY
)
137 if(ev
->button
== Button1
&& (arrange
== dofloat
|| c
->isfloat
)) {
141 else if(ev
->button
== Button2
)
143 else if(ev
->button
== Button3
&& (arrange
== dofloat
|| c
->isfloat
)) {
151 configurerequest(XEvent
*e
) {
152 unsigned long newmask
;
154 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
157 if((c
= getclient(ev
->window
))) {
160 if(ev
->value_mask
& CWX
)
162 if(ev
->value_mask
& CWY
)
164 if(ev
->value_mask
& CWWidth
)
166 if(ev
->value_mask
& CWHeight
)
168 if(ev
->value_mask
& CWBorderWidth
)
169 c
->border
= ev
->border_width
;
175 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
177 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
182 resize(c
, False
, TopLeft
);
192 wc
.width
= ev
->width
;
193 wc
.height
= ev
->height
;
194 wc
.border_width
= ev
->border_width
;
195 wc
.sibling
= ev
->above
;
196 wc
.stack_mode
= ev
->detail
;
197 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
203 destroynotify(XEvent
*e
) {
205 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
207 if((c
= getclient(ev
->window
)))
212 enternotify(XEvent
*e
) {
214 XCrossingEvent
*ev
= &e
->xcrossing
;
216 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
219 if(((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
))) && isvisible(c
))
221 else if(ev
->window
== root
) {
223 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
231 XExposeEvent
*ev
= &e
->xexpose
;
234 if(barwin
== ev
->window
)
236 else if((c
= getctitle(ev
->window
)))
242 keypress(XEvent
*e
) {
243 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
246 XKeyEvent
*ev
= &e
->xkey
;
248 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
249 for(i
= 0; i
< len
; i
++) {
250 if(keysym
== key
[i
].keysym
251 && CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
254 key
[i
].func(&key
[i
].arg
);
261 leavenotify(XEvent
*e
) {
262 XCrossingEvent
*ev
= &e
->xcrossing
;
264 if((ev
->window
== root
) && !ev
->same_screen
) {
271 mappingnotify(XEvent
*e
) {
272 XMappingEvent
*ev
= &e
->xmapping
;
274 XRefreshKeyboardMapping(ev
);
275 if(ev
->request
== MappingKeyboard
)
280 maprequest(XEvent
*e
) {
281 static XWindowAttributes wa
;
282 XMapRequestEvent
*ev
= &e
->xmaprequest
;
284 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
287 if(wa
.override_redirect
) {
288 XSelectInput(dpy
, ev
->window
,
289 (StructureNotifyMask
| PropertyChangeMask
));
293 if(!getclient(ev
->window
))
294 manage(ev
->window
, &wa
);
298 propertynotify(XEvent
*e
) {
301 XPropertyEvent
*ev
= &e
->xproperty
;
303 if(ev
->state
== PropertyDelete
)
306 if((c
= getclient(ev
->window
))) {
307 if(ev
->atom
== wmatom
[WMProtocols
]) {
308 c
->proto
= getproto(c
->win
);
313 case XA_WM_TRANSIENT_FOR
:
314 XGetTransientForHint(dpy
, c
->win
, &trans
);
315 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
318 case XA_WM_NORMAL_HINTS
:
322 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
331 unmapnotify(XEvent
*e
) {
333 XUnmapEvent
*ev
= &e
->xunmap
;
335 if((c
= getclient(ev
->window
)))
341 void (*handler
[LASTEvent
]) (XEvent
*) = {
342 [ButtonPress
] = buttonpress
,
343 [ConfigureRequest
] = configurerequest
,
344 [DestroyNotify
] = destroynotify
,
345 [EnterNotify
] = enternotify
,
346 [LeaveNotify
] = leavenotify
,
348 [KeyPress
] = keypress
,
349 [MappingNotify
] = mappingnotify
,
350 [MapRequest
] = maprequest
,
351 [PropertyNotify
] = propertynotify
,
352 [UnmapNotify
] = unmapnotify
357 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
361 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
362 for(i
= 0; i
< len
; i
++) {
363 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
364 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
365 GrabModeAsync
, GrabModeAsync
);
366 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
367 GrabModeAsync
, GrabModeAsync
);
368 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
369 GrabModeAsync
, GrabModeAsync
);
370 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
371 GrabModeAsync
, GrabModeAsync
);
379 while(XPending(dpy
)) {
380 XNextEvent(dpy
, &ev
);
382 (handler
[ev
.type
])(&ev
); /* call handler */