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
]);
112 if(ev
->button
== Button1
)
114 else if(ev
->button
== Button3
)
119 if(ev
->x
< x
+ bmw
) {
120 if(ev
->button
== Button1
)
124 else if((c
= getclient(ev
->window
))) {
126 if(CLEANMASK(ev
->state
) != MODKEY
)
132 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
141 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
151 configurerequest(XEvent
*e
)
153 unsigned long newmask
;
155 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
159 if((c
= getclient(ev
->window
))) {
161 if(ev
->value_mask
& CWX
)
163 if(ev
->value_mask
& CWY
)
165 if(ev
->value_mask
& CWWidth
)
167 if(ev
->value_mask
& CWHeight
)
169 if(ev
->value_mask
& CWBorderWidth
)
170 c
->border
= ev
->border_width
;
176 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
178 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
180 synev
.type
= ConfigureNotify
;
181 synev
.xconfigure
.display
= dpy
;
182 synev
.xconfigure
.event
= c
->win
;
183 synev
.xconfigure
.window
= c
->win
;
184 synev
.xconfigure
.x
= c
->x
;
185 synev
.xconfigure
.y
= c
->y
;
186 synev
.xconfigure
.width
= c
->w
;
187 synev
.xconfigure
.height
= c
->h
;
188 synev
.xconfigure
.border_width
= c
->border
;
189 synev
.xconfigure
.above
= None
;
190 /* Send synthetic ConfigureNotify */
191 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
195 resize(c
, False
, TopLeft
);
202 wc
.width
= ev
->width
;
203 wc
.height
= ev
->height
;
204 wc
.border_width
= ev
->border_width
;
205 wc
.sibling
= ev
->above
;
206 wc
.stack_mode
= ev
->detail
;
207 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
213 destroynotify(XEvent
*e
)
216 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
218 if((c
= getclient(ev
->window
)))
223 enternotify(XEvent
*e
)
226 XCrossingEvent
*ev
= &e
->xcrossing
;
228 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
231 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
233 else if(ev
->window
== root
) {
235 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
244 XExposeEvent
*ev
= &e
->xexpose
;
247 if(barwin
== ev
->window
)
249 else if((c
= getctitle(ev
->window
)))
257 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
260 XKeyEvent
*ev
= &e
->xkey
;
262 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
263 for(i
= 0; i
< len
; i
++) {
264 if(keysym
== key
[i
].keysym
&&
265 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
268 key
[i
].func(&key
[i
].arg
);
275 leavenotify(XEvent
*e
)
277 XCrossingEvent
*ev
= &e
->xcrossing
;
279 if((ev
->window
== root
) && !ev
->same_screen
) {
286 mappingnotify(XEvent
*e
)
288 XMappingEvent
*ev
= &e
->xmapping
;
290 XRefreshKeyboardMapping(ev
);
291 if(ev
->request
== MappingKeyboard
)
296 maprequest(XEvent
*e
)
298 static XWindowAttributes wa
;
299 XMapRequestEvent
*ev
= &e
->xmaprequest
;
301 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
304 if(wa
.override_redirect
) {
305 XSelectInput(dpy
, ev
->window
,
306 (StructureNotifyMask
| PropertyChangeMask
));
310 if(!getclient(ev
->window
))
311 manage(ev
->window
, &wa
);
315 propertynotify(XEvent
*e
)
319 XPropertyEvent
*ev
= &e
->xproperty
;
321 if(ev
->state
== PropertyDelete
)
324 if((c
= getclient(ev
->window
))) {
325 if(ev
->atom
== wmatom
[WMProtocols
]) {
326 c
->proto
= getproto(c
->win
);
331 case XA_WM_TRANSIENT_FOR
:
332 XGetTransientForHint(dpy
, c
->win
, &trans
);
333 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
336 case XA_WM_NORMAL_HINTS
:
340 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
348 unmapnotify(XEvent
*e
)
351 XUnmapEvent
*ev
= &e
->xunmap
;
353 if((c
= getclient(ev
->window
)))
359 void (*handler
[LASTEvent
]) (XEvent
*) = {
360 [ButtonPress
] = buttonpress
,
361 [ConfigureRequest
] = configurerequest
,
362 [DestroyNotify
] = destroynotify
,
363 [EnterNotify
] = enternotify
,
364 [LeaveNotify
] = leavenotify
,
366 [KeyPress
] = keypress
,
367 [MappingNotify
] = mappingnotify
,
368 [MapRequest
] = maprequest
,
369 [PropertyNotify
] = propertynotify
,
370 [UnmapNotify
] = unmapnotify
376 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
380 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
381 for(i
= 0; i
< len
; i
++) {
382 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
383 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
384 GrabModeAsync
, GrabModeAsync
);
385 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
386 GrabModeAsync
, GrabModeAsync
);
387 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
388 GrabModeAsync
, GrabModeAsync
);
389 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
390 GrabModeAsync
, GrabModeAsync
);
399 while(XPending(dpy
)) {
400 XNextEvent(dpy
, &ev
);
402 (handler
[ev
.type
])(&ev
); /* call handler */