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
) {
111 for(a
.i
= 0; a
.i
< ntags
; a
.i
++) {
112 x
+= textw(tags
[a
.i
]);
114 if(ev
->button
== Button1
)
116 else if(ev
->button
== Button3
)
122 else if((c
= getclient(ev
->window
))) {
124 if(CLEANMASK(ev
->state
) == 0)
130 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
139 if(!c
->ismax
&& (arrange
== dofloat
|| c
->isfloat
)) {
149 configurerequest(XEvent
*e
)
151 unsigned long newmask
;
153 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
157 if((c
= getclient(ev
->window
))) {
159 if(ev
->value_mask
& CWX
)
161 if(ev
->value_mask
& CWY
)
163 if(ev
->value_mask
& CWWidth
)
165 if(ev
->value_mask
& CWHeight
)
167 if(ev
->value_mask
& CWBorderWidth
)
168 c
->border
= ev
->border_width
;
174 newmask
= ev
->value_mask
& (~(CWSibling
| CWStackMode
| CWBorderWidth
));
176 XConfigureWindow(dpy
, c
->win
, newmask
, &wc
);
178 synev
.type
= ConfigureNotify
;
179 synev
.xconfigure
.display
= dpy
;
180 synev
.xconfigure
.event
= c
->win
;
181 synev
.xconfigure
.window
= c
->win
;
182 synev
.xconfigure
.x
= c
->x
;
183 synev
.xconfigure
.y
= c
->y
;
184 synev
.xconfigure
.width
= c
->w
;
185 synev
.xconfigure
.height
= c
->h
;
186 synev
.xconfigure
.border_width
= c
->border
;
187 synev
.xconfigure
.above
= None
;
188 /* Send synthetic ConfigureNotify */
189 XSendEvent(dpy
, c
->win
, True
, NoEventMask
, &synev
);
193 resize(c
, False
, TopLeft
);
200 wc
.width
= ev
->width
;
201 wc
.height
= ev
->height
;
202 wc
.border_width
= ev
->border_width
;
203 wc
.sibling
= ev
->above
;
204 wc
.stack_mode
= ev
->detail
;
205 XConfigureWindow(dpy
, ev
->window
, ev
->value_mask
, &wc
);
211 destroynotify(XEvent
*e
)
214 XDestroyWindowEvent
*ev
= &e
->xdestroywindow
;
216 if((c
= getclient(ev
->window
)))
221 enternotify(XEvent
*e
)
224 XCrossingEvent
*ev
= &e
->xcrossing
;
226 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
229 if((c
= getclient(ev
->window
)) || (c
= getctitle(ev
->window
)))
231 else if(ev
->window
== root
) {
233 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
242 XExposeEvent
*ev
= &e
->xexpose
;
245 if(barwin
== ev
->window
)
247 else if((c
= getctitle(ev
->window
)))
255 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
258 XKeyEvent
*ev
= &e
->xkey
;
260 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
261 for(i
= 0; i
< len
; i
++) {
262 if(keysym
== key
[i
].keysym
&&
263 CLEANMASK(key
[i
].mod
) == CLEANMASK(ev
->state
))
266 key
[i
].func(&key
[i
].arg
);
273 leavenotify(XEvent
*e
)
275 XCrossingEvent
*ev
= &e
->xcrossing
;
277 if((ev
->window
== root
) && !ev
->same_screen
) {
284 mappingnotify(XEvent
*e
)
286 XMappingEvent
*ev
= &e
->xmapping
;
288 XRefreshKeyboardMapping(ev
);
289 if(ev
->request
== MappingKeyboard
)
294 maprequest(XEvent
*e
)
296 static XWindowAttributes wa
;
297 XMapRequestEvent
*ev
= &e
->xmaprequest
;
299 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
302 if(wa
.override_redirect
) {
303 XSelectInput(dpy
, ev
->window
,
304 (StructureNotifyMask
| PropertyChangeMask
));
308 if(!getclient(ev
->window
))
309 manage(ev
->window
, &wa
);
313 propertynotify(XEvent
*e
)
317 XPropertyEvent
*ev
= &e
->xproperty
;
319 if(ev
->state
== PropertyDelete
)
322 if((c
= getclient(ev
->window
))) {
323 if(ev
->atom
== wmatom
[WMProtocols
]) {
324 c
->proto
= getproto(c
->win
);
329 case XA_WM_TRANSIENT_FOR
:
330 XGetTransientForHint(dpy
, c
->win
, &trans
);
331 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
334 case XA_WM_NORMAL_HINTS
:
338 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
346 unmapnotify(XEvent
*e
)
349 XUnmapEvent
*ev
= &e
->xunmap
;
351 if((c
= getclient(ev
->window
)))
357 void (*handler
[LASTEvent
]) (XEvent
*) = {
358 [ButtonPress
] = buttonpress
,
359 [ConfigureRequest
] = configurerequest
,
360 [DestroyNotify
] = destroynotify
,
361 [EnterNotify
] = enternotify
,
362 [LeaveNotify
] = leavenotify
,
364 [KeyPress
] = keypress
,
365 [MappingNotify
] = mappingnotify
,
366 [MapRequest
] = maprequest
,
367 [PropertyNotify
] = propertynotify
,
368 [UnmapNotify
] = unmapnotify
374 static unsigned int len
= sizeof(key
) / sizeof(key
[0]);
378 XUngrabKey(dpy
, AnyKey
, AnyModifier
, root
);
379 for(i
= 0; i
< len
; i
++) {
380 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
381 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
382 GrabModeAsync
, GrabModeAsync
);
383 XGrabKey(dpy
, code
, key
[i
].mod
| LockMask
, root
, True
,
384 GrabModeAsync
, GrabModeAsync
);
385 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
, root
, True
,
386 GrabModeAsync
, GrabModeAsync
);
387 XGrabKey(dpy
, code
, key
[i
].mod
| numlockmask
| LockMask
, root
, True
,
388 GrabModeAsync
, GrabModeAsync
);
397 while(XPending(dpy
)) {
398 XNextEvent(dpy
, &ev
);
400 (handler
[ev
.type
])(&ev
); /* call handler */