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
)
120 else if((c
= getclient(ev
->window
))) {
122 if(CLEANMASK(ev
->state
) == 0)
128 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
137 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
147 configurerequest(XEvent
*e
)
149 unsigned long newmask
;
151 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
155 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 /* Send synthetic ConfigureNotify */
187 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
191 resize(c
, False
, TopLeft
);
198 wc
.width
= ev
->width
;
199 wc
.height
= ev
->height
;
200 wc
.border_width
= ev
->border_width
;
201 wc
.sibling
= ev
->above
;
202 wc
.stack_mode
= ev
->detail
;
203 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
209 destroynotify(XEvent
*e
)
212 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
214 if((c
= getclient(ev
->window
)))
219 enternotify(XEvent
*e
)
222 XCrossingEvent
*ev
= &e
->xcrossing
;
224 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
227 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
229 else if(ev
->window
== root
) {
231 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
240 XExposeEvent
*ev
= &e
->xexpose
;
243 if(barwin
== ev
->window
)
245 else if((c
= getctitle(ev
->window
)))
253 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
256 XKeyEvent
*ev
= &e
->xkey
;
258 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
259 for(i
= 0; i
< len
; i
++) {
260 if(keysym
== key
[i
].keysym
&&
261 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
264 key
[i
].func(&key
[i
].arg
);
271 leavenotify(XEvent
*e
)
273 XCrossingEvent
*ev
= &e
->xcrossing
;
275 if((ev
->window
== root
) && !ev
->same_screen
) {
282 mappingnotify(XEvent
*e
)
284 XMappingEvent
*ev
= &e
->xmapping
;
286 XRefreshKeyboardMapping(ev
);
287 if(ev
->request
== MappingKeyboard
)
292 maprequest(XEvent
*e
)
294 static XWindowAttributes wa
;
295 XMapRequestEvent
*ev
= &e
->xmaprequest
;
297 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
300 if(wa
.override_redirect
) {
301 XSelectInput(dpy
, ev
->window
,
302 (StructureNotifyMask
| PropertyChangeMask
));
306 if(!getclient(ev
->window
))
307 manage(ev
->window
, &wa
);
311 propertynotify(XEvent
*e
)
315 XPropertyEvent
*ev
= &e
->xproperty
;
317 if(ev
->state
== PropertyDelete
)
320 if((c
= getclient(ev
->window
))) {
321 if(ev
->atom
== wmatom
[WMProtocols
]) {
322 c
->proto
= getproto(c
->win
);
327 case XA_WM_TRANSIENT_FOR
:
328 XGetTransientForHint(dpy
, c
->win
, &trans
);
329 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
332 case XA_WM_NORMAL_HINTS
:
336 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
344 unmapnotify(XEvent
*e
)
347 XUnmapEvent
*ev
= &e
->xunmap
;
349 if((c
= getclient(ev
->window
)))
355 void (*handler
[LASTEvent
]) (XEvent
*) = {
356 [ButtonPress
] = buttonpress
,
357 [ConfigureRequest
] = configurerequest
,
358 [DestroyNotify
] = destroynotify
,
359 [EnterNotify
] = enternotify
,
360 [LeaveNotify
] = leavenotify
,
362 [KeyPress
] = keypress
,
363 [MappingNotify
] = mappingnotify
,
364 [MapRequest
] = maprequest
,
365 [PropertyNotify
] = propertynotify
,
366 [UnmapNotify
] = unmapnotify
372 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
376 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
377 for(i
= 0; i
< len
; i
++) {
378 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
379 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
380 GrabModeAsync
, GrabModeAsync
);
381 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
382 GrabModeAsync
, GrabModeAsync
);
383 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
384 GrabModeAsync
, GrabModeAsync
);
385 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
386 GrabModeAsync
, GrabModeAsync
);
395 while(XPending(dpy
)) {
396 XNextEvent(dpy
, &ev
);
398 (handler
[ev
.type
])(&ev
); /* call handler */