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
)
66 if(XGrabPointer(dpy
, root
, False
, MOUSEMASK
, GrabModeAsync
, GrabModeAsync
,
67 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
69 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, c
->w
, c
->h
);
71 XMaskEvent(dpy
, MOUSEMASK
| ExposureMask
, &ev
);
79 c
->w
= abs(ocx
- ev
.xmotion
.x
);
80 c
->h
= abs(ocy
- ev
.xmotion
.y
);
81 c
->x
= (ocx
<= ev
.xmotion
.x
) ? ocx
: ocx
- c
->w
;
82 c
->y
= (ocy
<= ev
.xmotion
.y
) ? ocy
: ocy
- c
->h
;
83 if(ocx
<= ev
.xmotion
.x
)
84 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopLeft
: BotLeft
;
86 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopRight
: BotRight
;
87 resize(c
, True
, sticky
);
90 XUngrabPointer(dpy
, CurrentTime
);
97 buttonpress(XEvent
*e
)
102 XButtonPressedEvent
*ev
= &e
->xbutton
;
104 if(barwin
== ev
->window
) {
108 for(a
.i
= 0; a
.i
< ntags
; a
.i
++) {
109 x
+= textw(tags
[a
.i
]);
128 else if((c
= getclient(ev
->window
))) {
135 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
))
142 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
))
150 configurerequest(XEvent
*e
)
153 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
156 unsigned long newmask
;
158 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
);
179 synev
.type
= ConfigureNotify
;
180 synev
.xconfigure
.display
= dpy
;
181 synev
.xconfigure
.event
= c
->win
;
182 synev
.xconfigure
.window
= c
->win
;
183 synev
.xconfigure
.x
= c
->x
;
184 synev
.xconfigure
.y
= c
->y
;
185 synev
.xconfigure
.width
= c
->w
;
186 synev
.xconfigure
.height
= c
->h
;
187 synev
.xconfigure
.border_width
= c
->border
;
188 synev
.xconfigure
.above
= None
;
189 /* Send synthetic ConfigureNotify */
190 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
194 resize(c
, False
, TopLeft
);
201 wc
.width
= ev
->width
;
202 wc
.height
= ev
->height
;
203 wc
.border_width
= ev
->border_width
;
204 wc
.sibling
= ev
->above
;
205 wc
.stack_mode
= ev
->detail
;
206 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
212 destroynotify(XEvent
*e
)
215 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
217 if((c
= getclient(ev
->window
)))
222 enternotify(XEvent
*e
)
225 XCrossingEvent
*ev
= &e
->xcrossing
;
227 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
230 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
232 else if(ev
->window
== root
) {
234 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
243 XExposeEvent
*ev
= &e
->xexpose
;
246 if(barwin
== ev
->window
)
248 else if((c
= getctitle(ev
->window
)))
256 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
259 XKeyEvent
*ev
= &e
->xkey
;
261 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
262 for(i
= 0; i
< len
; i
++)
263 if(keysym
== key
[i
].keysym
&&
264 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
)) {
266 key
[i
].func(&key
[i
].arg
);
272 leavenotify(XEvent
*e
)
274 XCrossingEvent
*ev
= &e
->xcrossing
;
276 if((ev
->window
== root
) && !ev
->same_screen
) {
283 maprequest(XEvent
*e
)
285 static XWindowAttributes wa
;
286 XMapRequestEvent
*ev
= &e
->xmaprequest
;
288 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
291 if(wa
.override_redirect
) {
292 XSelectInput(dpy
, ev
->window
,
293 (StructureNotifyMask
| PropertyChangeMask
));
297 if(!getclient(ev
->window
))
298 manage(ev
->window
, &wa
);
302 propertynotify(XEvent
*e
)
306 XPropertyEvent
*ev
= &e
->xproperty
;
308 if(ev
->state
== PropertyDelete
)
311 if((c
= getclient(ev
->window
))) {
312 if(ev
->atom
== wmatom
[WMProtocols
]) {
313 c
->proto
= getproto(c
->win
);
318 case XA_WM_TRANSIENT_FOR
:
319 XGetTransientForHint(dpy
, c
->win
, &trans
);
320 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
323 case XA_WM_NORMAL_HINTS
:
327 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
335 unmapnotify(XEvent
*e
)
338 XUnmapEvent
*ev
= &e
->xunmap
;
340 if((c
= getclient(ev
->window
)))
346 void (*handler
[LASTEvent
]) (XEvent
*) = {
347 [ButtonPress
] = buttonpress
,
348 [ConfigureRequest
] = configurerequest
,
349 [DestroyNotify
] = destroynotify
,
350 [EnterNotify
] = enternotify
,
351 [LeaveNotify
] = leavenotify
,
353 [KeyPress
] = keypress
,
354 [MapRequest
] = maprequest
,
355 [PropertyNotify
] = propertynotify
,
356 [UnmapNotify
] = unmapnotify
362 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
366 for(i
= 0; i
< len
; i
++) {
367 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
368 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
369 GrabModeAsync
, GrabModeAsync
);
370 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
371 GrabModeAsync
, GrabModeAsync
);
372 XGrabKey(dpy
, code
, key
[i
].mod
| NUMLOCKMASK
, root
, True
,
373 GrabModeAsync
, GrabModeAsync
);
374 XGrabKey(dpy
, code
, key
[i
].mod
| NUMLOCKMASK
| LockMask
, root
, True
,
375 GrabModeAsync
, GrabModeAsync
);