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))
26 int x1
, y1
, ocx
, ocy
, di
;
33 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
34 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
36 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
38 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
, &ev
);
46 c
->x
= ocx
+ (ev
.xmotion
.x
- x1
);
47 c
->y
= ocy
+ (ev
.xmotion
.y
- y1
);
48 resize(c
, False
, TopLeft
);
51 XUngrabPointer(dpy
, CurrentTime
);
58 resizemouse(Client
*c
)
67 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
68 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
);
80 if((nw
= abs(ocx
- ev
.xmotion
.x
)))
81 c
->w
= abs(ocx
- ev
.xmotion
.x
);
82 if((nh
= abs(ocy
- ev
.xmotion
.y
)))
83 c
->h
= abs(ocy
- ev
.xmotion
.y
);
84 c
->x
= (ocx
<= ev
.xmotion
.x
) ? ocx
: ocx
- c
->w
;
85 c
->y
= (ocy
<= ev
.xmotion
.y
) ? ocy
: ocy
- c
->h
;
86 if(ocx
<= ev
.xmotion
.x
)
87 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopLeft
: BotLeft
;
89 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopRight
: BotRight
;
90 resize(c
, True
, sticky
);
93 XUngrabPointer(dpy
, CurrentTime
);
100 buttonpress(XEvent
*e
)
105 XButtonPressedEvent
*ev
= &e
->xbutton
;
107 if(barwin
== ev
->window
) {
109 for(a
.i
= 0; a
.i
< ntags
; a
.i
++) {
110 x
+= textw(tags
[a
.i
]);
114 if(ev
->state
& MODKEY
)
120 if(ev
->state
& MODKEY
)
129 if(ev
->x
< x
+ bmw
) {
130 if(ev
->button
== Button1
)
134 else if((c
= getclient(ev
->window
))) {
136 if(CLEANMASK(ev
->state
) != MODKEY
)
142 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
151 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
161 synconfig(Client
*c
, int x
, int y
, int w
, int h
, unsigned int border
)
165 synev
.type
= ConfigureNotify
;
166 synev
.xconfigure
.display
= dpy
;
167 synev
.xconfigure
.event
= c
->win
;
168 synev
.xconfigure
.window
= c
->win
;
169 synev
.xconfigure
.x
= x
;
170 synev
.xconfigure
.y
= y
;
171 synev
.xconfigure
.width
= w
;
172 synev
.xconfigure
.height
= h
;
173 synev
.xconfigure
.border_width
= border
;
174 synev
.xconfigure
.above
= None
;
175 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
179 configurerequest(XEvent
*e
)
181 unsigned long newmask
;
183 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
186 if((c
= getclient(ev
->window
))) {
187 if(!c
->isfloat
&& (arrange
!= dofloat
) && c
->ismax
) {
188 synconfig(c
, sx
, sy
+ bh
, sw
- 2, sh
- 2 - bh
, ev
->border_width
);
193 if(ev
->value_mask
& CWX
)
195 if(ev
->value_mask
& CWY
)
197 if(ev
->value_mask
& CWWidth
)
199 if(ev
->value_mask
& CWHeight
)
201 if(ev
->value_mask
& CWBorderWidth
)
202 c
->border
= ev
->border_width
;
208 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
210 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
212 synconfig(c
, c
->x
, c
->y
, c
->w
, c
->h
, c
->border
);
215 resize(c
, False
, TopLeft
);
222 wc
.width
= ev
->width
;
223 wc
.height
= ev
->height
;
224 wc
.border_width
= ev
->border_width
;
225 wc
.sibling
= ev
->above
;
226 wc
.stack_mode
= ev
->detail
;
227 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
233 destroynotify(XEvent
*e
)
236 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
238 if((c
= getclient(ev
->window
)))
243 enternotify(XEvent
*e
)
246 XCrossingEvent
*ev
= &e
->xcrossing
;
248 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
251 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
253 else if(ev
->window
== root
) {
255 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
264 XExposeEvent
*ev
= &e
->xexpose
;
267 if(barwin
== ev
->window
)
269 else if((c
= getctitle(ev
->window
)))
277 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
280 XKeyEvent
*ev
= &e
->xkey
;
282 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
283 for(i
= 0; i
< len
; i
++) {
284 if(keysym
== key
[i
].keysym
&&
285 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
288 key
[i
].func(&key
[i
].arg
);
295 leavenotify(XEvent
*e
)
297 XCrossingEvent
*ev
= &e
->xcrossing
;
299 if((ev
->window
== root
) && !ev
->same_screen
) {
306 mappingnotify(XEvent
*e
)
308 XMappingEvent
*ev
= &e
->xmapping
;
310 XRefreshKeyboardMapping(ev
);
311 if(ev
->request
== MappingKeyboard
)
316 maprequest(XEvent
*e
)
318 static XWindowAttributes wa
;
319 XMapRequestEvent
*ev
= &e
->xmaprequest
;
321 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
324 if(wa
.override_redirect
) {
325 XSelectInput(dpy
, ev
->window
,
326 (StructureNotifyMask
| PropertyChangeMask
));
330 if(!getclient(ev
->window
))
331 manage(ev
->window
, &wa
);
335 propertynotify(XEvent
*e
)
339 XPropertyEvent
*ev
= &e
->xproperty
;
341 if(ev
->state
== PropertyDelete
)
344 if((c
= getclient(ev
->window
))) {
345 if(ev
->atom
== wmatom
[WMProtocols
]) {
346 c
->proto
= getproto(c
->win
);
351 case XA_WM_TRANSIENT_FOR
:
352 XGetTransientForHint(dpy
, c
->win
, &trans
);
353 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
356 case XA_WM_NORMAL_HINTS
:
360 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
368 unmapnotify(XEvent
*e
)
371 XUnmapEvent
*ev
= &e
->xunmap
;
373 if((c
= getclient(ev
->window
)))
379 void (*handler
[LASTEvent
]) (XEvent
*) = {
380 [ButtonPress
] = buttonpress
,
381 [ConfigureRequest
] = configurerequest
,
382 [DestroyNotify
] = destroynotify
,
383 [EnterNotify
] = enternotify
,
384 [LeaveNotify
] = leavenotify
,
386 [KeyPress
] = keypress
,
387 [MappingNotify
] = mappingnotify
,
388 [MapRequest
] = maprequest
,
389 [PropertyNotify
] = propertynotify
,
390 [UnmapNotify
] = unmapnotify
396 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
400 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
401 for(i
= 0; i
< len
; i
++) {
402 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
403 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
404 GrabModeAsync
, GrabModeAsync
);
405 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
406 GrabModeAsync
, GrabModeAsync
);
407 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
408 GrabModeAsync
, GrabModeAsync
);
409 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
410 GrabModeAsync
, GrabModeAsync
);
419 while(XPending(dpy
)) {
420 XNextEvent(dpy
, &ev
);
422 (handler
[ev
.type
])(&ev
); /* call handler */