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
)
154 unsigned long newmask
;
156 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
160 if((c
= getclient(ev
->window
))) {
166 if(ev
->value_mask
& CWX
)
168 if(ev
->value_mask
& CWY
)
170 if(ev
->value_mask
& CWWidth
)
172 if(ev
->value_mask
& CWHeight
)
174 if(ev
->value_mask
& CWBorderWidth
)
175 c
->border
= ev
->border_width
;
181 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
183 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
185 synev
.type
= ConfigureNotify
;
186 synev
.xconfigure
.display
= dpy
;
187 synev
.xconfigure
.event
= c
->win
;
188 synev
.xconfigure
.window
= c
->win
;
189 synev
.xconfigure
.x
= c
->x
;
190 synev
.xconfigure
.y
= c
->y
;
191 synev
.xconfigure
.width
= c
->w
;
192 synev
.xconfigure
.height
= c
->h
;
193 synev
.xconfigure
.border_width
= c
->border
;
194 synev
.xconfigure
.above
= None
;
195 /* Send synthetic ConfigureNotify */
196 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
200 resize(c
, False
, TopLeft
);
202 resize(c
, False
, TopLeft
);
214 wc
.width
= ev
->width
;
215 wc
.height
= ev
->height
;
216 wc
.border_width
= ev
->border_width
;
217 wc
.sibling
= ev
->above
;
218 wc
.stack_mode
= ev
->detail
;
219 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
225 destroynotify(XEvent
*e
)
228 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
230 if((c
= getclient(ev
->window
)))
235 enternotify(XEvent
*e
)
238 XCrossingEvent
*ev
= &e
->xcrossing
;
240 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
243 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
245 else if(ev
->window
== root
) {
247 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
256 XExposeEvent
*ev
= &e
->xexpose
;
259 if(barwin
== ev
->window
)
261 else if((c
= getctitle(ev
->window
)))
269 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
272 XKeyEvent
*ev
= &e
->xkey
;
274 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
275 for(i
= 0; i
< len
; i
++) {
276 if(keysym
== key
[i
].keysym
&&
277 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
280 key
[i
].func(&key
[i
].arg
);
287 leavenotify(XEvent
*e
)
289 XCrossingEvent
*ev
= &e
->xcrossing
;
291 if((ev
->window
== root
) && !ev
->same_screen
) {
298 mappingnotify(XEvent
*e
)
300 XMappingEvent
*ev
= &e
->xmapping
;
302 XRefreshKeyboardMapping(ev
);
303 if(ev
->request
== MappingKeyboard
)
308 maprequest(XEvent
*e
)
310 static XWindowAttributes wa
;
311 XMapRequestEvent
*ev
= &e
->xmaprequest
;
313 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
316 if(wa
.override_redirect
) {
317 XSelectInput(dpy
, ev
->window
,
318 (StructureNotifyMask
| PropertyChangeMask
));
322 if(!getclient(ev
->window
))
323 manage(ev
->window
, &wa
);
327 propertynotify(XEvent
*e
)
331 XPropertyEvent
*ev
= &e
->xproperty
;
333 if(ev
->state
== PropertyDelete
)
336 if((c
= getclient(ev
->window
))) {
337 if(ev
->atom
== wmatom
[WMProtocols
]) {
338 c
->proto
= getproto(c
->win
);
343 case XA_WM_TRANSIENT_FOR
:
344 XGetTransientForHint(dpy
, c
->win
, &trans
);
345 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
348 case XA_WM_NORMAL_HINTS
:
352 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
360 unmapnotify(XEvent
*e
)
363 XUnmapEvent
*ev
= &e
->xunmap
;
365 if((c
= getclient(ev
->window
)))
371 void (*handler
[LASTEvent
]) (XEvent
*) = {
372 [ButtonPress
] = buttonpress
,
373 [ConfigureRequest
] = configurerequest
,
374 [DestroyNotify
] = destroynotify
,
375 [EnterNotify
] = enternotify
,
376 [LeaveNotify
] = leavenotify
,
378 [KeyPress
] = keypress
,
379 [MappingNotify
] = mappingnotify
,
380 [MapRequest
] = maprequest
,
381 [PropertyNotify
] = propertynotify
,
382 [UnmapNotify
] = unmapnotify
388 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
392 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
393 for(i
= 0; i
< len
; i
++) {
394 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
395 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
396 GrabModeAsync
, GrabModeAsync
);
397 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
398 GrabModeAsync
, GrabModeAsync
);
399 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
400 GrabModeAsync
, GrabModeAsync
);
401 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
402 GrabModeAsync
, GrabModeAsync
);
411 while(XPending(dpy
)) {
412 XNextEvent(dpy
, &ev
);
414 (handler
[ev
.type
])(&ev
); /* call handler */