Compare commits
233 Commits
Author | SHA1 | Date | |
---|---|---|---|
57c49fe867 | |||
c60de1acd4 | |||
69b738c097 | |||
da0b2a2f31 | |||
2378a558a2 | |||
f18ed615ae | |||
f6656fffb4 | |||
aaad7bfd15 | |||
0915da8842 | |||
0d0e8bde13 | |||
838a1ff950 | |||
e1315fd40c | |||
52a3ab1042 | |||
a82e7b765e | |||
0ed0fa4d5b | |||
ec85fddb9a | |||
3a1343a245 | |||
9066ee2eb4 | |||
40bd21ce63 | |||
4633fbec61 | |||
25060031a5 | |||
c7ae6334b7 | |||
eac04882b4 | |||
6499fc4f93 | |||
04f27a5438 | |||
1b3903d6e9 | |||
cc05093b0d | |||
6436dd4438 | |||
26c50c780e | |||
01d13b0c49 | |||
f15f45a9f8 | |||
1b2e149cb4 | |||
6136640ec9 | |||
95d8423823 | |||
de6411c338 | |||
e316cf53f6 | |||
c107db57db | |||
d39d00057c | |||
26157e6973 | |||
6d22782e8f | |||
1836b6740d | |||
924a088812 | |||
bab575c868 | |||
daae3bba50 | |||
05fbbbd8dc | |||
4c368bcd24 | |||
9927b9e642 | |||
1b492dffc8 | |||
140be1b4b3 | |||
79259acc12 | |||
5a3bea2d69 | |||
30d928591d | |||
70a3e62257 | |||
6828fba7a0 | |||
aa1bda8164 | |||
157ea539a2 | |||
c3c94c0e0a | |||
9d73909075 | |||
016c54196e | |||
5056bb952d | |||
8a6679b3b4 | |||
7b6d5ff298 | |||
846850914d | |||
4e6c513ac2 | |||
db9cda6a7d | |||
a50b15a9e9 | |||
0a25fe9188 | |||
2dd5212a79 | |||
00e95e1f38 | |||
0a0759132c | |||
5cf362c7d0 | |||
413be1112a | |||
8233dc8568 | |||
afa8b3bcd9 | |||
c518345f40 | |||
afe6ac9923 | |||
e995c1b532 | |||
e36929292e | |||
03128f78df | |||
7d4a5e654c | |||
41ba7a7984 | |||
aa471f2d65 | |||
d37dfa1bed | |||
9f35cc52fe | |||
f1fe19bc2b | |||
b55bd709ee | |||
9833610356 | |||
de7fc0011e | |||
2e0c767d74 | |||
a5379e901c | |||
a039d51d5f | |||
60b3dceccf | |||
c2ac851b90 | |||
c976bc6c2c | |||
2e834e941f | |||
77e5f3167c | |||
7e597ae204 | |||
c39df91ab9 | |||
af1158d105 | |||
b739721d9e | |||
7711ab6707 | |||
d370c32f69 | |||
d6a6eca71d | |||
39ffc18635 | |||
3e972ec84d | |||
b5159dfd2f | |||
07c2659806 | |||
dc83b9e988 | |||
8b4bc8270a | |||
0ff80653d3 | |||
352e1b4c81 | |||
aa13727067 | |||
595028614b | |||
6a3ae5e26a | |||
8c334ee078 | |||
f60fe2a4f9 | |||
b112257bf2 | |||
eb88adcd8a | |||
950a1ab5af | |||
1b9fe55025 | |||
2272df9d31 | |||
08d85d6d66 | |||
b43989207a | |||
2eebebf262 | |||
8c1fffe106 | |||
5e9acbc952 | |||
a420ceab50 | |||
0e1c649dca | |||
67c2124fa9 | |||
a635743c6d | |||
b5c2412d84 | |||
ad2e77d635 | |||
a20b10d01f | |||
4cc0551948 | |||
56130c3689 | |||
14f7380308 | |||
727449d1e7 | |||
80bf2aa559 | |||
b9cd0c4331 | |||
f77a87137c | |||
65dfe8fdce | |||
e3bb595d77 | |||
a1682b8927 | |||
24d91e3b8a | |||
ce04a66528 | |||
df74b26e5d | |||
b6ad663f87 | |||
ee31e38dc7 | |||
442334641e | |||
dfa5ea6360 | |||
3e06edeb5d | |||
78b050c13c | |||
4ad20ffc2c | |||
57e6e3bb80 | |||
19da197f58 | |||
666fae97e6 | |||
823fb1118a | |||
db1d62e184 | |||
d26ffc7fa3 | |||
0f3acce042 | |||
9eef9f7b02 | |||
aff4c787f4 | |||
fe3dfbbe90 | |||
2ffdc1936c | |||
0fe52c63ea | |||
28a52197c4 | |||
2c0d1cc87b | |||
375a251d16 | |||
d4b7a9a373 | |||
4d67199a4b | |||
95766d6241 | |||
4cb78a170c | |||
2c66b422e7 | |||
e571de83e9 | |||
4bb89e2cb1 | |||
349cadacf6 | |||
292ccc4c43 | |||
d7413ffd2d | |||
50729a2e73 | |||
a3e3f0b9ed | |||
45aea23355 | |||
975b459c17 | |||
2b35faee06 | |||
84818bdbb5 | |||
895902b57a | |||
7d4184dc5c | |||
8278f0a6be | |||
d3969634ac | |||
735ca9ccd6 | |||
4ee661d908 | |||
9fce8215b7 | |||
6521c2dd41 | |||
9ee9ce7e14 | |||
9d39da6452 | |||
0228dcd58f | |||
3d35ea99bb | |||
0680c76a6f | |||
c3e5f5cc9a | |||
1c620d27d8 | |||
fde45ebed8 | |||
4bd0d33f57 | |||
00255728aa | |||
4b0328f209 | |||
30561a0161 | |||
a4c4998c8b | |||
8e053b6476 | |||
b79b5facb1 | |||
c53f0fca91 | |||
c225e1afc2 | |||
92e55c7c53 | |||
c86f131681 | |||
e943234d09 | |||
9fc24e371b | |||
cac467d52c | |||
04f17d2669 | |||
dff15a02f7 | |||
42277b1110 | |||
095f9e143e | |||
9fbb2ebb90 | |||
dbcf87ce76 | |||
4250c26e9b | |||
e48de30516 | |||
1f0060caa3 | |||
c732cc90ab | |||
4e2c5b5f25 | |||
d9386a0c07 | |||
66e16c92d3 | |||
6a8e176df1 | |||
632c7f3410 | |||
045f1840e0 | |||
45d16d090b | |||
525c5ff4d8 | |||
5952157c3b |
7
.hgtags
7
.hgtags
@ -4,3 +4,10 @@ d31b5ad96b0ba7b5b0a30928fcf000428339a577 0.1
|
||||
eb3165734f00fe7f7da8aeebaed00e60a57caac9 0.4
|
||||
22213b9a2114167ee8ba019a012e27da0422a61a 0.5
|
||||
c11f86db4550cac5d0a648a3fe4d6d3b9a4fcf7e 0.6
|
||||
3fb41412e2492f66476d92ce8f007a8b48fb1d2a 0.7
|
||||
cd15de32e173f8ce97bfe1c9b6607937b59056b4 0.8
|
||||
fae61afa861755636c4a1070694209ace8efbb6c 0.9
|
||||
bbc98e77ae89a7c9232a5be0835f60ea00d8036e 1.0
|
||||
44a55e6e46bf6c231780b09d919977d6f01083de 1.1
|
||||
e3179ce2b90451d2807cd53b589d768412b8666b 1.2
|
||||
f5f5cbf016a94b48a8fe9c47f0736e96d166d5d4 1.3
|
||||
|
1
LICENSE
1
LICENSE
@ -1,6 +1,7 @@
|
||||
MIT/X Consortium License
|
||||
|
||||
(C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||
(C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
10
Makefile
10
Makefile
@ -3,23 +3,23 @@
|
||||
|
||||
include config.mk
|
||||
|
||||
SRC = client.c draw.c event.c main.c tag.c util.c
|
||||
SRC = client.c draw.c event.c main.c tag.c util.c view.c
|
||||
OBJ = ${SRC:.c=.o}
|
||||
|
||||
all: options dwm
|
||||
@echo finished
|
||||
|
||||
options:
|
||||
@echo dwm build options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
@echo "LD = ${LD}"
|
||||
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@${CC} -c ${CFLAGS} $<
|
||||
|
||||
${OBJ}: dwm.h config.h
|
||||
${OBJ}: dwm.h config.h config.mk
|
||||
|
||||
config.h:
|
||||
@echo creating $@ from config.default.h
|
||||
@ -27,7 +27,7 @@ config.h:
|
||||
|
||||
dwm: ${OBJ}
|
||||
@echo LD $@
|
||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
@${LD} -o $@ ${OBJ} ${LDFLAGS}
|
||||
@strip $@
|
||||
|
||||
clean:
|
||||
@ -50,7 +50,7 @@ install: all
|
||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/dwm
|
||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
@cp -f dwm.1 ${DESTDIR}${MANPREFIX}/man1
|
||||
@sed 's/VERSION/${VERSION}/g' < dwm.1 > ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dwm.1
|
||||
|
||||
uninstall:
|
||||
|
2
README
2
README
@ -1,6 +1,6 @@
|
||||
dwm - dynamic window manager
|
||||
----------------------------
|
||||
dwm is an extremely fast, small, and dynamic X11 window manager.
|
||||
dwm is an extremely fast, small, and dynamic window manager for X.
|
||||
|
||||
|
||||
Requirements
|
||||
|
268
client.c
268
client.c
@ -10,24 +10,57 @@
|
||||
|
||||
/* static functions */
|
||||
|
||||
static void
|
||||
grabbuttons(Client *c, Bool focus)
|
||||
{
|
||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||
|
||||
if(focus) {
|
||||
XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
}
|
||||
else
|
||||
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
resizetitle(Client *c)
|
||||
{
|
||||
int i;
|
||||
|
||||
c->tw = 0;
|
||||
for(i = 0; i < ntags; i++)
|
||||
if(c->tags[i])
|
||||
c->tw += textw(tags[i]);
|
||||
c->tw += textw(c->name);
|
||||
c->tw = textw(c->name);
|
||||
if(c->tw > c->w)
|
||||
c->tw = c->w + 2;
|
||||
c->tx = c->x + c->w - c->tw + 2;
|
||||
c->ty = c->y;
|
||||
if(c->tags[tsel])
|
||||
XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
|
||||
if(isvisible(c))
|
||||
XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th);
|
||||
else
|
||||
XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
|
||||
XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th);
|
||||
|
||||
}
|
||||
|
||||
@ -43,62 +76,35 @@ void
|
||||
ban(Client *c)
|
||||
{
|
||||
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
|
||||
XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
|
||||
XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty);
|
||||
}
|
||||
|
||||
void
|
||||
focus(Client *c)
|
||||
{
|
||||
Client *old = sel;
|
||||
XEvent ev;
|
||||
Client *old;
|
||||
|
||||
sel = c;
|
||||
if(old && old != c)
|
||||
drawtitle(old);
|
||||
drawtitle(c);
|
||||
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||||
XSync(dpy, False);
|
||||
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||||
}
|
||||
|
||||
void
|
||||
focusnext(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!sel)
|
||||
if(!issel)
|
||||
return;
|
||||
|
||||
if(sel->ismax)
|
||||
togglemax(NULL);
|
||||
|
||||
if(!(c = getnext(sel->next)))
|
||||
c = getnext(clients);
|
||||
if(c) {
|
||||
higher(c);
|
||||
focus(c);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
focusprev(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
if(sel->ismax)
|
||||
togglemax(NULL);
|
||||
|
||||
if(!(c = getprev(sel->prev))) {
|
||||
for(c = clients; c && c->next; c = c->next);
|
||||
c = getprev(c);
|
||||
sel = c;
|
||||
else if(sel != c) {
|
||||
if(maximized)
|
||||
togglemax(NULL);
|
||||
old = sel;
|
||||
sel = c;
|
||||
if(old) {
|
||||
grabbuttons(old, False);
|
||||
drawtitle(old);
|
||||
}
|
||||
}
|
||||
if(c) {
|
||||
higher(c);
|
||||
focus(c);
|
||||
grabbuttons(c, True);
|
||||
drawtitle(c);
|
||||
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
|
||||
}
|
||||
else
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
}
|
||||
|
||||
Client *
|
||||
@ -118,7 +124,7 @@ getctitle(Window w)
|
||||
Client *c;
|
||||
|
||||
for(c = clients; c; c = c->next)
|
||||
if(c->title == w)
|
||||
if(c->twin == w)
|
||||
return c;
|
||||
return NULL;
|
||||
}
|
||||
@ -178,13 +184,6 @@ gravitate(Client *c, Bool invert)
|
||||
c->y += dy;
|
||||
}
|
||||
|
||||
void
|
||||
higher(Client *c)
|
||||
{
|
||||
XRaiseWindow(dpy, c->win);
|
||||
XRaiseWindow(dpy, c->title);
|
||||
}
|
||||
|
||||
void
|
||||
killclient(Arg *arg)
|
||||
{
|
||||
@ -196,16 +195,10 @@ killclient(Arg *arg)
|
||||
XKillClient(dpy, sel->win);
|
||||
}
|
||||
|
||||
void
|
||||
lower(Client *c)
|
||||
{
|
||||
XLowerWindow(dpy, c->title);
|
||||
XLowerWindow(dpy, c->win);
|
||||
}
|
||||
|
||||
void
|
||||
manage(Window w, XWindowAttributes *wa)
|
||||
{
|
||||
unsigned int i;
|
||||
Client *c;
|
||||
Window trans;
|
||||
XSetWindowAttributes twa;
|
||||
@ -222,8 +215,14 @@ manage(Window w, XWindowAttributes *wa)
|
||||
c->border = 0;
|
||||
setsize(c);
|
||||
|
||||
if(c->x + c->w + 2 > sw)
|
||||
c->x = sw - c->w - 2;
|
||||
if(c->x < 0)
|
||||
c->x = 0;
|
||||
if(c->y + c->h + 2 > sh)
|
||||
c->y = sh - c->h - 2;
|
||||
if(c->h != sh && c->y < bh)
|
||||
c->y = c->ty = bh;
|
||||
c->y = bh;
|
||||
|
||||
c->proto = getproto(c->win);
|
||||
XSelectInput(dpy, c->win,
|
||||
@ -233,56 +232,30 @@ manage(Window w, XWindowAttributes *wa)
|
||||
twa.background_pixmap = ParentRelative;
|
||||
twa.event_mask = ExposureMask | EnterWindowMask;
|
||||
|
||||
c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
|
||||
c->twin = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
|
||||
0, DefaultDepth(dpy, screen), CopyFromParent,
|
||||
DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
|
||||
|
||||
grabbuttons(c, False);
|
||||
settags(c, getclient(trans));
|
||||
if(!c->isfloat)
|
||||
c->isfloat = trans
|
||||
|| (c->maxw && c->minw &&
|
||||
c->maxw == c->minw && c->maxh == c->minh);
|
||||
|
||||
if(clients)
|
||||
clients->prev = c;
|
||||
c->next = clients;
|
||||
clients = c;
|
||||
|
||||
XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button1, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button2, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
XGrabButton(dpy, Button3, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
|
||||
GrabModeAsync, GrabModeSync, None, None);
|
||||
|
||||
settags(c);
|
||||
if(!c->isfloat)
|
||||
c->isfloat = trans
|
||||
|| (c->maxw && c->minw &&
|
||||
c->maxw == c->minw && c->maxh == c->minh);
|
||||
settitle(c);
|
||||
arrange(NULL);
|
||||
|
||||
/* mapping the window now prevents flicker */
|
||||
XMapRaised(dpy, c->win);
|
||||
XMapRaised(dpy, c->title);
|
||||
if(c->tags[tsel])
|
||||
ban(c);
|
||||
XMapWindow(dpy, c->win);
|
||||
XMapWindow(dpy, c->twin);
|
||||
if(isvisible(c))
|
||||
focus(c);
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@ -290,7 +263,6 @@ resize(Client *c, Bool sizehints, Corner sticky)
|
||||
{
|
||||
int bottom = c->y + c->h;
|
||||
int right = c->x + c->w;
|
||||
/*XConfigureEvent e;*/
|
||||
XWindowChanges wc;
|
||||
|
||||
if(sizehints) {
|
||||
@ -307,10 +279,6 @@ resize(Client *c, Bool sizehints, Corner sticky)
|
||||
if(c->maxh && c->h > c->maxh)
|
||||
c->h = c->maxh;
|
||||
}
|
||||
if(c->x > right) /* might happen on restart */
|
||||
c->x = right - c->w;
|
||||
if(c->y > bottom)
|
||||
c->y = bottom - c->h;
|
||||
if(sticky == TopRight || sticky == BotRight)
|
||||
c->x = right - c->w;
|
||||
if(sticky == BotLeft || sticky == BotRight)
|
||||
@ -400,12 +368,13 @@ void
|
||||
togglemax(Arg *arg)
|
||||
{
|
||||
int ox, oy, ow, oh;
|
||||
Client *c;
|
||||
XEvent ev;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
if((sel->ismax = !sel->ismax)) {
|
||||
if((maximized = !maximized)) {
|
||||
ox = sel->x;
|
||||
oy = sel->y;
|
||||
ow = sel->w;
|
||||
@ -415,8 +384,11 @@ togglemax(Arg *arg)
|
||||
sel->w = sw - 2;
|
||||
sel->h = sh - 2 - bh;
|
||||
|
||||
higher(sel);
|
||||
resize(sel, False, TopLeft);
|
||||
restack();
|
||||
for(c = getnext(clients); c; c = getnext(c->next))
|
||||
if(c != sel)
|
||||
ban(c);
|
||||
resize(sel, arrange == dofloat, TopLeft);
|
||||
|
||||
sel->x = ox;
|
||||
sel->y = oy;
|
||||
@ -424,32 +396,31 @@ togglemax(Arg *arg)
|
||||
sel->h = oh;
|
||||
}
|
||||
else
|
||||
resize(sel, False, TopLeft);
|
||||
arrange(NULL);
|
||||
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||||
}
|
||||
|
||||
void
|
||||
unmanage(Client *c)
|
||||
{
|
||||
Client *tc, *fc;
|
||||
Window trans;
|
||||
XGrabServer(dpy);
|
||||
XSetErrorHandler(xerrordummy);
|
||||
|
||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||
XDestroyWindow(dpy, c->title);
|
||||
|
||||
if(c->prev)
|
||||
c->prev->next = c->next;
|
||||
if(c->next)
|
||||
c->next->prev = c->prev;
|
||||
if(c == clients)
|
||||
clients = c->next;
|
||||
detach(c);
|
||||
if(sel == c) {
|
||||
sel = getnext(c->next);
|
||||
if(!sel)
|
||||
sel = getprev(c->prev);
|
||||
if(!sel)
|
||||
sel = clients;
|
||||
XGetTransientForHint(dpy, c->win, &trans);
|
||||
if(trans && (tc = getclient(trans)) && isvisible(tc))
|
||||
fc = tc;
|
||||
else
|
||||
fc = getnext(clients);
|
||||
focus(fc);
|
||||
}
|
||||
|
||||
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
|
||||
XDestroyWindow(dpy, c->twin);
|
||||
|
||||
free(c->tags);
|
||||
free(c);
|
||||
|
||||
@ -457,35 +428,4 @@ unmanage(Client *c)
|
||||
XSetErrorHandler(xerror);
|
||||
XUngrabServer(dpy);
|
||||
arrange(NULL);
|
||||
if(sel)
|
||||
focus(sel);
|
||||
}
|
||||
|
||||
void
|
||||
zoom(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!sel || (arrange != dotile) || sel->isfloat)
|
||||
return;
|
||||
|
||||
if(sel == getnext(clients)) {
|
||||
if((c = getnext(sel->next)))
|
||||
sel = c;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
/* pop */
|
||||
if(sel->prev)
|
||||
sel->prev->next = sel->next;
|
||||
if(sel->next)
|
||||
sel->next->prev = sel->prev;
|
||||
sel->prev = NULL;
|
||||
if(clients)
|
||||
clients->prev = sel;
|
||||
sel->next = clients;
|
||||
clients = sel;
|
||||
arrange(NULL);
|
||||
focus(sel);
|
||||
}
|
||||
|
85
config.arg.h
85
config.arg.h
@ -4,56 +4,63 @@
|
||||
*/
|
||||
|
||||
#define TAGS \
|
||||
const char *tags[] = { "fnord", "dev", "net", "work", "misc", NULL };
|
||||
const char *tags[] = { "dev", "work", "net", "fnord", NULL };
|
||||
|
||||
#define DEFMODE dotile /* dofloat */
|
||||
#define DEFTAG 1 /* index */
|
||||
#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
|
||||
#define BGCOLOR "#0a2c2d"
|
||||
#define FGCOLOR "#ddeeee"
|
||||
#define BORDERCOLOR "#176164"
|
||||
#define FLOATSYMBOL "><>"
|
||||
#define TILESYMBOL "[]="
|
||||
|
||||
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
|
||||
#define SELBGCOLOR "#333366"
|
||||
#define SELFGCOLOR "#eeeeee"
|
||||
#define NORMBGCOLOR "#333333"
|
||||
#define NORMFGCOLOR "#dddddd"
|
||||
#define STATUSBGCOLOR "#222222"
|
||||
#define STATUSFGCOLOR "#9999cc"
|
||||
|
||||
#define MODKEY Mod1Mask
|
||||
#define NUMLOCKMASK Mod2Mask
|
||||
#define MASTERW 60 /* percent */
|
||||
|
||||
#define KEYS \
|
||||
static Key key[] = { \
|
||||
/* modifier key function arguments */ \
|
||||
{ MODKEY, XK_0, view, { .i = 0 } }, \
|
||||
{ MODKEY, XK_1, view, { .i = 1 } }, \
|
||||
{ MODKEY, XK_2, view, { .i = 2 } }, \
|
||||
{ MODKEY, XK_3, view, { .i = 3 } }, \
|
||||
{ MODKEY, XK_4, view, { .i = 4 } }, \
|
||||
{ MODKEY, XK_h, viewprev, { 0 } }, \
|
||||
{ MODKEY, XK_j, focusnext, { 0 } }, \
|
||||
{ MODKEY, XK_k, focusprev, { 0 } }, \
|
||||
{ MODKEY, XK_l, viewnext, { 0 } }, \
|
||||
{ MODKEY, XK_m, togglemax, { 0 } }, \
|
||||
{ MODKEY, XK_p, spawn, \
|
||||
{ .cmd = "exec `ls -lL /usr/bin /usr/local/bin 2>/dev/null |" \
|
||||
" awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | dmenu`" } }, \
|
||||
{ MODKEY, XK_space, togglemode, { 0 } }, \
|
||||
{ MODKEY, XK_Return, zoom, { 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_0, appendtag, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_1, appendtag, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask, XK_2, appendtag, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask, XK_3, appendtag, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask, XK_4, appendtag, { .i = 4 } }, \
|
||||
{ MODKEY|ShiftMask, XK_0, replacetag, { .i = 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_1, replacetag, { .i = 1 } }, \
|
||||
{ MODKEY|ShiftMask, XK_2, replacetag, { .i = 2 } }, \
|
||||
{ MODKEY|ShiftMask, XK_3, replacetag, { .i = 3 } }, \
|
||||
{ MODKEY|ShiftMask, XK_4, replacetag, { .i = 5 } }, \
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, \
|
||||
{ .cmd = "exec urxvt -tr +sb -bg black -fg white -cr white " \
|
||||
"-fn '-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*'" } }, \
|
||||
/* modifier key function arguments */ \
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, \
|
||||
{ .cmd = "exec uxterm -bg '#111111' -fg '#eeeeee' -cr '#eeeeee' +sb -fn '"FONT"'" } }, \
|
||||
{ MODKEY, XK_p, spawn, \
|
||||
{ .cmd = "exe=\"$(IFS=:; for dir in $PATH; do " \
|
||||
"for file in \"$dir\"/*; do [ -x \"$file\" ] && echo \"${file##*/}\"; done; " \
|
||||
"done | sort -u | dmenu)\" && exec \"$exe\"" } }, \
|
||||
{ MODKEY, XK_j, focusnext, { 0 } }, \
|
||||
{ MODKEY, XK_k, focusprev, { 0 } }, \
|
||||
{ MODKEY, XK_Return, zoom, { 0 } }, \
|
||||
{ MODKEY, XK_m, togglemax, { 0 } }, \
|
||||
{ MODKEY, XK_g, resizecol, { .i = 20 } }, \
|
||||
{ MODKEY, XK_s, resizecol, { .i = -20 } }, \
|
||||
{ MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \
|
||||
{ MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \
|
||||
{ MODKEY|ShiftMask, XK_4, tag, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_1, toggletag, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_2, toggletag, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_3, toggletag, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_4, toggletag, { .i = 3 } }, \
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
|
||||
{ MODKEY, XK_space, togglemode, { 0 } }, \
|
||||
{ MODKEY, XK_0, viewall, { 0 } }, \
|
||||
{ MODKEY, XK_1, view, { .i = 0 } }, \
|
||||
{ MODKEY, XK_2, view, { .i = 1 } }, \
|
||||
{ MODKEY, XK_3, view, { .i = 2 } }, \
|
||||
{ MODKEY, XK_4, view, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask, XK_1, toggleview, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_2, toggleview, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask, XK_3, toggleview, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask, XK_4, toggleview, { .i = 3 } }, \
|
||||
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
|
||||
};
|
||||
|
||||
#define RULES \
|
||||
static Rule rule[] = { \
|
||||
/* class:instance regex tags regex isfloat */ \
|
||||
/* class:instance:title regex tags regex isfloat */ \
|
||||
{ "Firefox.*", "net", False }, \
|
||||
{ "Gimp.*", NULL, True}, \
|
||||
{ "MPlayer.*", NULL, True}, \
|
||||
|
@ -4,51 +4,64 @@
|
||||
*/
|
||||
|
||||
#define TAGS \
|
||||
const char *tags[] = { "0", "1", "2", "3", "4", NULL };
|
||||
const char *tags[] = { "1", "2", "3", "4", "5", NULL };
|
||||
|
||||
#define DEFMODE dotile /* dofloat */
|
||||
#define DEFTAG 1 /* index */
|
||||
#define FLOATSYMBOL "><>"
|
||||
#define TILESYMBOL "[]="
|
||||
|
||||
#define FONT "fixed"
|
||||
#define BGCOLOR "#666699"
|
||||
#define FGCOLOR "#eeeeee"
|
||||
#define BORDERCOLOR "#9999CC"
|
||||
#define SELBGCOLOR "#666699"
|
||||
#define SELFGCOLOR "#eeeeee"
|
||||
#define NORMBGCOLOR "#333366"
|
||||
#define NORMFGCOLOR "#cccccc"
|
||||
#define STATUSBGCOLOR "#dddddd"
|
||||
#define STATUSFGCOLOR "#222222"
|
||||
|
||||
#define MODKEY Mod1Mask
|
||||
#define NUMLOCKMASK Mod2Mask
|
||||
#define MASTERW 60 /* percent */
|
||||
|
||||
#define KEYS \
|
||||
static Key key[] = { \
|
||||
/* modifier key function arguments */ \
|
||||
{ MODKEY, XK_0, view, { .i = 0 } }, \
|
||||
{ MODKEY, XK_1, view, { .i = 1 } }, \
|
||||
{ MODKEY, XK_2, view, { .i = 2 } }, \
|
||||
{ MODKEY, XK_3, view, { .i = 3 } }, \
|
||||
{ MODKEY, XK_4, view, { .i = 4 } }, \
|
||||
{ MODKEY, XK_h, viewprev, { 0 } }, \
|
||||
{ MODKEY, XK_j, focusnext, { 0 } }, \
|
||||
{ MODKEY, XK_k, focusprev, { 0 } }, \
|
||||
{ MODKEY, XK_l, viewnext, { 0 } }, \
|
||||
{ MODKEY, XK_m, togglemax, { 0 } }, \
|
||||
{ MODKEY, XK_space, togglemode, { 0 } }, \
|
||||
{ MODKEY, XK_Return, zoom, { 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_0, appendtag, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_1, appendtag, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask, XK_2, appendtag, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask, XK_3, appendtag, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask, XK_4, appendtag, { .i = 4 } }, \
|
||||
{ MODKEY|ShiftMask, XK_0, replacetag, { .i = 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_1, replacetag, { .i = 1 } }, \
|
||||
{ MODKEY|ShiftMask, XK_2, replacetag, { .i = 2 } }, \
|
||||
{ MODKEY|ShiftMask, XK_3, replacetag, { .i = 3 } }, \
|
||||
{ MODKEY|ShiftMask, XK_4, replacetag, { .i = 4 } }, \
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, { .cmd = "exec xterm" } }, \
|
||||
/* modifier key function arguments */ \
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, { .cmd = "exec xterm" } }, \
|
||||
{ MODKEY, XK_Tab, focusnext, { 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_Tab, focusprev, { 0 } }, \
|
||||
{ MODKEY, XK_Return, zoom, { 0 } }, \
|
||||
{ MODKEY, XK_m, togglemax, { 0 } }, \
|
||||
{ MODKEY, XK_g, resizecol, { .i = 20 } }, \
|
||||
{ MODKEY, XK_s, resizecol, { .i = -20 } }, \
|
||||
{ MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \
|
||||
{ MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \
|
||||
{ MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \
|
||||
{ MODKEY|ShiftMask, XK_4, tag, { .i = 3 } }, \
|
||||
{ MODKEY|ShiftMask, XK_5, tag, { .i = 4 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_1, toggletag, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_2, toggletag, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_3, toggletag, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_4, toggletag, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask|ShiftMask, XK_5, toggletag, { .i = 4 } }, \
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
|
||||
{ MODKEY, XK_space, togglemode, { 0 } }, \
|
||||
{ MODKEY, XK_0, viewall, { 0 } }, \
|
||||
{ MODKEY, XK_1, view, { .i = 0 } }, \
|
||||
{ MODKEY, XK_2, view, { .i = 1 } }, \
|
||||
{ MODKEY, XK_3, view, { .i = 2 } }, \
|
||||
{ MODKEY, XK_4, view, { .i = 3 } }, \
|
||||
{ MODKEY, XK_5, view, { .i = 4 } }, \
|
||||
{ MODKEY|ControlMask, XK_1, toggleview, { .i = 0 } }, \
|
||||
{ MODKEY|ControlMask, XK_2, toggleview, { .i = 1 } }, \
|
||||
{ MODKEY|ControlMask, XK_3, toggleview, { .i = 2 } }, \
|
||||
{ MODKEY|ControlMask, XK_4, toggleview, { .i = 3 } }, \
|
||||
{ MODKEY|ControlMask, XK_5, toggleview, { .i = 4 } }, \
|
||||
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
|
||||
};
|
||||
|
||||
/* Query class:instance:title for regex matching info with following command:
|
||||
* xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/ { printf("%s\n",$2) }' */
|
||||
#define RULES \
|
||||
static Rule rule[] = { \
|
||||
/* class:instance regex tags regex isfloat */ \
|
||||
/* class:instance:title regex tags regex isfloat */ \
|
||||
{ "Firefox.*", "2", False }, \
|
||||
{ "Gimp.*", NULL, True}, \
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
# dwm version
|
||||
VERSION = 0.7
|
||||
VERSION = 1.4
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -11,7 +11,7 @@ X11INC = /usr/X11R6/include
|
||||
X11LIB = /usr/X11R6/lib
|
||||
|
||||
# includes and libs
|
||||
INCS = -I/usr/lib -I${X11INC}
|
||||
INCS = -I. -I/usr/include -I${X11INC}
|
||||
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
|
||||
|
||||
# flags
|
||||
@ -20,5 +20,6 @@ LDFLAGS = ${LIBS}
|
||||
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
||||
#LDFLAGS = -g ${LIBS}
|
||||
|
||||
# compiler
|
||||
# compiler and linker
|
||||
CC = cc
|
||||
LD = ${CC}
|
||||
|
120
draw.c
120
draw.c
@ -9,26 +9,6 @@
|
||||
|
||||
/* static */
|
||||
|
||||
static void
|
||||
drawborder(void)
|
||||
{
|
||||
XPoint points[5];
|
||||
|
||||
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
XSetForeground(dpy, dc.gc, dc.border);
|
||||
points[0].x = dc.x;
|
||||
points[0].y = dc.y;
|
||||
points[1].x = dc.w - 1;
|
||||
points[1].y = 0;
|
||||
points[2].x = 0;
|
||||
points[2].y = dc.h - 1;
|
||||
points[3].x = -(dc.w - 1);
|
||||
points[3].y = 0;
|
||||
points[4].x = 0;
|
||||
points[4].y = -(dc.h - 1);
|
||||
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
textnw(const char *text, unsigned int len)
|
||||
{
|
||||
@ -42,25 +22,22 @@ textnw(const char *text, unsigned int len)
|
||||
}
|
||||
|
||||
static void
|
||||
drawtext(const char *text, Bool invert, Bool border)
|
||||
drawtext(const char *text, unsigned long col[ColLast], Bool highlight)
|
||||
{
|
||||
int x, y, w, h;
|
||||
static char buf[256];
|
||||
unsigned int len;
|
||||
unsigned int len, olen;
|
||||
XGCValues gcv;
|
||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
||||
|
||||
XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
|
||||
XSetForeground(dpy, dc.gc, col[ColBG]);
|
||||
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
|
||||
|
||||
w = 0;
|
||||
if(border)
|
||||
drawborder();
|
||||
|
||||
if(!text)
|
||||
return;
|
||||
|
||||
len = strlen(text);
|
||||
w = 0;
|
||||
olen = len = strlen(text);
|
||||
if(len >= sizeof(buf))
|
||||
len = sizeof(buf) - 1;
|
||||
memcpy(buf, text, len);
|
||||
@ -73,21 +50,32 @@ drawtext(const char *text, Bool invert, Bool border)
|
||||
/* shorten text if necessary */
|
||||
while(len && (w = textnw(buf, len)) > dc.w - h)
|
||||
buf[--len] = 0;
|
||||
if(len < olen) {
|
||||
if(len > 1)
|
||||
buf[len - 1] = '.';
|
||||
if(len > 2)
|
||||
buf[len - 2] = '.';
|
||||
if(len > 3)
|
||||
buf[len - 3] = '.';
|
||||
}
|
||||
|
||||
if(w > dc.w)
|
||||
return; /* too long */
|
||||
|
||||
gcv.foreground = invert ? dc.bg : dc.fg;
|
||||
gcv.background = invert ? dc.fg : dc.bg;
|
||||
gcv.foreground = col[ColFG];
|
||||
if(dc.font.set) {
|
||||
XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
|
||||
XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
|
||||
x, y, buf, len);
|
||||
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
|
||||
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
|
||||
}
|
||||
else {
|
||||
gcv.font = dc.font.xfont->fid;
|
||||
XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
|
||||
XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||
XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
|
||||
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||
}
|
||||
if(highlight) {
|
||||
r.x = dc.x + 2;
|
||||
r.y = dc.y + 2;
|
||||
r.width = r.height = 3;
|
||||
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,28 +95,36 @@ void
|
||||
drawstatus()
|
||||
{
|
||||
int i, x;
|
||||
Bool istile = arrange == dotile;
|
||||
|
||||
dc.x = dc.y = 0;
|
||||
dc.w = bw;
|
||||
drawtext(NULL, !istile, False);
|
||||
|
||||
dc.w = 0;
|
||||
for(i = 0; i < ntags; i++) {
|
||||
dc.x += dc.w;
|
||||
dc.w = textw(tags[i]);
|
||||
if(istile)
|
||||
drawtext(tags[i], (i == tsel), True);
|
||||
if(seltag[i])
|
||||
drawtext(tags[i], dc.sel, sel && sel->tags[i]);
|
||||
else
|
||||
drawtext(tags[i], (i != tsel), True);
|
||||
drawtext(tags[i], dc.norm, sel && sel->tags[i]);
|
||||
dc.x += dc.w;
|
||||
}
|
||||
|
||||
dc.w = bmw;
|
||||
drawtext(arrange == dotile ? TILESYMBOL : FLOATSYMBOL, dc.status, False);
|
||||
|
||||
x = dc.x + dc.w;
|
||||
dc.w = textw(stext);
|
||||
dc.x = bx + bw - dc.w;
|
||||
drawtext(stext, !istile, False);
|
||||
if(sel && ((dc.w = dc.x - x) >= bh)) {
|
||||
if(dc.x < x) {
|
||||
dc.x = x;
|
||||
drawtext(sel->name, istile, True);
|
||||
dc.w = bw - x;
|
||||
}
|
||||
drawtext(stext, dc.status, False);
|
||||
|
||||
if((dc.w = dc.x - x) > bh) {
|
||||
dc.x = x;
|
||||
if(sel)
|
||||
drawtext(sel->name, dc.sel, False);
|
||||
else
|
||||
drawtext(NULL, dc.norm, False);
|
||||
}
|
||||
XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
|
||||
XSync(dpy, False);
|
||||
@ -137,33 +133,19 @@ drawstatus()
|
||||
void
|
||||
drawtitle(Client *c)
|
||||
{
|
||||
int i;
|
||||
Bool istile = arrange == dotile;
|
||||
|
||||
if(c == sel) {
|
||||
if(c == sel && issel) {
|
||||
drawstatus();
|
||||
XUnmapWindow(dpy, c->title);
|
||||
XSetWindowBorder(dpy, c->win, dc.fg);
|
||||
XUnmapWindow(dpy, c->twin);
|
||||
XSetWindowBorder(dpy, c->win, dc.sel[ColBG]);
|
||||
return;
|
||||
}
|
||||
|
||||
XSetWindowBorder(dpy, c->win, dc.bg);
|
||||
XMapWindow(dpy, c->title);
|
||||
|
||||
XSetWindowBorder(dpy, c->win, dc.norm[ColBG]);
|
||||
XMapWindow(dpy, c->twin);
|
||||
dc.x = dc.y = 0;
|
||||
|
||||
dc.w = 0;
|
||||
for(i = 0; i < ntags; i++) {
|
||||
if(c->tags[i]) {
|
||||
dc.x += dc.w;
|
||||
dc.w = textw(tags[i]);
|
||||
drawtext(tags[i], !istile, True);
|
||||
}
|
||||
}
|
||||
dc.x += dc.w;
|
||||
dc.w = textw(c->name);
|
||||
drawtext(c->name, !istile, True);
|
||||
XCopyArea(dpy, dc.drawable, c->title, dc.gc, 0, 0, c->tw, c->th, 0, 0);
|
||||
dc.w = c->tw;
|
||||
drawtext(c->name, dc.norm, False);
|
||||
XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0);
|
||||
XSync(dpy, False);
|
||||
}
|
||||
|
||||
|
165
dwm.1
165
dwm.1
@ -1,4 +1,4 @@
|
||||
.TH DWM 1 dwm-0.7
|
||||
.TH DWM 1 dwm-VERSION
|
||||
.SH NAME
|
||||
dwm \- dynamic window manager
|
||||
.SH SYNOPSIS
|
||||
@ -6,7 +6,7 @@ dwm \- dynamic window manager
|
||||
.RB [ \-v ]
|
||||
.SH DESCRIPTION
|
||||
.B dwm
|
||||
is a dynamic window manager for X11. It manages windows in tiling and floating
|
||||
is a dynamic window manager for X. It manages windows in tiling and floating
|
||||
modes. Either mode can be applied dynamically, optimizing the environment for
|
||||
the application in use and the task performed.
|
||||
.P
|
||||
@ -21,47 +21,102 @@ tags. Selecting a certain tag for viewing will display all windows with that
|
||||
tag.
|
||||
.P
|
||||
.B dwm
|
||||
has a small status bar which displays the text read from standard
|
||||
input, if written. Besides that, it displays all available tags, and the title
|
||||
of the focused window. It draws a 1-pixel border around windows to
|
||||
indicate the focus state. Unfocused windows contain a small bar in front of
|
||||
them displaying their tags and title.
|
||||
contains a small status bar which displays all available tags, the mode, the
|
||||
title of the focused window, and the text read from standard input. The tags of
|
||||
the focused window are highlighted with a small point.
|
||||
.P
|
||||
.B dwm
|
||||
draws a 1-pixel border around windows to indicate the focus state.
|
||||
Unfocused windows contain a small bar in front of them displaying their title.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to standard output, then exits.
|
||||
.SH USAGE
|
||||
.SS Status bar
|
||||
.TP
|
||||
.B Standard input
|
||||
is read and displayed in the status text area.
|
||||
.TP
|
||||
.B Button1
|
||||
click on a tag label views all windows with that
|
||||
.BR tag ,
|
||||
click on the mode label toggles between
|
||||
.B tiled
|
||||
and
|
||||
.B floating
|
||||
mode.
|
||||
.TP
|
||||
.B Button3
|
||||
click on a tag label adds/removes all windows with that
|
||||
.B tag
|
||||
to/from the view.
|
||||
.TP
|
||||
.B Mod1-Button1
|
||||
click on a tag label applies that
|
||||
.B tag
|
||||
to the focused
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-Button3
|
||||
click on a tag label adds/removes that
|
||||
.B tag
|
||||
to/from the focused
|
||||
.BR window .
|
||||
.SS Keyboard commands
|
||||
.TP
|
||||
.B Mod1-Shift-Return
|
||||
Start
|
||||
.BR xterm (1).
|
||||
.TP
|
||||
.B Mod1-Tab
|
||||
Focus next
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-Shift-Tab
|
||||
Focus previous
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-Return
|
||||
Zoom
|
||||
Zoom current
|
||||
.B window
|
||||
to the
|
||||
.B master
|
||||
column
|
||||
.TP
|
||||
.B Mod1-h
|
||||
Focus previous
|
||||
.B tag
|
||||
.TP
|
||||
.B Mod1-j
|
||||
Focus next
|
||||
.B window
|
||||
.TP
|
||||
.B Mod1-k
|
||||
Focus previous
|
||||
.B window
|
||||
.TP
|
||||
.B Mod1-l
|
||||
Focus next
|
||||
.B tag
|
||||
.RB ( tiling
|
||||
mode only).
|
||||
.TP
|
||||
.B Mod1-m
|
||||
Maximize current
|
||||
.B window
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-[0..n]
|
||||
Focus
|
||||
.B Mod1-g
|
||||
Grow current
|
||||
.BR column
|
||||
.RB ( tiling
|
||||
mode only).
|
||||
.TP
|
||||
.B Mod1-s
|
||||
Shrink current
|
||||
.BR column
|
||||
.RB ( tiling
|
||||
mode only).
|
||||
.TP
|
||||
.B Mod1-Shift-[1..n]
|
||||
Apply
|
||||
.B nth tag
|
||||
to current
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-Control-Shift-[1..n]
|
||||
Add/remove
|
||||
.B nth tag
|
||||
to/from current
|
||||
.BR window .
|
||||
.TP
|
||||
.B Mod1-Shift-c
|
||||
Close focused
|
||||
.B window.
|
||||
.TP
|
||||
.B Mod1-space
|
||||
Toggle between
|
||||
@ -69,44 +124,60 @@ Toggle between
|
||||
and
|
||||
.B floating
|
||||
mode (affects
|
||||
.BR "all windows" )
|
||||
.BR "all windows" ).
|
||||
.TP
|
||||
.B Mod1-Shift-[0..n]
|
||||
Apply
|
||||
.B nth tag
|
||||
to current
|
||||
.B window
|
||||
.B Mod1-[1..n]
|
||||
View all windows with
|
||||
.BR "tag n" .
|
||||
.TP
|
||||
.B Mod1-0
|
||||
View all windows with any
|
||||
.BR "tag" .
|
||||
.TP
|
||||
.B Mod1-Control-[1..n]
|
||||
Add/remove all windows with
|
||||
.B tag n
|
||||
to/from the view.
|
||||
.TP
|
||||
.B Mod1-Shift-q
|
||||
Quit
|
||||
.B dwm
|
||||
.TP
|
||||
.B Mod1-Shift-Return
|
||||
Start
|
||||
.B terminal
|
||||
.TP
|
||||
.B Mod1-Control-[0..n]
|
||||
Append
|
||||
.B nth tag
|
||||
to current
|
||||
.B window
|
||||
.B dwm.
|
||||
.SS Mouse commands
|
||||
.TP
|
||||
.B Mod1-Button1
|
||||
Moves current
|
||||
Move current
|
||||
.B window
|
||||
while dragging
|
||||
.RB ( floating
|
||||
mode only).
|
||||
.TP
|
||||
.B Mod1-Button2
|
||||
Lowers current
|
||||
Zoom current
|
||||
.B window
|
||||
to the
|
||||
.B master
|
||||
column
|
||||
.RB ( tiling
|
||||
mode only).
|
||||
.TP
|
||||
.B Mod1-Button3
|
||||
Resizes current
|
||||
Resize current
|
||||
.B window
|
||||
while dragging
|
||||
.RB ( floating
|
||||
mode only).
|
||||
.SH CUSTOMIZATION
|
||||
.B dwm
|
||||
is customized by creating a custom config.h and (re)compiling the source
|
||||
code. This keeps it fast, secure and simple.
|
||||
.SH CAVEATS
|
||||
The status bar may display
|
||||
.B broken pipe
|
||||
when
|
||||
.B dwm
|
||||
has been started by
|
||||
.BR xdm (1),
|
||||
because it closes standard output before executing
|
||||
.BR dwm .
|
||||
.SH SEE ALSO
|
||||
.BR dmenu (1)
|
||||
|
74
dwm.h
74
dwm.h
@ -11,15 +11,10 @@
|
||||
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
|
||||
#define PROTODELWIN 1
|
||||
|
||||
typedef union Arg Arg;
|
||||
typedef struct Client Client;
|
||||
typedef struct DC DC;
|
||||
typedef struct Fnt Fnt;
|
||||
|
||||
union Arg {
|
||||
typedef union {
|
||||
const char *cmd;
|
||||
int i;
|
||||
};
|
||||
} Arg;
|
||||
|
||||
/* atoms */
|
||||
enum { NetSupported, NetWMName, NetLast };
|
||||
@ -28,27 +23,31 @@ enum { WMProtocols, WMDelete, WMLast };
|
||||
/* cursor */
|
||||
enum { CurNormal, CurResize, CurMove, CurLast };
|
||||
|
||||
/* windowcorners */
|
||||
/* color */
|
||||
enum { ColFG, ColBG, ColLast };
|
||||
|
||||
/* window corners */
|
||||
typedef enum { TopLeft, TopRight, BotLeft, BotRight } Corner;
|
||||
|
||||
struct Fnt {
|
||||
typedef struct {
|
||||
int ascent;
|
||||
int descent;
|
||||
int height;
|
||||
XFontSet set;
|
||||
XFontStruct *xfont;
|
||||
};
|
||||
} Fnt;
|
||||
|
||||
struct DC { /* draw context */
|
||||
typedef struct { /* draw context */
|
||||
int x, y, w, h;
|
||||
unsigned long bg;
|
||||
unsigned long fg;
|
||||
unsigned long border;
|
||||
unsigned long norm[ColLast];
|
||||
unsigned long sel[ColLast];
|
||||
unsigned long status[ColLast];
|
||||
Drawable drawable;
|
||||
Fnt font;
|
||||
GC gc;
|
||||
};
|
||||
} DC;
|
||||
|
||||
typedef struct Client Client;
|
||||
struct Client {
|
||||
char name[256];
|
||||
int proto;
|
||||
@ -57,24 +56,23 @@ struct Client {
|
||||
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
|
||||
int grav;
|
||||
long flags;
|
||||
unsigned int border;
|
||||
unsigned int border, weight;
|
||||
Bool isfloat;
|
||||
Bool ismax;
|
||||
Bool *tags;
|
||||
Client *next;
|
||||
Client *prev;
|
||||
Window win;
|
||||
Window title;
|
||||
Window twin;
|
||||
};
|
||||
|
||||
extern const char *tags[];
|
||||
extern char stext[1024];
|
||||
extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||
extern unsigned int ntags;
|
||||
extern int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh;
|
||||
extern unsigned int ntags, numlockmask;
|
||||
extern void (*handler[LASTEvent])(XEvent *);
|
||||
extern void (*arrange)(Arg *);
|
||||
extern Atom wmatom[WMLast], netatom[NetLast];
|
||||
extern Bool running, issel;
|
||||
extern Bool running, issel, maximized, *seltag;
|
||||
extern Client *clients, *sel;
|
||||
extern Cursor cursor[CurLast];
|
||||
extern DC dc;
|
||||
@ -84,21 +82,16 @@ extern Window root, barwin;
|
||||
/* client.c */
|
||||
extern void ban(Client *c);
|
||||
extern void focus(Client *c);
|
||||
extern void focusnext(Arg *arg);
|
||||
extern void focusprev(Arg *arg);
|
||||
extern Client *getclient(Window w);
|
||||
extern Client *getctitle(Window w);
|
||||
extern void gravitate(Client *c, Bool invert);
|
||||
extern void higher(Client *c);
|
||||
extern void killclient(Arg *arg);
|
||||
extern void lower(Client *c);
|
||||
extern void manage(Window w, XWindowAttributes *wa);
|
||||
extern void resize(Client *c, Bool sizehints, Corner sticky);
|
||||
extern void setsize(Client *c);
|
||||
extern void settitle(Client *c);
|
||||
extern void togglemax(Arg *arg);
|
||||
extern void unmanage(Client *c);
|
||||
extern void zoom(Arg *arg);
|
||||
|
||||
/* draw.c */
|
||||
extern void drawall();
|
||||
@ -110,6 +103,7 @@ extern unsigned int textw(const char *text);
|
||||
|
||||
/* event.c */
|
||||
extern void grabkeys();
|
||||
extern void procevent();
|
||||
|
||||
/* main.c */
|
||||
extern int getproto(Window w);
|
||||
@ -118,20 +112,30 @@ extern void sendevent(Window w, Atom a, long value);
|
||||
extern int xerror(Display *dsply, XErrorEvent *ee);
|
||||
|
||||
/* tag.c */
|
||||
extern void appendtag(Arg *arg);
|
||||
extern void dofloat(Arg *arg);
|
||||
extern void dotile(Arg *arg);
|
||||
extern void initrregs();
|
||||
extern Client *getnext(Client *c);
|
||||
extern Client *getprev(Client *c);
|
||||
extern void replacetag(Arg *arg);
|
||||
extern void settags(Client *c);
|
||||
extern void togglemode(Arg *arg);
|
||||
extern void view(Arg *arg);
|
||||
extern void viewnext(Arg *arg);
|
||||
extern void viewprev(Arg *arg);
|
||||
extern void settags(Client *c, Client *trans);
|
||||
extern void tag(Arg *arg);
|
||||
extern void toggletag(Arg *arg);
|
||||
|
||||
/* util.c */
|
||||
extern void *emallocz(unsigned int size);
|
||||
extern void eprint(const char *errstr, ...);
|
||||
extern void *erealloc(void *ptr, unsigned int size);
|
||||
extern void spawn(Arg *arg);
|
||||
|
||||
/* view.c */
|
||||
extern void detach(Client *c);
|
||||
extern void dofloat(Arg *arg);
|
||||
extern void dotile(Arg *arg);
|
||||
extern void focusnext(Arg *arg);
|
||||
extern void focusprev(Arg *arg);
|
||||
extern Bool isvisible(Client *c);
|
||||
extern void resizecol(Arg *arg);
|
||||
extern void restack();
|
||||
extern void togglemode(Arg *arg);
|
||||
extern void toggleview(Arg *arg);
|
||||
extern void view(Arg *arg);
|
||||
extern void viewall(Arg *arg);
|
||||
extern void zoom(Arg *arg);
|
||||
|
125
dwm.html
125
dwm.html
@ -1,125 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>dwm - dynamic window manager</title>
|
||||
<meta name="author" content="Anselm R. Garbe">
|
||||
<meta name="generator" content="ed">
|
||||
<meta name="copyright" content="(C)opyright 2006 by Anselm R. Garbe">
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: #000000;
|
||||
font-family: sans-serif;
|
||||
margin: 20px 20px 20px 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<img src="dwm.png"/><br />
|
||||
<h3>dynamic window manager</h3>
|
||||
</center>
|
||||
<h3>Description</h3>
|
||||
<p>
|
||||
dwm is a dynamic window manager for X11.
|
||||
</p>
|
||||
<h4>Philosophy</h4>
|
||||
<p>
|
||||
As founder and main developer of wmii I came to the conclusion that
|
||||
wmii is too clunky for my needs. I don't need so many funky features
|
||||
and all this hype about remote control through a 9P service, I only
|
||||
want to manage my windows in a simple, but dynamic way. wmii never got
|
||||
finished because I listened to users, who proposed arbitrary ideas I
|
||||
considered useful. This resulted in an extreme <a
|
||||
href="http://www.jwz.org/doc/cadt.html">CADT</a> development model,
|
||||
which was a mistake. Thus the philosophy of dwm is simply <i>to fit my
|
||||
needs</i> (maybe yours as well). That's it.
|
||||
</p>
|
||||
<h4>Differences to ion, larswm, and wmii</h4>
|
||||
<p>
|
||||
In contrast to ion, larswm, and wmii, dwm is much smaller, faster and simpler.
|
||||
</p>
|
||||
<ul>
|
||||
<li>
|
||||
dwm has no Lua integration, no 9P support, no editable
|
||||
tagbars, no shell-based configuration, no remote control, and comes
|
||||
without any additional tools like printing the selection or warping
|
||||
the mouse.
|
||||
</li>
|
||||
<li>
|
||||
dwm is only a single binary, it's source code is intended to never
|
||||
exceed 2000 SLOC.
|
||||
</li>
|
||||
<li>
|
||||
dwm is based on tagging and dynamic window management (however
|
||||
simpler than ion, wmii or larswm). It manages windows in
|
||||
tiling and floating modes. Either mode can be applied dynamically,
|
||||
depending on the application in use and the task performed.
|
||||
</li>
|
||||
<li>
|
||||
dwm don't distinguishes between layers, there is no floating or
|
||||
tiled layer. Wether the clients of currently selected tag are in
|
||||
tiled mode or not, you can re-arrange all clients on the fly.
|
||||
Popup- and fixed-size windows are treated floating, however.
|
||||
</li>
|
||||
<li>
|
||||
dwm is customized through editing its source code, that makes it
|
||||
extremely fast and secure - it does not process any input data
|
||||
which hasn't been known at compile time, except window title names
|
||||
and status text read from standard input. You don't have to learn
|
||||
Lua/sh/ruby or some weird configuration file format (like X
|
||||
resource files), beside C to customize it for your needs,
|
||||
you <b>only</b> have to learn C (at least editing header files).
|
||||
</li>
|
||||
<li>
|
||||
Because dwm is customized through editing its source code, it's
|
||||
pointless to make binary packages of it. This keeps its userbase
|
||||
small and elitist. No novices asking stupid questions.
|
||||
</li>
|
||||
<li>
|
||||
dwm uses 1-pixel borders to provide the maximum of screen real
|
||||
estate to clients. Small titlebars are only drawn in front of
|
||||
unfocused clients.
|
||||
</li>
|
||||
<li>
|
||||
dwm reads from standard input to print arbitrary status text (like
|
||||
the date, load, battery charge). That's much simpler than
|
||||
larsremote, wmiir and what not...
|
||||
</li>
|
||||
<li>
|
||||
It can be downloaded and distributed under the conditions
|
||||
of the <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm?f=f10eb1139362;file=LICENSE;style=raw">MIT/X Consortium license</a>.
|
||||
</li>
|
||||
<li>
|
||||
Optionally you can install <b>dmenu</b> to extend dwm with a wmii-alike menu.
|
||||
</li>
|
||||
</ul>
|
||||
<h4>Links</h4>
|
||||
<ul>
|
||||
<li><a href="http://10kloc.org/cgi-bin/man/man2html?query=dwm">Man page</a></li>
|
||||
<li><a href="http://10kloc.org/shots/dwm-20060801.png">Screenshot</a> (20060801)</li>
|
||||
<li><a href="http://10kloc.org/download/poster.ps">A4 poster (PostScript)</a></li>
|
||||
<li>Mailing List: <a href="http://10kloc.org/cgi-bin/mailman/listinfo/dwm">dwm at wmii dot de</a> <a href="http://10kloc.org/pipermail/dwm/">(Archives)</a></li>
|
||||
<li>IRC channel: <code>#dwm</code> at <code>irc.oftc.net</code></li>
|
||||
</ul>
|
||||
<h3>Download</h3>
|
||||
<ul>
|
||||
<li><a href="http://10kloc.org/download/dwm-0.7.tar.gz">dwm 0.7</a> (14kb) (20060807)</li>
|
||||
<li><a href="http://10kloc.org/download/dmenu-0.2.tar.gz">dmenu 0.2</a> (7kb) (20060807)</li>
|
||||
</ul>
|
||||
<h3>Development</h3>
|
||||
<p>
|
||||
dwm is actively developed in parallel to wmii. You can <a href="http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm">browse</a> its source code repository or get a copy using <a href="http://www.selenic.com/mercurial/">Mercurial</a> with following command:
|
||||
</p>
|
||||
<p>
|
||||
<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/dwm</code>
|
||||
</p>
|
||||
<p>
|
||||
<code>hg clone http://10kloc.org/cgi-bin/hgwebdir.cgi/dmenu</code>
|
||||
</p>
|
||||
<h3>Miscellaneous</h3>
|
||||
<p>
|
||||
You can purchase this <a href="https://www.spreadshirt.net/shop.php?op=article&article_id=3298632&view=403">tricot</a>
|
||||
if you like dwm and the dwm logo, which has been designed by Anselm.
|
||||
</p>
|
||||
<p><small>--Anselm</small></p>
|
||||
</body>
|
||||
</html>
|
171
event.c
171
event.c
@ -18,7 +18,7 @@ typedef struct {
|
||||
|
||||
KEYS
|
||||
|
||||
#define CLEANMASK(mask) (mask & ~(NUMLOCKMASK | LockMask))
|
||||
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
|
||||
|
||||
static void
|
||||
movemouse(Client *c)
|
||||
@ -58,6 +58,7 @@ static void
|
||||
resizemouse(Client *c)
|
||||
{
|
||||
int ocx, ocy;
|
||||
int nw, nh;
|
||||
Corner sticky;
|
||||
XEvent ev;
|
||||
|
||||
@ -76,8 +77,10 @@ resizemouse(Client *c)
|
||||
break;
|
||||
case MotionNotify:
|
||||
XSync(dpy, False);
|
||||
c->w = abs(ocx - ev.xmotion.x);
|
||||
c->h = abs(ocy - ev.xmotion.y);
|
||||
if((nw = abs(ocx - ev.xmotion.x)))
|
||||
c->w = abs(ocx - ev.xmotion.x);
|
||||
if((nh = abs(ocy - ev.xmotion.y)))
|
||||
c->h = abs(ocy - ev.xmotion.y);
|
||||
c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
|
||||
c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
|
||||
if(ocx <= ev.xmotion.x)
|
||||
@ -102,59 +105,79 @@ buttonpress(XEvent *e)
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
|
||||
if(barwin == ev->window) {
|
||||
switch(ev->button) {
|
||||
default:
|
||||
x = 0;
|
||||
for(a.i = 0; a.i < ntags; a.i++) {
|
||||
x += textw(tags[a.i]);
|
||||
if(ev->x < x) {
|
||||
view(&a);
|
||||
break;
|
||||
x = 0;
|
||||
for(a.i = 0; a.i < ntags; a.i++) {
|
||||
x += textw(tags[a.i]);
|
||||
if(ev->x < x) {
|
||||
if(ev->button == Button1) {
|
||||
if(ev->state & MODKEY)
|
||||
tag(&a);
|
||||
else
|
||||
view(&a);
|
||||
}
|
||||
else if(ev->button == Button3) {
|
||||
if(ev->state & MODKEY)
|
||||
toggletag(&a);
|
||||
else
|
||||
toggleview(&a);
|
||||
}
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case Button4:
|
||||
viewnext(&a);
|
||||
break;
|
||||
case Button5:
|
||||
viewprev(&a);
|
||||
break;
|
||||
}
|
||||
if(ev->x < x + bmw) {
|
||||
if(ev->button == Button1)
|
||||
togglemode(NULL);
|
||||
}
|
||||
}
|
||||
else if((c = getclient(ev->window))) {
|
||||
focus(c);
|
||||
switch(ev->button) {
|
||||
default:
|
||||
break;
|
||||
case Button1:
|
||||
if(!c->ismax && (arrange == dofloat || c->isfloat)) {
|
||||
higher(c);
|
||||
movemouse(c);
|
||||
}
|
||||
break;
|
||||
case Button2:
|
||||
lower(c);
|
||||
break;
|
||||
case Button3:
|
||||
if(!c->ismax && (arrange == dofloat || c->isfloat)) {
|
||||
higher(c);
|
||||
resizemouse(c);
|
||||
}
|
||||
break;
|
||||
if(maximized || CLEANMASK(ev->state) != MODKEY)
|
||||
return;
|
||||
if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) {
|
||||
restack(c);
|
||||
movemouse(c);
|
||||
}
|
||||
else if(ev->button == Button2)
|
||||
zoom(NULL);
|
||||
else if(ev->button == Button3 && (arrange == dofloat || c->isfloat)) {
|
||||
restack(c);
|
||||
resizemouse(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
synconfig(Client *c, int x, int y, int w, int h, unsigned int border)
|
||||
{
|
||||
XEvent synev;
|
||||
|
||||
synev.type = ConfigureNotify;
|
||||
synev.xconfigure.display = dpy;
|
||||
synev.xconfigure.event = c->win;
|
||||
synev.xconfigure.window = c->win;
|
||||
synev.xconfigure.x = x;
|
||||
synev.xconfigure.y = y;
|
||||
synev.xconfigure.width = w;
|
||||
synev.xconfigure.height = h;
|
||||
synev.xconfigure.border_width = border;
|
||||
synev.xconfigure.above = None;
|
||||
XSendEvent(dpy, c->win, True, NoEventMask, &synev);
|
||||
}
|
||||
|
||||
static void
|
||||
configurerequest(XEvent *e)
|
||||
{
|
||||
unsigned long newmask;
|
||||
Client *c;
|
||||
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||
XEvent synev;
|
||||
XWindowChanges wc;
|
||||
unsigned long newmask;
|
||||
|
||||
if((c = getclient(ev->window))) {
|
||||
if((c == sel) && !c->isfloat && (arrange != dofloat) && maximized) {
|
||||
synconfig(c, sx, sy + bh, sw - 2, sh - 2 - bh, ev->border_width);
|
||||
XSync(dpy, False);
|
||||
return;
|
||||
}
|
||||
gravitate(c, True);
|
||||
if(ev->value_mask & CWX)
|
||||
c->x = ev->x;
|
||||
@ -174,20 +197,8 @@ configurerequest(XEvent *e)
|
||||
newmask = ev->value_mask & (~(CWSibling | CWStackMode | CWBorderWidth));
|
||||
if(newmask)
|
||||
XConfigureWindow(dpy, c->win, newmask, &wc);
|
||||
else {
|
||||
synev.type = ConfigureNotify;
|
||||
synev.xconfigure.display = dpy;
|
||||
synev.xconfigure.event = c->win;
|
||||
synev.xconfigure.window = c->win;
|
||||
synev.xconfigure.x = c->x;
|
||||
synev.xconfigure.y = c->y;
|
||||
synev.xconfigure.width = c->w;
|
||||
synev.xconfigure.height = c->h;
|
||||
synev.xconfigure.border_width = c->border;
|
||||
synev.xconfigure.above = None;
|
||||
/* Send synthetic ConfigureNotify */
|
||||
XSendEvent(dpy, c->win, True, NoEventMask, &synev);
|
||||
}
|
||||
else
|
||||
synconfig(c, c->x, c->y, c->w, c->h, c->border);
|
||||
XSync(dpy, False);
|
||||
if(c->isfloat)
|
||||
resize(c, False, TopLeft);
|
||||
@ -223,13 +234,16 @@ enternotify(XEvent *e)
|
||||
Client *c;
|
||||
XCrossingEvent *ev = &e->xcrossing;
|
||||
|
||||
if(ev->detail == NotifyInferior)
|
||||
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
|
||||
return;
|
||||
|
||||
if((c = getclient(ev->window)) || (c = getctitle(ev->window)))
|
||||
focus(c);
|
||||
else if(ev->window == root)
|
||||
else if(ev->window == root) {
|
||||
issel = True;
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
drawall();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -255,13 +269,15 @@ keypress(XEvent *e)
|
||||
XKeyEvent *ev = &e->xkey;
|
||||
|
||||
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
|
||||
for(i = 0; i < len; i++)
|
||||
for(i = 0; i < len; i++) {
|
||||
if(keysym == key[i].keysym &&
|
||||
CLEANMASK(key[i].mod) == CLEANMASK(ev->state)) {
|
||||
CLEANMASK(key[i].mod) == CLEANMASK(ev->state))
|
||||
{
|
||||
if(key[i].func)
|
||||
key[i].func(&key[i].arg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -269,8 +285,20 @@ leavenotify(XEvent *e)
|
||||
{
|
||||
XCrossingEvent *ev = &e->xcrossing;
|
||||
|
||||
if((ev->window == root) && !ev->same_screen)
|
||||
issel = True;
|
||||
if((ev->window == root) && !ev->same_screen) {
|
||||
issel = False;
|
||||
drawall();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mappingnotify(XEvent *e)
|
||||
{
|
||||
XMappingEvent *ev = &e->xmapping;
|
||||
|
||||
XRefreshKeyboardMapping(ev);
|
||||
if(ev->request == MappingKeyboard)
|
||||
grabkeys();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -345,6 +373,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
|
||||
[LeaveNotify] = leavenotify,
|
||||
[Expose] = expose,
|
||||
[KeyPress] = keypress,
|
||||
[MappingNotify] = mappingnotify,
|
||||
[MapRequest] = maprequest,
|
||||
[PropertyNotify] = propertynotify,
|
||||
[UnmapNotify] = unmapnotify
|
||||
@ -357,23 +386,29 @@ grabkeys()
|
||||
unsigned int i;
|
||||
KeyCode code;
|
||||
|
||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||
for(i = 0; i < len; i++) {
|
||||
code = XKeysymToKeycode(dpy, key[i].keysym);
|
||||
/* normal */
|
||||
XUngrabKey(dpy, code, key[i].mod, root);
|
||||
XGrabKey(dpy, code, key[i].mod, root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
/* capslock */
|
||||
XUngrabKey(dpy, code, key[i].mod | LockMask, root);
|
||||
XGrabKey(dpy, code, key[i].mod | LockMask, root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
/* numlock */
|
||||
XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root);
|
||||
XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK, root, True,
|
||||
XGrabKey(dpy, code, key[i].mod | numlockmask, root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
/* capslock & numlock */
|
||||
XUngrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root);
|
||||
XGrabKey(dpy, code, key[i].mod | NUMLOCKMASK | LockMask, root, True,
|
||||
XGrabKey(dpy, code, key[i].mod | numlockmask | LockMask, root, True,
|
||||
GrabModeAsync, GrabModeAsync);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
procevent()
|
||||
{
|
||||
XEvent ev;
|
||||
|
||||
while(XPending(dpy)) {
|
||||
XNextEvent(dpy, &ev);
|
||||
if(handler[ev.type])
|
||||
(handler[ev.type])(&ev); /* call handler */
|
||||
}
|
||||
}
|
||||
|
||||
|
242
main.c
242
main.c
@ -11,22 +11,51 @@
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
#include <X11/cursorfont.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xproto.h>
|
||||
|
||||
/* extern */
|
||||
|
||||
char stext[1024];
|
||||
Bool *seltag;
|
||||
int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh;
|
||||
unsigned int ntags, numlockmask;
|
||||
Atom wmatom[WMLast], netatom[NetLast];
|
||||
Bool running = True;
|
||||
Bool issel = True;
|
||||
Bool maximized = False;
|
||||
Client *clients = NULL;
|
||||
Client *sel = NULL;
|
||||
Cursor cursor[CurLast];
|
||||
Display *dpy;
|
||||
DC dc = {0};
|
||||
Window root, barwin;
|
||||
|
||||
/* static */
|
||||
|
||||
static int (*xerrorxlib)(Display *, XErrorEvent *);
|
||||
static Bool otherwm;
|
||||
static Bool otherwm, readin;
|
||||
|
||||
static void
|
||||
cleanup()
|
||||
{
|
||||
close(STDIN_FILENO);
|
||||
while(sel) {
|
||||
resize(sel, True, TopLeft);
|
||||
unmanage(sel);
|
||||
}
|
||||
if(dc.font.set)
|
||||
XFreeFontSet(dpy, dc.font.set);
|
||||
else
|
||||
XFreeFont(dpy, dc.font.xfont);
|
||||
XUngrabKey(dpy, AnyKey, AnyModifier, root);
|
||||
XFreePixmap(dpy, dc.drawable);
|
||||
XFreeGC(dpy, dc.gc);
|
||||
XDestroyWindow(dpy, barwin);
|
||||
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||||
XSync(dpy, False);
|
||||
free(seltag);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -36,6 +65,7 @@ scan()
|
||||
Window *wins, d1, d2;
|
||||
XWindowAttributes wa;
|
||||
|
||||
wins = NULL;
|
||||
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
|
||||
for(i = 0; i < num; i++) {
|
||||
if(!XGetWindowAttributes(dpy, wins[i], &wa))
|
||||
@ -50,23 +80,81 @@ scan()
|
||||
XFree(wins);
|
||||
}
|
||||
|
||||
static int
|
||||
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
|
||||
static void
|
||||
setup()
|
||||
{
|
||||
int status, format;
|
||||
unsigned long res, extra;
|
||||
Atom real;
|
||||
int i, j;
|
||||
unsigned int mask;
|
||||
Window w;
|
||||
XModifierKeymap *modmap;
|
||||
XSetWindowAttributes wa;
|
||||
|
||||
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
|
||||
&res, &extra, prop);
|
||||
/* init atoms */
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) netatom, NetLast);
|
||||
|
||||
if(status != Success || *prop == 0) {
|
||||
return 0;
|
||||
/* init cursors */
|
||||
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
||||
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
||||
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
|
||||
|
||||
modmap = XGetModifierMapping(dpy);
|
||||
for (i = 0; i < 8; i++) {
|
||||
for (j = 0; j < modmap->max_keypermod; j++) {
|
||||
if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
|
||||
numlockmask = (1 << i);
|
||||
}
|
||||
}
|
||||
if(res == 0) {
|
||||
free((void *) *prop);
|
||||
}
|
||||
return res;
|
||||
XFree(modmap);
|
||||
|
||||
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask;
|
||||
wa.cursor = cursor[CurNormal];
|
||||
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||||
|
||||
grabkeys();
|
||||
initrregs();
|
||||
|
||||
for(ntags = 0; tags[ntags]; ntags++);
|
||||
seltag = emallocz(sizeof(Bool) * ntags);
|
||||
seltag[0] = True;
|
||||
|
||||
/* style */
|
||||
dc.norm[ColBG] = getcolor(NORMBGCOLOR);
|
||||
dc.norm[ColFG] = getcolor(NORMFGCOLOR);
|
||||
dc.sel[ColBG] = getcolor(SELBGCOLOR);
|
||||
dc.sel[ColFG] = getcolor(SELFGCOLOR);
|
||||
dc.status[ColBG] = getcolor(STATUSBGCOLOR);
|
||||
dc.status[ColFG] = getcolor(STATUSFGCOLOR);
|
||||
setfont(FONT);
|
||||
|
||||
bmw = textw(FLOATSYMBOL) > textw(TILESYMBOL) ? textw(FLOATSYMBOL) : textw(TILESYMBOL);
|
||||
sx = sy = 0;
|
||||
sw = DisplayWidth(dpy, screen);
|
||||
sh = DisplayHeight(dpy, screen);
|
||||
mw = (sw * MASTERW) / 100;
|
||||
|
||||
bx = by = 0;
|
||||
bw = sw;
|
||||
dc.h = bh = dc.font.height + 2;
|
||||
wa.override_redirect = 1;
|
||||
wa.background_pixmap = ParentRelative;
|
||||
wa.event_mask = ButtonPressMask | ExposureMask;
|
||||
barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
|
||||
CopyFromParent, DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
||||
XMapRaised(dpy, barwin);
|
||||
|
||||
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
|
||||
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
||||
|
||||
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -82,38 +170,22 @@ xerrorstart(Display *dsply, XErrorEvent *ee)
|
||||
|
||||
/* extern */
|
||||
|
||||
char stext[1024];
|
||||
int tsel = DEFTAG;
|
||||
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
|
||||
unsigned int ntags;
|
||||
Atom wmatom[WMLast], netatom[NetLast];
|
||||
Bool running = True;
|
||||
Bool issel = True;
|
||||
Client *clients = NULL;
|
||||
Client *sel = NULL;
|
||||
Cursor cursor[CurLast];
|
||||
Display *dpy;
|
||||
DC dc = {0};
|
||||
Window root, barwin;
|
||||
|
||||
int
|
||||
getproto(Window w)
|
||||
{
|
||||
int protos = 0;
|
||||
int i;
|
||||
long res;
|
||||
Atom *protocols;
|
||||
int i, format, protos, status;
|
||||
unsigned long extra, res;
|
||||
Atom *protocols, real;
|
||||
|
||||
res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L,
|
||||
((unsigned char **)&protocols));
|
||||
if(res <= 0) {
|
||||
protos = 0;
|
||||
status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L, False,
|
||||
XA_ATOM, &real, &format, &res, &extra, (unsigned char **)&protocols);
|
||||
if(status != Success || protocols == 0)
|
||||
return protos;
|
||||
}
|
||||
for(i = 0; i < res; i++) {
|
||||
for(i = 0; i < res; i++)
|
||||
if(protocols[i] == wmatom[WMDelete])
|
||||
protos |= PROTODELWIN;
|
||||
}
|
||||
free((char *) protocols);
|
||||
free(protocols);
|
||||
return protos;
|
||||
}
|
||||
|
||||
@ -135,7 +207,7 @@ sendevent(Window w, Atom a, long value)
|
||||
void
|
||||
quit(Arg *arg)
|
||||
{
|
||||
running = False;
|
||||
readin = running = False;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -162,13 +234,8 @@ xerror(Display *dpy, XErrorEvent *ee)
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
unsigned int mask;
|
||||
int r, xfd;
|
||||
fd_set rd;
|
||||
Bool readin = True;
|
||||
Window w;
|
||||
XEvent ev;
|
||||
XSetWindowAttributes wa;
|
||||
|
||||
if(argc == 2 && !strncmp("-v", argv[1], 3)) {
|
||||
fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout);
|
||||
@ -181,6 +248,7 @@ main(int argc, char *argv[])
|
||||
if(!dpy)
|
||||
eprint("dwm: cannot open display\n");
|
||||
|
||||
xfd = ConnectionNumber(dpy);
|
||||
screen = DefaultScreen(dpy);
|
||||
root = RootWindow(dpy, screen);
|
||||
|
||||
@ -193,84 +261,28 @@ main(int argc, char *argv[])
|
||||
if(otherwm)
|
||||
eprint("dwm: another window manager is already running\n");
|
||||
|
||||
XSync(dpy, False);
|
||||
XSetErrorHandler(NULL);
|
||||
xerrorxlib = XSetErrorHandler(xerror);
|
||||
XSync(dpy, False);
|
||||
|
||||
/* init atoms */
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
|
||||
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
|
||||
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
|
||||
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
|
||||
PropModeReplace, (unsigned char *) netatom, NetLast);
|
||||
|
||||
/* init cursors */
|
||||
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
|
||||
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
|
||||
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
|
||||
|
||||
grabkeys();
|
||||
initrregs();
|
||||
|
||||
for(ntags = 0; tags[ntags]; ntags++);
|
||||
|
||||
/* style */
|
||||
dc.bg = getcolor(BGCOLOR);
|
||||
dc.fg = getcolor(FGCOLOR);
|
||||
dc.border = getcolor(BORDERCOLOR);
|
||||
setfont(FONT);
|
||||
|
||||
sx = sy = 0;
|
||||
sw = DisplayWidth(dpy, screen);
|
||||
sh = DisplayHeight(dpy, screen);
|
||||
mw = (sw * MASTERW) / 100;
|
||||
|
||||
wa.override_redirect = 1;
|
||||
wa.background_pixmap = ParentRelative;
|
||||
wa.event_mask = ButtonPressMask | ExposureMask;
|
||||
|
||||
bx = by = 0;
|
||||
bw = sw;
|
||||
dc.h = bh = dc.font.height + 4;
|
||||
barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
|
||||
CopyFromParent, DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||
XDefineCursor(dpy, barwin, cursor[CurNormal]);
|
||||
XMapRaised(dpy, barwin);
|
||||
|
||||
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
|
||||
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||
setup();
|
||||
drawstatus();
|
||||
|
||||
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
|
||||
|
||||
wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
|
||||
wa.cursor = cursor[CurNormal];
|
||||
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
|
||||
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
scan();
|
||||
|
||||
/* main event loop, reads status text from stdin as well */
|
||||
/* main event loop, also reads status text from stdin */
|
||||
XSync(dpy, False);
|
||||
procevent();
|
||||
readin = True;
|
||||
while(running) {
|
||||
FD_ZERO(&rd);
|
||||
if(readin)
|
||||
FD_SET(STDIN_FILENO, &rd);
|
||||
FD_SET(ConnectionNumber(dpy), &rd);
|
||||
|
||||
i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
|
||||
if(i == -1 && errno == EINTR)
|
||||
FD_SET(xfd, &rd);
|
||||
r = select(xfd + 1, &rd, NULL, NULL, NULL);
|
||||
if((r == -1) && (errno == EINTR))
|
||||
continue;
|
||||
if(i < 0)
|
||||
eprint("select failed\n");
|
||||
else if(i > 0) {
|
||||
if(FD_ISSET(ConnectionNumber(dpy), &rd)) {
|
||||
while(XPending(dpy)) {
|
||||
XNextEvent(dpy, &ev);
|
||||
if(handler[ev.type])
|
||||
(handler[ev.type])(&ev); /* call handler */
|
||||
}
|
||||
}
|
||||
if(r > 0) {
|
||||
if(readin && FD_ISSET(STDIN_FILENO, &rd)) {
|
||||
readin = NULL != fgets(stext, sizeof(stext), stdin);
|
||||
if(readin)
|
||||
@ -280,8 +292,10 @@ main(int argc, char *argv[])
|
||||
drawstatus();
|
||||
}
|
||||
}
|
||||
else if(r < 0)
|
||||
eprint("select failed\n");
|
||||
procevent();
|
||||
}
|
||||
|
||||
cleanup();
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
|
176
tag.c
176
tag.c
@ -30,116 +30,19 @@ RULES
|
||||
static RReg *rreg = NULL;
|
||||
static unsigned int len = 0;
|
||||
|
||||
void (*arrange)(Arg *) = DEFMODE;
|
||||
|
||||
/* extern */
|
||||
|
||||
void
|
||||
appendtag(Arg *arg)
|
||||
{
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
sel->tags[arg->i] = True;
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
dofloat(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
for(c = clients; c; c = c->next) {
|
||||
c->ismax = False;
|
||||
if(c->tags[tsel]) {
|
||||
resize(c, True, TopLeft);
|
||||
}
|
||||
else
|
||||
ban(c);
|
||||
}
|
||||
if((sel = getnext(clients))) {
|
||||
higher(sel);
|
||||
focus(sel);
|
||||
}
|
||||
else
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
drawall();
|
||||
}
|
||||
|
||||
void
|
||||
dotile(Arg *arg)
|
||||
{
|
||||
int n, i, w, h;
|
||||
Client *c;
|
||||
|
||||
w = sw - mw;
|
||||
for(n = 0, c = clients; c; c = c->next)
|
||||
if(c->tags[tsel] && !c->isfloat)
|
||||
n++;
|
||||
|
||||
if(n > 1)
|
||||
h = (sh - bh) / (n - 1);
|
||||
else
|
||||
h = sh - bh;
|
||||
|
||||
for(i = 0, c = clients; c; c = c->next) {
|
||||
c->ismax = False;
|
||||
if(c->tags[tsel]) {
|
||||
if(c->isfloat) {
|
||||
higher(c);
|
||||
resize(c, True, TopLeft);
|
||||
continue;
|
||||
}
|
||||
if(n == 1) {
|
||||
c->x = sx;
|
||||
c->y = sy + bh;
|
||||
c->w = sw - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
else if(i == 0) {
|
||||
c->x = sx;
|
||||
c->y = sy + bh;
|
||||
c->w = mw - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
else if(h > bh) {
|
||||
c->x = sx + mw;
|
||||
c->y = sy + (i - 1) * h + bh;
|
||||
c->w = w - 2;
|
||||
c->h = h - 2;
|
||||
}
|
||||
else { /* fallback if h < bh */
|
||||
c->x = sx + mw;
|
||||
c->y = sy + bh;
|
||||
c->w = w - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
resize(c, False, TopLeft);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
ban(c);
|
||||
}
|
||||
if((sel = getnext(clients))) {
|
||||
higher(sel);
|
||||
focus(sel);
|
||||
}
|
||||
else
|
||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||
drawall();
|
||||
}
|
||||
|
||||
Client *
|
||||
getnext(Client *c)
|
||||
{
|
||||
for(; c && !c->tags[tsel]; c = c->next);
|
||||
for(; c && !isvisible(c); c = c->next);
|
||||
return c;
|
||||
}
|
||||
|
||||
Client *
|
||||
getprev(Client *c)
|
||||
{
|
||||
for(; c && !c->tags[tsel]; c = c->prev);
|
||||
for(; c && !isvisible(c); c = c->prev);
|
||||
return c;
|
||||
}
|
||||
|
||||
@ -173,33 +76,24 @@ initrregs()
|
||||
}
|
||||
|
||||
void
|
||||
replacetag(Arg *arg)
|
||||
settags(Client *c, Client *trans)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
for(i = 0; i < ntags; i++)
|
||||
sel->tags[i] = False;
|
||||
appendtag(arg);
|
||||
}
|
||||
|
||||
void
|
||||
settags(Client *c)
|
||||
{
|
||||
char classinst[256];
|
||||
char prop[512];
|
||||
unsigned int i, j;
|
||||
regmatch_t tmp;
|
||||
Bool matched = False;
|
||||
Bool matched = trans != NULL;
|
||||
XClassHint ch;
|
||||
|
||||
if(XGetClassHint(dpy, c->win, &ch)) {
|
||||
snprintf(classinst, sizeof(classinst), "%s:%s",
|
||||
if(matched) {
|
||||
for(i = 0; i < ntags; i++)
|
||||
c->tags[i] = trans->tags[i];
|
||||
}
|
||||
else if(XGetClassHint(dpy, c->win, &ch)) {
|
||||
snprintf(prop, sizeof(prop), "%s:%s:%s",
|
||||
ch.res_class ? ch.res_class : "",
|
||||
ch.res_name ? ch.res_name : "");
|
||||
ch.res_name ? ch.res_name : "", c->name);
|
||||
for(i = 0; !matched && i < len; i++)
|
||||
if(rreg[i].clregex && !regexec(rreg[i].clregex, classinst, 1, &tmp, 0)) {
|
||||
if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
|
||||
c->isfloat = rule[i].isfloat;
|
||||
for(j = 0; rreg[i].tregex && j < ntags; j++) {
|
||||
if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
|
||||
@ -214,34 +108,38 @@ settags(Client *c)
|
||||
XFree(ch.res_name);
|
||||
}
|
||||
if(!matched)
|
||||
c->tags[tsel] = True;
|
||||
for(i = 0; i < ntags; i++)
|
||||
c->tags[i] = seltag[i];
|
||||
for(c->weight = 0; c->weight < ntags && !c->tags[c->weight]; c->weight++);
|
||||
}
|
||||
|
||||
void
|
||||
togglemode(Arg *arg)
|
||||
tag(Arg *arg)
|
||||
{
|
||||
arrange = arrange == dofloat ? dotile : dofloat;
|
||||
unsigned int i;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
for(i = 0; i < ntags; i++)
|
||||
sel->tags[i] = False;
|
||||
sel->tags[arg->i] = True;
|
||||
sel->weight = arg->i;
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
view(Arg *arg)
|
||||
toggletag(Arg *arg)
|
||||
{
|
||||
tsel = arg->i;
|
||||
unsigned int i;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
sel->tags[arg->i] = !sel->tags[arg->i];
|
||||
for(i = 0; i < ntags && !sel->tags[i]; i++);
|
||||
if(i == ntags)
|
||||
sel->tags[arg->i] = True;
|
||||
sel->weight = (i == ntags) ? arg->i : i;
|
||||
arrange(NULL);
|
||||
drawall();
|
||||
}
|
||||
|
||||
void
|
||||
viewnext(Arg *arg)
|
||||
{
|
||||
arg->i = (tsel < ntags-1) ? tsel+1 : 0;
|
||||
view(arg);
|
||||
}
|
||||
|
||||
void
|
||||
viewprev(Arg *arg)
|
||||
{
|
||||
arg->i = (tsel > 0) ? tsel-1 : ntags-1;
|
||||
view(arg);
|
||||
}
|
||||
|
24
util.c
24
util.c
@ -9,14 +9,6 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* static */
|
||||
|
||||
static void
|
||||
bad_malloc(unsigned int size)
|
||||
{
|
||||
eprint("fatal: could not malloc() %u bytes\n", size);
|
||||
}
|
||||
|
||||
/* extern */
|
||||
|
||||
void *
|
||||
@ -25,7 +17,7 @@ emallocz(unsigned int size)
|
||||
void *res = calloc(1, size);
|
||||
|
||||
if(!res)
|
||||
bad_malloc(size);
|
||||
eprint("fatal: could not malloc() %u bytes\n", size);
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -40,6 +32,15 @@ eprint(const char *errstr, ...)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void *
|
||||
erealloc(void *ptr, unsigned int size)
|
||||
{
|
||||
void *res = realloc(ptr, size);
|
||||
if(!res)
|
||||
eprint("fatal: could not malloc() %u bytes\n", size);
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
spawn(Arg *arg)
|
||||
{
|
||||
@ -50,13 +51,14 @@ spawn(Arg *arg)
|
||||
|
||||
if(!arg->cmd)
|
||||
return;
|
||||
/* the double-fork construct avoids zombie processes */
|
||||
if(fork() == 0) {
|
||||
if(fork() == 0) {
|
||||
if(dpy)
|
||||
close(ConnectionNumber(dpy));
|
||||
setsid();
|
||||
execl(shell, shell, "-c", arg->cmd, NULL);
|
||||
fprintf(stderr, "dwm: execl '%s'", arg->cmd);
|
||||
execl(shell, shell, "-c", arg->cmd, (char *)NULL);
|
||||
fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg->cmd);
|
||||
perror(" failed");
|
||||
}
|
||||
exit(0);
|
||||
|
306
view.c
Normal file
306
view.c
Normal file
@ -0,0 +1,306 @@
|
||||
/*
|
||||
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
#include "dwm.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/* static */
|
||||
|
||||
static Client *
|
||||
minclient()
|
||||
{
|
||||
Client *c, *min;
|
||||
|
||||
for(min = c = clients; c; c = c->next)
|
||||
if(c->weight < min->weight)
|
||||
min = c;
|
||||
return min;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
reorder()
|
||||
{
|
||||
Client *c, *newclients, *tail;
|
||||
|
||||
newclients = tail = NULL;
|
||||
while((c = minclient())) {
|
||||
detach(c);
|
||||
if(tail) {
|
||||
c->prev = tail;
|
||||
tail->next = c;
|
||||
tail = c;
|
||||
}
|
||||
else
|
||||
tail = newclients = c;
|
||||
}
|
||||
clients = newclients;
|
||||
}
|
||||
|
||||
static Client *
|
||||
nexttiled(Client *c)
|
||||
{
|
||||
for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
|
||||
return c;
|
||||
}
|
||||
|
||||
/* extern */
|
||||
|
||||
void (*arrange)(Arg *) = DEFMODE;
|
||||
|
||||
void
|
||||
detach(Client *c)
|
||||
{
|
||||
if(c->prev)
|
||||
c->prev->next = c->next;
|
||||
if(c->next)
|
||||
c->next->prev = c->prev;
|
||||
if(c == clients)
|
||||
clients = c->next;
|
||||
c->next = c->prev = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
dofloat(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
maximized = False;
|
||||
|
||||
for(c = clients; c; c = c->next) {
|
||||
if(isvisible(c)) {
|
||||
resize(c, True, TopLeft);
|
||||
}
|
||||
else
|
||||
ban(c);
|
||||
}
|
||||
if(!sel || !isvisible(sel))
|
||||
focus(getnext(clients));
|
||||
restack();
|
||||
}
|
||||
|
||||
void
|
||||
dotile(Arg *arg)
|
||||
{
|
||||
int h, i, n, w;
|
||||
Client *c;
|
||||
|
||||
maximized = False;
|
||||
|
||||
w = sw - mw;
|
||||
for(n = 0, c = clients; c; c = c->next)
|
||||
if(isvisible(c) && !c->isfloat)
|
||||
n++;
|
||||
|
||||
if(n > 1)
|
||||
h = (sh - bh) / (n - 1);
|
||||
else
|
||||
h = sh - bh;
|
||||
|
||||
for(i = 0, c = clients; c; c = c->next) {
|
||||
if(isvisible(c)) {
|
||||
if(c->isfloat) {
|
||||
resize(c, True, TopLeft);
|
||||
continue;
|
||||
}
|
||||
if(n == 1) {
|
||||
c->x = sx;
|
||||
c->y = sy + bh;
|
||||
c->w = sw - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
else if(i == 0) {
|
||||
c->x = sx;
|
||||
c->y = sy + bh;
|
||||
c->w = mw - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
else if(h > bh) {
|
||||
c->x = sx + mw;
|
||||
c->y = sy + (i - 1) * h + bh;
|
||||
c->w = w - 2;
|
||||
if(i + 1 == n)
|
||||
c->h = sh - c->y - 2;
|
||||
else
|
||||
c->h = h - 2;
|
||||
}
|
||||
else { /* fallback if h < bh */
|
||||
c->x = sx + mw;
|
||||
c->y = sy + bh;
|
||||
c->w = w - 2;
|
||||
c->h = sh - 2 - bh;
|
||||
}
|
||||
resize(c, False, TopLeft);
|
||||
i++;
|
||||
}
|
||||
else
|
||||
ban(c);
|
||||
}
|
||||
if(!sel || !isvisible(sel))
|
||||
focus(getnext(clients));
|
||||
restack();
|
||||
}
|
||||
|
||||
void
|
||||
focusnext(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
if(!(c = getnext(sel->next)))
|
||||
c = getnext(clients);
|
||||
if(c) {
|
||||
focus(c);
|
||||
restack();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
focusprev(Arg *arg)
|
||||
{
|
||||
Client *c;
|
||||
|
||||
if(!sel)
|
||||
return;
|
||||
|
||||
if(!(c = getprev(sel->prev))) {
|
||||
for(c = clients; c && c->next; c = c->next);
|
||||
c = getprev(c);
|
||||
}
|
||||
if(c) {
|
||||
focus(c);
|
||||
restack();
|
||||
}
|
||||
}
|
||||
|
||||
Bool
|
||||
isvisible(Client *c)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i = 0; i < ntags; i++)
|
||||
if(c->tags[i] && seltag[i])
|
||||
return True;
|
||||
return False;
|
||||
}
|
||||
|
||||
void
|
||||
resizecol(Arg *arg)
|
||||
{
|
||||
unsigned int n;
|
||||
Client *c;
|
||||
|
||||
for(n = 0, c = clients; c; c = c->next)
|
||||
if(isvisible(c) && !c->isfloat)
|
||||
n++;
|
||||
if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
||||
return;
|
||||
|
||||
if(sel == getnext(clients)) {
|
||||
if(mw + arg->i > sw - 100 || mw + arg->i < 100)
|
||||
return;
|
||||
mw += arg->i;
|
||||
}
|
||||
else {
|
||||
if(mw - arg->i > sw - 100 || mw - arg->i < 100)
|
||||
return;
|
||||
mw -= arg->i;
|
||||
}
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
restack()
|
||||
{
|
||||
Client *c;
|
||||
XEvent ev;
|
||||
|
||||
if(!sel) {
|
||||
drawstatus();
|
||||
return;
|
||||
}
|
||||
if(sel->isfloat || arrange == dofloat) {
|
||||
XRaiseWindow(dpy, sel->win);
|
||||
XRaiseWindow(dpy, sel->twin);
|
||||
}
|
||||
if(arrange != dofloat)
|
||||
for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
|
||||
XLowerWindow(dpy, c->twin);
|
||||
XLowerWindow(dpy, c->win);
|
||||
}
|
||||
drawall();
|
||||
XSync(dpy, False);
|
||||
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
|
||||
}
|
||||
|
||||
void
|
||||
togglemode(Arg *arg)
|
||||
{
|
||||
arrange = (arrange == dofloat) ? dotile : dofloat;
|
||||
if(sel)
|
||||
arrange(NULL);
|
||||
else
|
||||
drawstatus();
|
||||
}
|
||||
|
||||
void
|
||||
toggleview(Arg *arg)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
seltag[arg->i] = !seltag[arg->i];
|
||||
for(i = 0; i < ntags && !seltag[i]; i++);
|
||||
if(i == ntags)
|
||||
seltag[arg->i] = True; /* cannot toggle last view */
|
||||
reorder();
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
view(Arg *arg)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i = 0; i < ntags; i++)
|
||||
seltag[i] = False;
|
||||
seltag[arg->i] = True;
|
||||
reorder();
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
viewall(Arg *arg)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for(i = 0; i < ntags; i++)
|
||||
seltag[i] = True;
|
||||
reorder();
|
||||
arrange(NULL);
|
||||
}
|
||||
|
||||
void
|
||||
zoom(Arg *arg)
|
||||
{
|
||||
unsigned int n;
|
||||
Client *c;
|
||||
|
||||
for(n = 0, c = clients; c; c = c->next)
|
||||
if(isvisible(c) && !c->isfloat)
|
||||
n++;
|
||||
if(!sel || sel->isfloat || n < 2 || (arrange != dotile) || maximized)
|
||||
return;
|
||||
|
||||
if((c = sel) == nexttiled(clients))
|
||||
if(!(c = nexttiled(c->next)))
|
||||
return;
|
||||
detach(c);
|
||||
c->next = clients;
|
||||
clients->prev = c;
|
||||
clients = c;
|
||||
focus(c);
|
||||
arrange(NULL);
|
||||
}
|
Reference in New Issue
Block a user