Xinqi Bao's Git
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
8 #include <X11/keysym.h>
11 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
12 #define MouseMask (ButtonMask | PointerMotionMask)
15 const char *browse
[] = { "firefox", NULL
};
16 const char *gimp
[] = { "gimp", NULL
};
17 const char *term
[] = {
18 "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
19 "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
21 const char *xlock
[] = { "xlock", NULL
};
24 /* modifier key function arguments */
25 { ControlMask
, XK_0
, appendtag
, { .i
= Tscratch
} },
26 { ControlMask
, XK_1
, appendtag
, { .i
= Tdev
} },
27 { ControlMask
, XK_2
, appendtag
, { .i
= Twww
} },
28 { ControlMask
, XK_3
, appendtag
, { .i
= Twork
} },
29 { MODKEY
, XK_0
, view
, { .i
= Tscratch
} },
30 { MODKEY
, XK_1
, view
, { .i
= Tdev
} },
31 { MODKEY
, XK_2
, view
, { .i
= Twww
} },
32 { MODKEY
, XK_3
, view
, { .i
= Twork
} },
33 { MODKEY
, XK_j
, focusnext
, { 0 } },
34 { MODKEY
, XK_k
, focusprev
, { 0 } },
35 { MODKEY
, XK_m
, maximize
, { 0 } },
36 { MODKEY
, XK_space
, dotile
, { 0 } },
37 { MODKEY
, XK_Return
, zoom
, { 0 } },
38 { ControlMask
|ShiftMask
,XK_0
, heretag
, { .i
= Tscratch
} },
39 { ControlMask
|ShiftMask
,XK_1
, heretag
, { .i
= Tdev
} },
40 { ControlMask
|ShiftMask
,XK_2
, heretag
, { .i
= Twww
} },
41 { ControlMask
|ShiftMask
,XK_3
, heretag
, { .i
= Twork
} },
42 { MODKEY
|ShiftMask
, XK_0
, replacetag
, { .i
= Tscratch
} },
43 { MODKEY
|ShiftMask
, XK_1
, replacetag
, { .i
= Tdev
} },
44 { MODKEY
|ShiftMask
, XK_2
, replacetag
, { .i
= Twww
} },
45 { MODKEY
|ShiftMask
, XK_3
, replacetag
, { .i
= Twork
} },
46 { MODKEY
|ShiftMask
, XK_c
, killclient
, { 0 } },
47 { MODKEY
|ShiftMask
, XK_g
, spawn
, { .argv
= gimp
} },
48 { MODKEY
|ShiftMask
, XK_l
, spawn
, { .argv
= xlock
} },
49 { MODKEY
|ShiftMask
, XK_q
, quit
, { 0 } },
50 { MODKEY
|ShiftMask
, XK_space
, dofloat
, { 0 } },
51 { MODKEY
|ShiftMask
, XK_w
, spawn
, { .argv
= browse
} },
52 { MODKEY
|ShiftMask
, XK_Return
, spawn
, { .argv
= term
} },
61 int x1
, y1
, ocx
, ocy
, di
;
67 if(XGrabPointer(dpy
, root
, False
, MouseMask
, GrabModeAsync
, GrabModeAsync
,
68 None
, cursor
[CurMove
], CurrentTime
) != GrabSuccess
)
70 XQueryPointer(dpy
, root
, &dummy
, &dummy
, &x1
, &y1
, &di
, &di
, &dui
);
72 XMaskEvent(dpy
, MouseMask
| ExposureMask
, &ev
);
80 *c
->x
= ocx
+ (ev
.xmotion
.x
- x1
);
81 *c
->y
= ocy
+ (ev
.xmotion
.y
- y1
);
82 resize(c
, False
, TopLeft
);
85 XUngrabPointer(dpy
, CurrentTime
);
92 resizemouse(Client
*c
)
100 if(XGrabPointer(dpy
, root
, False
, MouseMask
, GrabModeAsync
, GrabModeAsync
,
101 None
, cursor
[CurResize
], CurrentTime
) != GrabSuccess
)
103 XWarpPointer(dpy
, None
, c
->win
, 0, 0, 0, 0, *c
->w
, *c
->h
);
105 XMaskEvent(dpy
, MouseMask
| ExposureMask
, &ev
);
109 handler
[Expose
](&ev
);
113 *c
->w
= abs(ocx
- ev
.xmotion
.x
);
114 *c
->h
= abs(ocy
- ev
.xmotion
.y
);
115 *c
->x
= (ocx
<= ev
.xmotion
.x
) ? ocx
: ocx
- *c
->w
;
116 *c
->y
= (ocy
<= ev
.xmotion
.y
) ? ocy
: ocy
- *c
->h
;
117 if(ocx
<= ev
.xmotion
.x
)
118 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopLeft
: BotLeft
;
120 sticky
= (ocy
<= ev
.xmotion
.y
) ? TopRight
: BotRight
;
121 resize(c
, True
, sticky
);
124 XUngrabPointer(dpy
, CurrentTime
);
131 buttonpress(XEvent
*e
)
135 XButtonPressedEvent
*ev
= &e
->xbutton
;
138 if(barwin
== ev
->window
) {
142 for(a
.i
= 0; a
.i
< TLast
; a
.i
++) {
143 x
+= textw(tags
[a
.i
]);
151 a
.i
= (tsel
+ 1 < TLast
) ? tsel
+ 1 : 0;
155 a
.i
= (tsel
- 1 >= 0) ? tsel
- 1 : TLast
- 1;
160 else if((c
= getclient(ev
->window
))) {
165 if(arrange
== dotile
&& !c
->isfloat
) {
166 if((ev
->state
& ControlMask
) && (ev
->button
== Button1
))
178 if(arrange
== dofloat
|| c
->isfloat
) {
188 configurerequest(XEvent
*e
)
190 XConfigureRequestEvent
*ev
= &e
->xconfigurerequest
;
194 ev
->value_mask
&= ~CWSibling
;
195 if((c
= getclient(ev
->window
))) {
197 if(ev
->value_mask
& CWX
)
199 if(ev
->value_mask
& CWY
)
201 if(ev
->value_mask
& CWWidth
)
203 if(ev
->value_mask
& CWHeight
)
205 if(ev
->value_mask
& CWBorderWidth
)
208 resize(c
, True
, TopLeft
);
213 wc
.width
= ev
->width
;
214 wc
.height
= ev
->height
;
217 wc
.stack_mode
= Above
;
218 ev
->value_mask
&= ~CWStackMode
;
219 ev
->value_mask
|= CWBorderWidth
;
220 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
)
237 XCrossingEvent
*ev
= &e
->xcrossing
;
240 if(ev
->mode
!= NotifyNormal
|| ev
->detail
== NotifyInferior
)
243 if((c
= getclient(ev
->window
)))
245 else if(ev
->window
== root
)
252 XExposeEvent
*ev
= &e
->xexpose
;
256 if(barwin
== ev
->window
)
258 else if((c
= getctitle(ev
->window
)))
266 XKeyEvent
*ev
= &e
->xkey
;
267 static unsigned int len
= key
? sizeof(key
) / sizeof(key
[0]) : 0;
271 keysym
= XKeycodeToKeysym(dpy
, (KeyCode
)ev
->keycode
, 0);
272 for(i
= 0; i
< len
; i
++)
273 if((keysym
== key
[i
].keysym
) && (key
[i
].mod
== ev
->state
)) {
275 key
[i
].func(&key
[i
].arg
);
281 leavenotify(XEvent
*e
)
283 XCrossingEvent
*ev
= &e
->xcrossing
;
285 if((ev
->window
== root
) && !ev
->same_screen
)
290 maprequest(XEvent
*e
)
292 XMapRequestEvent
*ev
= &e
->xmaprequest
;
293 static XWindowAttributes wa
;
295 if(!XGetWindowAttributes(dpy
, ev
->window
, &wa
))
298 if(wa
.override_redirect
) {
299 XSelectInput(dpy
, ev
->window
,
300 (StructureNotifyMask
| PropertyChangeMask
));
304 if(!getclient(ev
->window
))
305 manage(ev
->window
, &wa
);
309 propertynotify(XEvent
*e
)
311 XPropertyEvent
*ev
= &e
->xproperty
;
315 if(ev
->state
== PropertyDelete
)
318 if((c
= getclient(ev
->window
))) {
319 if(ev
->atom
== wmatom
[WMProtocols
]) {
320 c
->proto
= getproto(c
->win
);
325 case XA_WM_TRANSIENT_FOR
:
326 XGetTransientForHint(dpy
, c
->win
, &trans
);
327 if(!c
->isfloat
&& (c
->isfloat
= (trans
!= 0)))
330 case XA_WM_NORMAL_HINTS
:
334 if(ev
->atom
== XA_WM_NAME
|| ev
->atom
== netatom
[NetWMName
]) {
342 unmapnotify(XEvent
*e
)
345 XUnmapEvent
*ev
= &e
->xunmap
;
347 if((c
= getclient(ev
->window
)))
353 void (*handler
[LASTEvent
]) (XEvent
*) = {
354 [ButtonPress
] = buttonpress
,
355 [ConfigureRequest
] = configurerequest
,
356 [DestroyNotify
] = destroynotify
,
357 [EnterNotify
] = enternotify
,
358 [LeaveNotify
] = leavenotify
,
360 [KeyPress
] = keypress
,
361 [MapRequest
] = maprequest
,
362 [PropertyNotify
] = propertynotify
,
363 [UnmapNotify
] = unmapnotify
369 static unsigned int len
= key
? sizeof(key
) / sizeof(key
[0]) : 0;
373 for(i
= 0; i
< len
; i
++) {
374 code
= XKeysymToKeycode(dpy
, key
[i
].keysym
);
375 XUngrabKey(dpy
, code
, key
[i
].mod
, root
);
376 XGrabKey(dpy
, code
, key
[i
].mod
, root
, True
,
377 GrabModeAsync
, GrabModeAsync
);