Compare commits

...

178 Commits
1.0 ... 1.8

Author SHA1 Message Date
69408d384d simplified dotile(), removed misleading line 2006-10-05 13:47:30 +02:00
4aea423f06 final fix for man page 2006-10-05 13:44:48 +02:00
6fc8a63041 keep master ratio on resizecol -> arrange 2006-10-05 12:59:35 +02:00
2583a7c0d1 yet another simplification of dotile() 2006-10-05 12:18:04 +02:00
0ef6e3103c simplified dotile() 2006-10-05 12:13:24 +02:00
7c052b37c8 applied resizecol fix by Jukka 2006-10-05 11:00:55 +02:00
d9c475d7f4 Button3 click on mode label toggles stack position now 2006-10-05 09:37:11 +02:00
c8e57332d1 applied dave's highlight patch for big fonts 2006-09-29 19:06:27 +02:00
c045459917 using ff tiled again, seems to work perfectly with new bottom stack 2006-09-29 18:40:32 +02:00
e0f64e63db applied ality's hardcode-0 patches 2006-09-29 18:21:02 +02:00
dddd58a8cd added symbols for different modes 2006-09-29 18:08:20 +02:00
010fd21b20 removed useless updatemaster 2006-09-29 17:25:49 +02:00
1802fad2f9 documented the new behavior in man page 2006-09-29 17:20:05 +02:00
f833d109d1 fixed small offset issue 2006-09-29 17:15:05 +02:00
7225c99903 fixed the z-layer issue described on mailinglist 2006-09-29 17:12:57 +02:00
36178933ed removed the direction flipping 2006-09-29 17:02:56 +02:00
ad0da9a571 small fix of a corner case 2006-09-29 16:54:15 +02:00
6646468125 small change 2006-09-29 16:44:02 +02:00
fee8df6ccf added the new dotile as described on ml 2006-09-29 16:22:20 +02:00
8fa47ac679 prelim of dotile() 2006-09-29 14:39:03 +02:00
b427a2c6cb I changed sanders patch to fix the ff issue to be simplier, though it needs testing if this really fixes the issue 2006-09-29 12:56:01 +02:00
14d05e7c72 first step to a more flexible dotile() algorithm 2006-09-29 12:38:27 +02:00
a118a57fe3 renamed column into area 2006-09-28 21:29:20 +02:00
02cea3b47e small change to README 2006-09-28 16:14:48 +02:00
1c2d673ded applied Jukkas patch 2006-09-28 14:03:39 +02:00
c34df2c1b6 Added tag 1.7.1 for changeset d5ad819f2a66a40fa75dd2e44429f3bfc884d07b 2006-09-27 17:21:25 +02:00
6092aa977e fixing the settags issue, preparing 1.7.1 2006-09-27 17:18:46 +02:00
c9cc2b385a removed an unused var 2006-09-26 17:42:14 +02:00
b39d0c521a Added tag 1.7 for changeset 4dbdb61c8b8ce21dee5c7050a6b103855964ed20 2006-09-26 17:39:30 +02:00
e87bed6df2 updated README 2006-09-26 14:32:02 +02:00
4ee05b3294 small change 2006-09-26 14:08:42 +02:00
e81eb46a78 added slight error check to getcolor 2006-09-26 13:49:16 +02:00
f315832f75 small fix 2006-09-26 13:30:30 +02:00
97ced11e53 changed order of colordefs in config.h's, changed config.arg.h to fit to new dmenu 2006-09-26 13:24:14 +02:00
4d6c4d36ce removed useless debug info 2006-09-26 08:17:35 +02:00
b4d53bf194 added configure(), but this doesn't really fix those frking broken SDL apps 2006-09-26 07:40:19 +02:00
67bc08d1b9 slight change of event handling order 2006-09-25 21:28:00 +02:00
bcb07de750 simplified mouse resizals 2006-09-25 21:19:18 +02:00
7d7cde0fd6 applied sanders jukka patch 2006-09-25 20:38:30 +02:00
6b25d06d7d applied Jukkas patch 2006-09-25 08:21:51 +02:00
cff951c650 removed all dotile checks 2006-09-22 18:48:35 +02:00
114cc3ec02 applied Jukkas remark (dunno if this is correct though) 2006-09-22 16:35:49 +02:00
3c4b7672a8 applied jukkas patch 2006-09-22 15:39:38 +02:00
6de149eb22 man page fix 2006-09-22 14:02:41 +02:00
da909dd1e8 ismax toggling on mouse based action 2006-09-22 14:00:54 +02:00
67986e81ee hotfix 2006-09-22 13:58:21 +02:00
346bdea946 small change to achieve Jukka's last proposal 2006-09-22 13:53:28 +02:00
05c10c5776 fixed issue pointed out by Jukka 2006-09-22 11:49:24 +02:00
b2cb925d99 patched resizemouse according to sanders remark 2006-09-22 11:24:01 +02:00
9fb6502b3b small man page fix 2006-09-22 10:01:51 +02:00
9eb226ff78 sander check this 2006-09-22 09:43:21 +02:00
e34c4eaf61 slight change to config.arg.h (I use ff floating) 2006-09-22 08:22:39 +02:00
9e75bcfc75 updated man page 2006-09-22 08:17:42 +02:00
d800ec05ff implemented the maximization as I described on the mailinglist, this feels better to me. 2006-09-22 07:37:56 +02:00
bda53ac6ad reviewed client.c 2006-09-20 09:53:21 +02:00
4230932563 reviewed util.c 2006-09-20 09:49:32 +02:00
f17e898bd1 fixed a nuance in dwm.1 2006-09-20 09:45:39 +02:00
886b2088f1 improved intro comment in dwm.h, updated config.mk 2006-09-20 09:40:35 +02:00
551d6bb23d some simplifications to intro in dwm.h 2006-09-19 16:13:44 +02:00
d504005e91 Added tag 1.6 for changeset ad3fa2d185426c51fd5deceae809770363f8d33c 2006-09-16 11:21:01 +02:00
2511b5c675 added visibility check to enternotify as well 2006-09-15 14:21:25 +02:00
28aba061ec offscreen client appearance fixes 2006-09-15 10:54:32 +02:00
8e37c78ce3 focus() enforces visibility of a client if not NULL 2006-09-15 10:49:05 +02:00
ca68975ff8 removed useless inclusion 2006-09-14 11:07:44 +02:00
529be52fea fixed executing of dmenu output to handle args correctly 2006-09-12 19:09:04 +02:00
ca65478c89 removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined) 2006-09-12 10:57:28 +02:00
a1e9362d38 some more simplifications of intro comment in dwm.h, this should suffice for comments in dwm 2006-09-12 09:50:06 +02:00
cbfc69e310 made introduction comment in dwm.h shorter 2006-09-12 09:46:19 +02:00
1d7674bb22 applied Christof Musik's multihead patch for a pathologic cornercase 2006-09-12 08:27:11 +02:00
e6cc22396a added a general comment to dwm.h how dwm is basically organized 2006-09-12 08:14:22 +02:00
868159fd0a some other simplifications 2006-09-11 17:31:21 +02:00
b597fa4637 fixed some other comments, now also the code side seems to be at a level to be reviewed by experienced programmers 2006-09-11 11:28:28 +02:00
d2d394eccf small change to comments, renamed two set* functions in client.c into update* 2006-09-11 10:00:56 +02:00
438beeabde small fix 2006-09-11 08:58:58 +02:00
281f0981a6 added some comments 2006-09-11 07:40:41 +02:00
6ff346bed9 Added tag 1.5 for changeset 728c9089b079721b43c3347124639a29baa22a97 2006-09-08 08:32:08 +02:00
0925dd588c applied sanders patch of not manipulating sel 2006-09-08 08:19:54 +02:00
6f20315dff really small changes to dwm.1 2006-09-08 07:40:16 +02:00
2e68f22118 hotfix 2006-09-07 18:13:19 +02:00
8aa860d270 simplified unmanage 2006-09-07 18:12:40 +02:00
15abade272 using a global stack for focus recovery on arrange() - seems to work great 2006-09-07 17:53:40 +02:00
7ab8c87281 made markups in dwm.1 more consistent 2006-09-07 09:26:01 +02:00
4ff8f71643 small addition to dwm.1 2006-09-07 07:53:29 +02:00
d22abeee86 this patch keeps track of global z-layer order of clients which are floating or if floating mode is enabled 2006-09-06 17:31:52 +02:00
a33150eb4b no this is better 2006-09-06 15:36:42 +02:00
fd00b3a186 does this preserve z order for anthony? 2006-09-06 15:30:28 +02:00
e8389a4cc0 maybe this might work 2006-09-06 13:56:46 +02:00
6078d756bc Added tag 1.4 for changeset 3cff9403766bf83a9fc2a0aef230115d68de2a8e 2006-09-06 12:19:07 +02:00
57c49fe867 prepared dwm-1.4 update 2006-09-06 12:18:57 +02:00
c60de1acd4 drawstatus even if no client exists 2006-09-06 12:10:43 +02:00
69b738c097 sanders solution is convincing and elegant 2006-09-06 11:54:16 +02:00
da0b2a2f31 seems to preserve floating client z-layer order (even with reorder() calls) 2006-09-06 11:46:35 +02:00
2378a558a2 Added tag 1.4 for changeset a6b8994af16491220db0199623bd57d061e06143 2006-09-06 10:54:10 +02:00
f18ed615ae small fix 2006-09-06 10:03:21 +02:00
f6656fffb4 made args mode symbols the default ones (the default ones look too ugly) 2006-09-06 09:23:34 +02:00
aaad7bfd15 moved transient_for tag inheritance to settags 2006-09-06 09:21:17 +02:00
0915da8842 no, reodering floating clients definately breaks the manage() policy which attaches all clients zoomed (otherwise higher-weight clients couldn't be attached zoomed, which sucks) 2006-09-06 09:13:31 +02:00
0d0e8bde13 no, ordering floating clients at the end seems better 2006-09-05 19:26:34 +02:00
838a1ff950 fix 2006-09-05 18:43:15 +02:00
e1315fd40c this makes sure the issue mentioned by sander 2006-09-05 18:04:22 +02:00
52a3ab1042 fixing zoom 2006-09-05 17:10:48 +02:00
a82e7b765e fixing two off-by-ones 2006-09-05 16:11:52 +02:00
0ed0fa4d5b ach ich will auch Alt-s 2006-09-05 16:05:09 +02:00
ec85fddb9a applied checking existance of >2 tiles patch (proposed by sander) to zoom and resizecol 2006-09-05 16:00:09 +02:00
3a1343a245 renamed resizetile into resizecol 2006-09-05 13:52:23 +02:00
9066ee2eb4 well ok, added Mod-s to default bindings (however, I don't need it) 2006-09-05 13:27:43 +02:00
40bd21ce63 s/growcol/resizetile/g 2006-09-05 13:25:42 +02:00
4633fbec61 right, multihead issue is not involved with growcol 2006-09-05 13:21:59 +02:00
25060031a5 hotfix 2006-09-05 13:20:29 +02:00
c7ae6334b7 applied a fix related to Sanders remark to growcol 2006-09-05 13:19:18 +02:00
eac04882b4 sanders toggletag patch is much more elegant 2006-09-05 09:37:45 +02:00
6499fc4f93 I really need column growing, now pushing upstream 2006-09-05 09:02:37 +02:00
04f27a5438 don't access sel in restack without checking for NULL (multihead crashing bug) 2006-09-05 08:37:34 +02:00
1b3903d6e9 fixing c->weight handling 2006-09-05 08:24:00 +02:00
cc05093b0d removed some useless tags 2006-09-04 19:19:37 +02:00
6436dd4438 after 1.3 2006-09-04 17:52:46 +02:00
26c50c780e Added tag 1.3 for changeset f5f5cbf016a94b48a8fe9c47f0736e96d166d5d4 2006-09-04 17:52:16 +02:00
01d13b0c49 retagged 2006-09-04 17:52:12 +02:00
f15f45a9f8 simplified manage 2006-09-04 17:39:33 +02:00
1b2e149cb4 removed html crap 2006-09-04 17:37:31 +02:00
6136640ec9 Added tag 1.3 for changeset dd44dc937e8b0a46abf1a15a333dba5304e4fe89 2006-09-04 17:21:18 +02:00
95d8423823 hotfixing with sanders hint 2006-09-04 17:21:15 +02:00
de6411c338 Added tag 1.3 for changeset 6413ea66b1c2496cfc2173fe58df67cb965eb1da 2006-09-04 17:18:01 +02:00
e316cf53f6 fixing the issue that new clients appear lowered 2006-09-04 17:02:13 +02:00
c107db57db removed unused vars 2006-09-04 12:23:41 +02:00
d39d00057c reducing focus calls (sanders patch) 2006-09-04 10:10:08 +02:00
26157e6973 applied Sanders max_and_focus.patch 2006-09-04 08:55:49 +02:00
6d22782e8f simplified buttonpress 2006-09-01 15:31:59 +02:00
1836b6740d applied sanders patch 2006-09-01 10:32:50 +02:00
924a088812 reorder was misssing in Ross version of viewall 2006-08-31 18:08:28 +02:00
bab575c868 changed shortcut into Mod1-0 2006-08-31 18:04:34 +02:00
daae3bba50 added viewall to mainstream (only Ross Mohns version, not the toggle) 2006-08-31 18:02:38 +02:00
05fbbbd8dc implemented Button2 press on tags for toggletag on the focused client 2006-08-31 17:49:04 +02:00
4c368bcd24 applied sanders patch to remove unnecessary commit() 2006-08-31 08:48:04 +02:00
9927b9e642 small fix in config.arg.h 2006-08-30 13:00:30 +02:00
1b492dffc8 Added tag 1.2 for changeset e3179ce2b90451d2807cd53b589d768412b8666b 2006-08-30 12:39:35 +02:00
140be1b4b3 prepared 1.2 2006-08-30 12:39:27 +02:00
79259acc12 now using Salmi's menu command 2006-08-30 11:21:56 +02:00
5a3bea2d69 removed a warning reported by Jukka 2006-08-30 11:15:58 +02:00
30d928591d simplified configurerequest 2006-08-29 19:24:28 +02:00
70a3e62257 now dwm enforces max screen size also in tiled mode on non-floating clients which are maximized 2006-08-29 18:05:02 +02:00
6828fba7a0 fixed 2006-08-29 17:33:27 +02:00
aa1bda8164 configurenotify remembers max geom now, and restores this if necessary, however it accepts to touch the max size on configurerequest, this shouldn't break fillscreen apps (tested with mplayer) 2006-08-29 17:31:55 +02:00
157ea539a2 applied patch similiar proposed by dave tweed 2006-08-29 17:11:37 +02:00
c3c94c0e0a improved selection policy 2006-08-29 15:28:29 +02:00
9d73909075 still something wrong with reorder() 2006-08-29 13:40:09 +02:00
016c54196e this algorithm seems to keep order for any scenario 2006-08-29 09:57:57 +02:00
5056bb952d fix client position in list also on tag and toggletag 2006-08-29 09:25:14 +02:00
8a6679b3b4 added attach/detach functions which don't attach at the begin of list, but at the slot of a first match of the tags of a client 2006-08-29 09:23:44 +02:00
7b6d5ff298 removed crappy variables 2006-08-28 14:32:51 +02:00
846850914d changed config.arg.h - I really need the 4th tag 2006-08-28 12:27:00 +02:00
4e6c513ac2 updated html page 2006-08-28 10:21:40 +02:00
db9cda6a7d Added tag 1.1 for changeset 44a55e6e46bf6c231780b09d919977d6f01083de 2006-08-28 10:19:55 +02:00
a50b15a9e9 added a comment to spawn 2006-08-28 08:17:27 +02:00
0a25fe9188 applied sanders focus_ patches 2006-08-28 08:06:50 +02:00
2dd5212a79 applied sanders somepatches.patch 2006-08-28 08:02:29 +02:00
00e95e1f38 oh frking dear big font... 2006-08-25 18:14:55 +02:00
0a0759132c term enlightened 2006-08-25 18:05:18 +02:00
5cf362c7d0 switching to darker colorscheme with larger font 2006-08-25 18:03:56 +02:00
413be1112a patched arg.h 2006-08-25 17:42:58 +02:00
8233dc8568 new stuff 2006-08-25 17:34:03 +02:00
afa8b3bcd9 switching to dark colors again 2006-08-25 17:31:57 +02:00
c518345f40 updated man page of dwm 2006-08-25 16:21:45 +02:00
afe6ac9923 changed order of options 2006-08-25 16:15:13 +02:00
e995c1b532 trying a different configuration 2006-08-25 15:48:44 +02:00
e36929292e removed small 1px gap, somehow without it things feel better 2006-08-25 15:37:00 +02:00
03128f78df oops 2006-08-25 15:24:18 +02:00
7d4a5e654c fixed typo 2006-08-25 15:21:49 +02:00
41ba7a7984 s/TILED/TILE/g 2006-08-25 15:16:20 +02:00
aa471f2d65 removed a bunch of lines, made mode symbols configurable 2006-08-25 15:12:32 +02:00
d37dfa1bed changed symbols for float/tiled mode, added mouse-driven mode toggle to buttonpress() 2006-08-25 15:06:38 +02:00
9f35cc52fe small fix to separate client title from right-most tag 2006-08-25 14:46:01 +02:00
f1fe19bc2b restored config.arg.h 2006-08-25 13:02:07 +02:00
b55bd709ee new color stuff/new rendering stuff 2006-08-25 12:59:45 +02:00
9833610356 back to 3 colors 2006-08-25 07:54:49 +02:00
de7fc0011e fixed 2006-08-24 12:07:10 +02:00
2e0c767d74 3->4 colors 2006-08-24 12:04:56 +02:00
a5379e901c Added tag 1.0 for changeset bbc98e77ae89a7c9232a5be0835f60ea00d8036e 2006-08-24 10:28:50 +02:00
16 changed files with 774 additions and 767 deletions

View File

@ -7,3 +7,12 @@ c11f86db4550cac5d0a648a3fe4d6d3b9a4fcf7e 0.6
3fb41412e2492f66476d92ce8f007a8b48fb1d2a 0.7
cd15de32e173f8ce97bfe1c9b6607937b59056b4 0.8
fae61afa861755636c4a1070694209ace8efbb6c 0.9
bbc98e77ae89a7c9232a5be0835f60ea00d8036e 1.0
44a55e6e46bf6c231780b09d919977d6f01083de 1.1
e3179ce2b90451d2807cd53b589d768412b8666b 1.2
f5f5cbf016a94b48a8fe9c47f0736e96d166d5d4 1.3
3cff9403766bf83a9fc2a0aef230115d68de2a8e 1.4
728c9089b079721b43c3347124639a29baa22a97 1.5
ad3fa2d185426c51fd5deceae809770363f8d33c 1.6
4dbdb61c8b8ce21dee5c7050a6b103855964ed20 1.7
d5ad819f2a66a40fa75dd2e44429f3bfc884d07b 1.7.1

4
README
View File

@ -1,5 +1,5 @@
dwm - dynamic window manager
----------------------------
============================
dwm is an extremely fast, small, and dynamic window manager for X.
@ -37,7 +37,7 @@ like this in your .xinitrc:
while true
do
echo `date` `uptime | sed 's/.*://; s/,//g'`
echo `date` `uptime | sed 's/.*,//'`
sleep 1
done | dwm

275
client.c
View File

@ -11,83 +11,109 @@
/* static functions */
static void
grabbutton(Client *c, unsigned int button, unsigned int modifier)
{
XGrabButton(dpy, button, modifier, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, button, modifier | LockMask, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, button, modifier | numlockmask, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, button, modifier | numlockmask | LockMask, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
detachstack(Client *c) {
Client **tc;
for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
*tc = c->snext;
}
static void
resizetitle(Client *c)
{
int i;
grabbuttons(Client *c, Bool focused) {
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
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(isvisible(c))
XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th);
if(focused) {
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
XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th);
}
static void
ungrabbutton(Client *c, unsigned int button, unsigned int modifier)
{
XUngrabButton(dpy, button, modifier, c->win);
XUngrabButton(dpy, button, modifier | LockMask, c->win);
XUngrabButton(dpy, button, modifier | numlockmask, c->win);
XUngrabButton(dpy, button, modifier | numlockmask | LockMask, c->win);
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
GrabModeAsync, GrabModeSync, None, None);
}
static int
xerrordummy(Display *dsply, XErrorEvent *ee)
{
xerrordummy(Display *dsply, XErrorEvent *ee) {
return 0;
}
/* extern functions */
void
ban(Client *c)
{
ban(Client *c) {
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty);
}
void
focus(Client *c)
{
Client *old = sel;
configure(Client *c) {
XEvent synev;
if(!issel)
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;
XSendEvent(dpy, c->win, True, NoEventMask, &synev);
}
void
focus(Client *c) {
Client *old;
if(!issel || (c && !isvisible(c)))
return;
if(!sel)
sel = c;
else if(sel != c) {
if(sel->ismax)
togglemax(NULL);
old = sel;
sel = c;
grabbutton(old, AnyButton, 0);
drawtitle(old);
if(old) {
grabbuttons(old, False);
drawtitle(old);
}
}
ungrabbutton(c, AnyButton, 0);
drawtitle(c);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
if(c) {
detachstack(c);
c->snext = stack;
stack = c;
grabbuttons(c, True);
drawtitle(c);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
}
else
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
}
Client *
getclient(Window w)
{
getclient(Window w) {
Client *c;
for(c = clients; c; c = c->next)
@ -97,8 +123,7 @@ getclient(Window w)
}
Client *
getctitle(Window w)
{
getctitle(Window w) {
Client *c;
for(c = clients; c; c = c->next)
@ -108,8 +133,7 @@ getctitle(Window w)
}
void
gravitate(Client *c, Bool invert)
{
gravitate(Client *c, Bool invert) {
int dx = 0, dy = 0;
switch(c->grav) {
@ -163,8 +187,7 @@ gravitate(Client *c, Bool invert)
}
void
killclient(Arg *arg)
{
killclient(Arg *arg) {
if(!sel)
return;
if(sel->proto & PROTODELWIN)
@ -174,10 +197,8 @@ killclient(Arg *arg)
}
void
manage(Window w, XWindowAttributes *wa)
{
unsigned int i;
Client *c, *tc;
manage(Window w, XWindowAttributes *wa) {
Client *c;
Window trans;
XSetWindowAttributes twa;
@ -191,14 +212,14 @@ manage(Window w, XWindowAttributes *wa)
c->th = bh;
c->border = 0;
setsize(c);
updatesize(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->x + c->w + 2 * BORDERPX > sw)
c->x = sw - c->w - 2 * BORDERPX;
if(c->x < sx)
c->x = sx;
if(c->y + c->h + 2 * BORDERPX > sh)
c->y = sh - c->h - 2 * BORDERPX;
if(c->h != sh && c->y < bh)
c->y = bh;
@ -215,37 +236,31 @@ manage(Window w, XWindowAttributes *wa)
DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
if(clients)
clients->prev = c;
c->next = clients;
clients = c;
grabbutton(c, Button1, MODKEY);
grabbutton(c, Button2, MODKEY);
grabbutton(c, Button3, MODKEY);
if((tc = getclient(trans))) /* inherit tags */
for(i = 0; i < ntags; i++)
c->tags[i] = tc->tags[i];
else
settags(c);
grabbuttons(c, False);
updatetitle(c);
settags(c, getclient(trans));
if(!c->isfloat)
c->isfloat = trans
|| (c->maxw && c->minw &&
c->maxw == c->minw && c->maxh == c->minh);
settitle(c);
if(isvisible(c))
sel = c;
arrange(NULL);
resizetitle(c);
if(clients)
clients->prev = c;
c->next = clients;
c->snext = stack;
stack = clients = c;
ban(c);
XMapWindow(dpy, c->win);
XMapWindow(dpy, c->twin);
if(isvisible(c))
focus(c);
arrange(NULL);
}
void
resize(Client *c, Bool sizehints, Corner sticky)
{
resize(Client *c, Bool sizehints, Corner sticky) {
int bottom = c->y + c->h;
int right = c->x + c->w;
XWindowChanges wc;
@ -269,6 +284,16 @@ resize(Client *c, Bool sizehints, Corner sticky)
if(sticky == BotLeft || sticky == BotRight)
c->y = bottom - c->h;
/* offscreen appearance fixes */
if(c->x + c->w < sx)
c->x = sx;
if(c->y + c->h < bh)
c->y = bh;
if(c->x > sw)
c->x = sw - c->w;
if(c->y > sh)
c->y = sh - c->h;
resizetitle(c);
wc.x = c->x;
wc.y = c->y;
@ -277,14 +302,27 @@ resize(Client *c, Bool sizehints, Corner sticky)
if(c->w == sw && c->h == sh)
wc.border_width = 0;
else
wc.border_width = 1;
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
wc.border_width = BORDERPX;
XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
}
void
setsize(Client *c)
{
resizetitle(Client *c) {
c->tw = textw(c->name);
if(c->tw > c->w)
c->tw = c->w + 2 * BORDERPX;
c->tx = c->x + c->w - c->tw + 2 * BORDERPX;
c->ty = c->y;
if(isvisible(c))
XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th);
else
XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th);
}
void
updatesize(Client *c) {
long msize;
XSizeHints size;
@ -322,10 +360,9 @@ setsize(Client *c)
}
void
settitle(Client *c)
{
updatetitle(Client *c) {
char **list = NULL;
int i, n;
int n;
XTextProperty name;
name.nitems = 0;
@ -346,65 +383,31 @@ settitle(Client *c)
}
}
XFree(name.value);
resizetitle(c);
}
void
togglemax(Arg *arg)
{
int ox, oy, ow, oh;
XEvent ev;
unmanage(Client *c) {
Client *nc;
if(!sel)
return;
if((sel->ismax = !sel->ismax)) {
ox = sel->x;
oy = sel->y;
ow = sel->w;
oh = sel->h;
sel->x = sx;
sel->y = sy + bh;
sel->w = sw - 2;
sel->h = sh - 2 - bh;
restack();
resize(sel, arrange == dofloat, TopLeft);
sel->x = ox;
sel->y = oy;
sel->w = ow;
sel->h = oh;
}
else
resize(sel, False, TopLeft);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void
unmanage(Client *c)
{
/* The server grab construct avoids race conditions. */
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
detach(c);
detachstack(c);
if(sel == c) {
for(nc = stack; nc && !isvisible(nc); nc = nc->snext);
focus(nc);
}
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
XDestroyWindow(dpy, c->twin);
if(c->prev)
c->prev->next = c->next;
if(c->next)
c->next->prev = c->prev;
if(c == clients)
clients = c->next;
if(sel == c)
sel = getnext(clients);
free(c->tags);
free(c);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
if(sel)
focus(sel);
arrange(NULL);
}

View File

@ -4,49 +4,67 @@
*/
#define TAGS \
const char *tags[] = { "work", "net", "fnord", NULL };
const char *tags[] = { "dev", "work", "net", "fnord", NULL };
#define DEFMODE dotile /* dofloat */
#define FLOATSYMBOL "><>"
#define STACKPOS StackRight /* StackLeft */
#define BSTACKSYMBOL "==="
#define VSTACKSYMBOL "[]="
#define DEFMODE dotile /* dofloat */
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
#define BGCOLOR "#666699"
#define FGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC"
#define NORMBGCOLOR "#333333"
#define NORMFGCOLOR "#dddddd"
#define SELBGCOLOR "#333366"
#define SELFGCOLOR "#eeeeee"
#define STATUSBGCOLOR "#222222"
#define STATUSFGCOLOR "#9999cc"
#define MASTER 60 /* percent */
#define MODKEY Mod1Mask
#define MASTERW 60 /* percent */
#define KEYS \
static Key key[] = { \
/* modifier key function arguments */ \
{ MODKEY|ShiftMask, XK_Return, spawn, \
{ .cmd = "exec uxterm -bg '#e0e0e0' -fg '#000000' -cr '#000000' +sb -fn '"FONT"'" } }, \
{ .cmd = "exec uxterm -bg '#111111' -fg '#eeeeee' -cr '#eeeeee' +sb -fn '"FONT"'" } }, \
{ MODKEY, XK_p, spawn, \
{ .cmd = "exec `ls -lL /usr/bin /usr/X11R6/bin /usr/local/bin 2>/dev/null | " \
"awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort -u | dmenu`" } }, \
{ .cmd = "exe=\"$(IFS=:; for dir in $PATH; do " \
"for file in \"$dir\"/*; do [ -x \"$file\" ] && echo \"${file##*/}\"; done; done " \
"| sort -u | dmenu -font '"FONT"' -normbg '"NORMBGCOLOR"' -normfg '"NORMFGCOLOR"' " \
"-selbg '"SELBGCOLOR"' -selfg '"SELFGCOLOR"')\" && exec $exe" } }, \
{ MODKEY, XK_j, focusnext, { 0 } }, \
{ MODKEY, XK_k, focusprev, { 0 } }, \
{ MODKEY, XK_Return, zoom, { 0 } }, \
{ MODKEY, XK_m, togglemax, { 0 } }, \
{ MODKEY, XK_b, togglestackpos, { 0 } }, \
{ MODKEY, XK_g, resizecol, { .i = 1 } }, \
{ MODKEY, XK_s, resizecol, { .i = -1 } }, \
{ 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:title regex tags regex isfloat */ \
{ "Firefox.*", "net", False }, \
{ "Firefox.*", "net", False}, \
{ "Gimp.*", NULL, True}, \
{ "MPlayer.*", NULL, True}, \
{ "Acroread.*", NULL, True}, \

View File

@ -7,12 +7,21 @@
const char *tags[] = { "1", "2", "3", "4", "5", NULL };
#define DEFMODE dotile /* dofloat */
#define FLOATSYMBOL "><>"
#define STACKPOS StackRight /* StackLeft */
#define BSTACKSYMBOL "==="
#define VSTACKSYMBOL "[]="
#define FONT "fixed"
#define BGCOLOR "#666699"
#define FGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC"
#define NORMBGCOLOR "#333366"
#define NORMFGCOLOR "#cccccc"
#define SELBGCOLOR "#666699"
#define SELFGCOLOR "#eeeeee"
#define STATUSBGCOLOR "#dddddd"
#define STATUSFGCOLOR "#222222"
#define MASTER 60 /* percent */
#define MODKEY Mod1Mask
#define MASTERW 60 /* percent */
#define KEYS \
static Key key[] = { \
@ -21,7 +30,9 @@ static Key key[] = { \
{ MODKEY, XK_Tab, focusnext, { 0 } }, \
{ MODKEY|ShiftMask, XK_Tab, focusprev, { 0 } }, \
{ MODKEY, XK_Return, zoom, { 0 } }, \
{ MODKEY, XK_m, togglemax, { 0 } }, \
{ MODKEY, XK_b, togglestackpos, { 0 } }, \
{ MODKEY, XK_g, resizecol, { .i = 1 } }, \
{ MODKEY, XK_s, resizecol, { .i = -1 } }, \
{ MODKEY|ShiftMask, XK_1, tag, { .i = 0 } }, \
{ MODKEY|ShiftMask, XK_2, tag, { .i = 1 } }, \
{ MODKEY|ShiftMask, XK_3, tag, { .i = 2 } }, \
@ -34,6 +45,7 @@ static Key key[] = { \
{ 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 } }, \
@ -48,7 +60,7 @@ static Key key[] = { \
};
/* 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) }' */
* xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/ { printf("%s\n",$2) }' */
#define RULES \
static Rule rule[] = { \
/* class:instance:title regex tags regex isfloat */ \

View File

@ -1,5 +1,5 @@
# dwm version
VERSION = 1.0
VERSION = 1.8
# Customize below to fit your system

100
draw.c
View File

@ -10,8 +10,7 @@
/* static */
static unsigned int
textnw(const char *text, unsigned int len)
{
textnw(const char *text, unsigned int len) {
XRectangle r;
if(dc.font.set) {
@ -22,29 +21,15 @@ textnw(const char *text, unsigned int len)
}
static void
drawtext(const char *text, Bool invert, Bool highlight)
{
drawtext(const char *text, unsigned long col[ColLast], Bool highlight) {
int x, y, w, h;
static char buf[256];
unsigned int len, olen;
XGCValues gcv;
XPoint points[5];
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);
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);
XSetForeground(dpy, dc.gc, dc.border);
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
if(!text)
return;
@ -74,37 +59,28 @@ drawtext(const char *text, Bool invert, Bool highlight)
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);
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);
XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
if(highlight) {
points[0].x = dc.x + 1;
points[0].y = dc.y + 1;
points[1].x = dc.w - 3;
points[1].y = 0;
points[2].x = 0;
points[2].y = dc.h - 3;
points[3].x = -(dc.w - 3);
points[3].y = 0;
points[4].x = 0;
points[4].y = -(dc.h - 3);
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
r.x = dc.x + 2;
r.y = dc.y + 2;
r.width = r.height = (h + 2) / 4;
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
}
}
/* extern */
void
drawall()
{
drawall(void) {
Client *c;
for(c = clients; c; c = getnext(c->next))
@ -113,24 +89,25 @@ drawall()
}
void
drawstatus()
{
drawstatus(void) {
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], seltag[i], sel && sel->tags[i]);
if(seltag[i])
drawtext(tags[i], dc.sel, sel && sel->tags[i]);
else
drawtext(tags[i], !seltag[i], sel && sel->tags[i]);
drawtext(tags[i], dc.norm, sel && sel->tags[i]);
dc.x += dc.w;
}
dc.w = bmw;
drawtext(arrange == dofloat ?
FLOATSYMBOL : stackpos == StackBottom ?
BSTACKSYMBOL : VSTACKSYMBOL, dc.status, False);
x = dc.x + dc.w;
dc.w = textw(stext);
dc.x = bx + bw - dc.w;
@ -138,51 +115,49 @@ drawstatus()
dc.x = x;
dc.w = bw - x;
}
drawtext(stext, !istile, False);
drawtext(stext, dc.status, False);
if(sel && ((dc.w = dc.x - x) > bh)) {
if((dc.w = dc.x - x) > bh) {
dc.x = x;
drawtext(sel->name, istile, False);
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);
}
void
drawtitle(Client *c)
{
int i;
Bool istile = arrange == dotile;
drawtitle(Client *c) {
if(c == sel && issel) {
drawstatus();
XUnmapWindow(dpy, c->twin);
XSetWindowBorder(dpy, c->win, dc.fg);
XSetWindowBorder(dpy, c->win, dc.sel[ColBG]);
return;
}
XSetWindowBorder(dpy, c->win, dc.bg);
XSetWindowBorder(dpy, c->win, dc.norm[ColBG]);
XMapWindow(dpy, c->twin);
dc.x = dc.y = 0;
dc.w = c->tw;
drawtext(c->name, !istile, False);
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);
}
unsigned long
getcolor(const char *colstr)
{
getcolor(const char *colstr) {
Colormap cmap = DefaultColormap(dpy, screen);
XColor color;
XAllocNamedColor(dpy, cmap, colstr, &color, &color);
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
eprint("error, cannot allocate color '%s'\n", colstr);
return color.pixel;
}
void
setfont(const char *fontstr)
{
setfont(const char *fontstr) {
char **missing, *def;
int i, n;
@ -232,7 +207,6 @@ setfont(const char *fontstr)
}
unsigned int
textw(const char *text)
{
textw(const char *text) {
return textnw(text, strlen(text)) + dc.font.height;
}

140
dwm.1
View File

@ -5,28 +5,25 @@ dwm \- dynamic window manager
.B dwm
.RB [ \-v ]
.SH DESCRIPTION
.B dwm
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.
dwm 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
In tiling mode windows are managed in a master and stacking column. The master
column contains the window which currently needs most attention, whereas the
stacking column contains all other windows. In floating mode windows can be
In tiling mode windows are managed in a master and stacking area. The master
area contains the window which currently needs most attention, whereas the
stacking area contains all other windows. In floating mode windows can be
resized and moved freely. Dialog windows are always managed floating,
regardless of the mode selected.
.P
Windows are grouped by tags. Each window can be tagged with one or multiple
tags. Selecting a certain tag for viewing will display all windows with that
tag.
tags. Selecting certain tags displays all windows with these tags.
.P
.B dwm
contains a small status bar which displays all available tags, the title
of the focused window, and the text read from standard input. The tags of the
focused window are highlighted.
dwm 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
selected tags are highlighted with a different color, 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.
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
@ -39,13 +36,18 @@ prints version information to standard output, then exits.
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 a tag label to display all windows with that tag, click on the mode
label toggles between tiling and floating mode.
.TP
.B Button3
click on a tag label adds/removes all windows with that
.B tag
to/from the view.
click on a tag label adds/removes all windows with that tag to/from the view,
click on the mode label toggles the stack position (tiling mode).
.TP
.B Mod1-Button1
click on a tag label applies that tag to the focused window.
.TP
.B Mod1-Button3
click on a tag label adds/removes that tag to/from the focused window.
.SS Keyboard commands
.TP
.B Mod1-Shift-Return
@ -53,98 +55,72 @@ Start
.BR xterm (1).
.TP
.B Mod1-Tab
Focus next
.BR window .
Focus next window.
.TP
.B Mod1-Shift-Tab
Focus previous
.BR window .
Focus previous window.
.TP
.B Mod1-Return
Zoom current
.B window
to the
.B master
column
.RB ( tiling
mode only).
Zooms/cycles current window to/from master area (tiling mode), toggles maximization current window (floating mode).
.TP
.B Mod1-m
Maximize current
.BR window .
.B Mod1-b
Toggle stack position (tiling mode only).
.TP
.B Mod1-Shift-[0..n]
.B Mod1-g
Grow current area (tiling mode only).
.TP
.B Mod1-s
Shrink current area (tiling mode only).
.TP
.B Mod1-Shift-[1..n]
Apply
.B nth tag
to current
.BR window .
.RB nth
tag to current window.
.TP
.B Mod1-Control-Shift-[0..n]
.B Mod1-Control-Shift-[1..n]
Add/remove
.B nth tag
to/from current
.BR window .
.B nth
tag to/from current window.
.TP
.B Mod1-Shift-c
Close focused
.B window.
Close focused window.
.TP
.B Mod1-space
Toggle between
.B tiled
and
.B floating
mode (affects
.BR "all windows" ).
Toggle between tiling and floating mode (affects all windows).
.TP
.B Mod1-[0..n]
.B Mod1-[1..n]
View all windows with
.BR "tag n" .
.BR nth
tag.
.TP
.B Mod1-Control-[0..n]
.B Mod1-0
View all windows with any tag.
.TP
.B Mod1-Control-[1..n]
Add/remove all windows with
.B tag n
to/from the view.
.BR nth
tag to/from the view.
.TP
.B Mod1-Shift-q
Quit
.B dwm.
Quit dwm.
.SS Mouse commands
.TP
.B Mod1-Button1
Move current
.B window
while dragging
.RB ( floating
mode only).
Move current window while dragging (floating mode only).
.TP
.B Mod1-Button2
Zoom current
.B window
to the
.B master
column
.RB ( tiling
mode only).
Zoom current window to the master area (tiling mode only).
.TP
.B Mod1-Button3
Resize current
.B window
while dragging
.RB ( floating
mode only).
Resize current window while dragging (floating mode only).
.SH CUSTOMIZATION
.B dwm
is customized by creating a custom config.h and (re)compiling the source
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 "broken pipe"
when dwm has been started by
.BR xdm (1),
because it closes standard output before executing
.BR dwm .
because it closes standard output before executing dwm.
.SH SEE ALSO
.BR dmenu (1)

188
dwm.h
View File

@ -1,6 +1,35 @@
/*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*
* dynamic window manager is designed like any other X client as well. It is
* driven through handling X events. In contrast to other X clients, a window
* manager selects for SubstructureRedirectMask on the root window, to receive
* events about window (dis-)appearance. Only one X connection at a time is
* allowed to select for this event mask.
*
* Calls to fetch an X event from the event queue are blocking. Due reading
* status text from standard input, a select()-driven main loop has been
* implemented which selects for reads on the X connection and STDIN_FILENO to
* handle all data smoothly. The event handlers of dwm are organized in an
* array which is accessed whenever a new event has been fetched. This allows
* event dispatching in O(1) time.
*
* Each child of the root window is called a client, except windows which have
* set the override_redirect flag. Clients are organized in a global
* doubly-linked client list, the focus history is remembered through a global
* stack list. Each client contains an array of Bools of the same size as the
* global tags array to indicate the tags of a client. For each client dwm
* creates a small title window, which is resized whenever the (_NET_)WM_NAME
* properties are updated or the client is moved/resized.
*
* Keys and tagging rules are organized as arrays and defined in the config.h
* file. These arrays are kept static in event.o and tag.o respectively,
* because no other part of dwm needs access to them. The current mode is
* represented by the arrange() function pointer, which wether points to
* dofloat() or dotile().
*
* To understand everything else, start reading main.c:main().
*/
#include "config.h"
@ -9,22 +38,27 @@
/* mask shorthands, used in event.c and client.c */
#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
/* other stuff used in different places */
#define BORDERPX 1
#define PROTODELWIN 1
enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMLast }; /* default atoms */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColFG, ColBG, ColLast }; /* color */
typedef enum {
StackLeft, StackBottom, StackRight
} StackPos; /* stack position*/
typedef enum {
TopLeft, TopRight, BotLeft, BotRight
} Corner; /* window corners */
typedef union {
const char *cmd;
int i;
} Arg;
/* atoms */
enum { NetSupported, NetWMName, NetLast };
enum { WMProtocols, WMDelete, WMLast };
/* cursor */
enum { CurNormal, CurResize, CurMove, CurLast };
/* window corners */
typedef enum { TopLeft, TopRight, BotLeft, BotRight } Corner;
} Arg; /* argument type */
typedef struct {
int ascent;
@ -34,103 +68,111 @@ typedef struct {
XFontStruct *xfont;
} Fnt;
typedef struct { /* draw context */
typedef struct {
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;
} DC; /* draw context */
typedef struct Client Client;
struct Client {
char name[256];
int proto;
int x, y, w, h;
int tx, ty, tw, th; /* title */
int rx, ry, rw, rh; /* revert geometry */
int tx, ty, tw, th; /* title window geometry */
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int grav;
long flags;
unsigned int border;
Bool isfloat;
Bool ismax;
unsigned int border, weight;
Bool isfloat, ismax;
Bool *tags;
Client *next;
Client *prev;
Client *snext;
Window win;
Window twin;
};
extern const char *tags[];
extern char stext[1024];
extern int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
extern unsigned int ntags, numlockmask;
extern void (*handler[LASTEvent])(XEvent *);
extern void (*arrange)(Arg *);
extern const char *tags[]; /* all tags */
extern char stext[1024]; /* status text */
extern int bx, by, bw, bh, bmw; /* bar geometry, bar mode label width */
extern int screen, sx, sy, sw, sh; /* screen geometry */
extern unsigned int master, ntags, numlockmask; /* master percent, number of tags, dynamic lock mask */
extern void (*handler[LASTEvent])(XEvent *); /* event handler */
extern void (*arrange)(Arg *); /* arrange function, indicates mode */
extern Atom wmatom[WMLast], netatom[NetLast];
extern Bool running, issel, *seltag;
extern Client *clients, *sel;
extern Bool running, issel, *seltag; /* seltag is array of Bool */
extern Client *clients, *sel, *stack; /* global client list and stack */
extern Cursor cursor[CurLast];
extern DC dc;
extern DC dc; /* global draw context */
extern Display *dpy;
extern StackPos stackpos;
extern Window root, barwin;
/* client.c */
extern void ban(Client *c);
extern void focus(Client *c);
extern Client *getclient(Window w);
extern Client *getctitle(Window w);
extern void gravitate(Client *c, Bool invert);
extern void killclient(Arg *arg);
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 ban(Client *c); /* ban c from screen */
extern void configure(Client *c); /* send synthetic configure event */
extern void focus(Client *c); /* focus c, c may be NULL */
extern Client *getclient(Window w); /* return client of w */
extern Client *getctitle(Window w); /* return client of title window */
extern void gravitate(Client *c, Bool invert); /* gravitate c */
extern void killclient(Arg *arg); /* kill c nicely */
extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
extern void resize(Client *c, Bool sizehints, Corner sticky); /* resize c*/
extern void resizetitle(Client *c); /* resizes c->twin correctly */
extern void updatesize(Client *c); /* update the size structs of c */
extern void updatetitle(Client *c); /* update the name of c */
extern void unmanage(Client *c); /* destroy c */
/* draw.c */
extern void drawall();
extern void drawstatus();
extern void drawtitle(Client *c);
extern unsigned long getcolor(const char *colstr);
extern void setfont(const char *fontstr);
extern unsigned int textw(const char *text);
extern void drawall(void); /* draw all visible client titles and the bar */
extern void drawstatus(void); /* draw the bar */
extern void drawtitle(Client *c); /* draw title of c */
extern unsigned long getcolor(const char *colstr); /* return color of colstr */
extern void setfont(const char *fontstr); /* set the font for DC */
extern unsigned int textw(const char *text); /* return the width of text in px*/
/* event.c */
extern void grabkeys();
extern void procevent();
extern void grabkeys(void); /* grab all keys defined in config.h */
extern void procevent(void); /* process pending X events */
/* main.c */
extern int getproto(Window w);
extern void quit(Arg *arg);
extern void sendevent(Window w, Atom a, long value);
extern int xerror(Display *dsply, XErrorEvent *ee);
extern int getproto(Window w); /* return protocol mask of WMProtocols property of w */
extern void quit(Arg *arg); /* quit dwm nicely */
extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
/* tag.c */
extern void initrregs();
extern Client *getnext(Client *c);
extern Client *getprev(Client *c);
extern void settags(Client *c);
extern void tag(Arg *arg);
extern void toggletag(Arg *arg);
extern void initrregs(void); /* initialize regexps of rules defined in config.h */
extern Client *getnext(Client *c); /* returns next visible client */
extern Client *getprev(Client *c); /* returns previous visible client */
extern void settags(Client *c, Client *trans); /* sets tags of c */
extern void tag(Arg *arg); /* tags c with arg's index */
extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
/* 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);
extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
extern void *erealloc(void *ptr, unsigned int size); /* reallocates memory, exits on error */
extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
/* view.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 restack();
extern void togglemode(Arg *arg);
extern void toggleview(Arg *arg);
extern void view(Arg *arg);
extern void zoom(Arg *arg);
extern void detach(Client *c); /* detaches c from global client list */
extern void dofloat(Arg *arg); /* arranges all windows floating, arg is ignored */
extern void dotile(Arg *arg); /* arranges all windows, arg is ignored */
extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
extern Bool isvisible(Client *c); /* returns True if client is visible */
extern void resizecol(Arg *arg); /* resizes the master percent with arg's index value */
extern void restack(void); /* restores z layers of all clients */
extern void togglestackpos(Arg *arg); /* toggles stack position */
extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */
extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
extern void view(Arg *arg); /* views the tag with arg's index */
extern void viewall(Arg *arg); /* views all tags, arg is ignored */
extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */

127
dwm.html
View File

@ -1,127 +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">
<link rel="dwm icon" href="favicon.ico" type="image/x-icon" />
<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>Background</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 doesn'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-20060810a.png">Screenshot of tiled mode</a> (20060810)</li>
<li><a href="http://10kloc.org/shots/dwm-20060810b.png">Screenshotof floating mode</a> (20060810)</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>&nbsp;<a href="http://dir.gmane.org/gmane.comp.window-managers.dwm">(GMANE Archive)</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-1.0.tar.gz">dwm 1.0</a> (15kb) (20060824)</li>
<li><a href="http://10kloc.org/download/dmenu-0.5.tar.gz">dmenu 0.5</a> (7kb) (20060824)</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>

151
event.c
View File

@ -21,8 +21,7 @@ KEYS
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
static void
movemouse(Client *c)
{
movemouse(Client *c) {
int x1, y1, ocx, ocy, di;
unsigned int dui;
Window dummy;
@ -33,11 +32,15 @@ movemouse(Client *c)
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurMove], CurrentTime) != GrabSuccess)
return;
c->ismax = False;
XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
for(;;) {
XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
switch (ev.type) {
default: break;
case ButtonRelease:
resize(c, True, TopLeft);
XUngrabPointer(dpy, CurrentTime);
return;
case Expose:
handler[Expose](&ev);
break;
@ -47,16 +50,12 @@ movemouse(Client *c)
c->y = ocy + (ev.xmotion.y - y1);
resize(c, False, TopLeft);
break;
case ButtonRelease:
XUngrabPointer(dpy, CurrentTime);
return;
}
}
}
static void
resizemouse(Client *c)
{
resizemouse(Client *c) {
int ocx, ocy;
int nw, nh;
Corner sticky;
@ -67,20 +66,24 @@ resizemouse(Client *c)
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
None, cursor[CurResize], CurrentTime) != GrabSuccess)
return;
c->ismax = False;
XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
for(;;) {
XMaskEvent(dpy, MOUSEMASK | ExposureMask, &ev);
switch(ev.type) {
default: break;
case ButtonRelease:
resize(c, True, TopLeft);
XUngrabPointer(dpy, CurrentTime);
return;
case Expose:
handler[Expose](&ev);
break;
case MotionNotify:
XSync(dpy, False);
if((nw = abs(ocx - ev.xmotion.x)))
c->w = abs(ocx - ev.xmotion.x);
c->w = nw;
if((nh = abs(ocy - ev.xmotion.y)))
c->h = abs(ocy - ev.xmotion.y);
c->h = nh;
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)
@ -89,16 +92,12 @@ resizemouse(Client *c)
sticky = (ocy <= ev.xmotion.y) ? TopRight : BotRight;
resize(c, True, sticky);
break;
case ButtonRelease:
XUngrabPointer(dpy, CurrentTime);
return;
}
}
}
static void
buttonpress(XEvent *e)
{
buttonpress(XEvent *e) {
int x;
Arg a;
Client *c;
@ -109,50 +108,54 @@ buttonpress(XEvent *e)
for(a.i = 0; a.i < ntags; a.i++) {
x += textw(tags[a.i]);
if(ev->x < x) {
if(ev->button == Button1)
view(&a);
else if(ev->button == Button3)
toggleview(&a);
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;
}
}
if(ev->x < x + bmw) {
if(ev->button == Button1)
togglemode(NULL);
else if(ev->button == Button3)
togglestackpos(NULL);
}
}
else if((c = getclient(ev->window))) {
focus(c);
if(CLEANMASK(ev->state) == 0)
if(CLEANMASK(ev->state) != MODKEY)
return;
switch(ev->button) {
default:
break;
case Button1:
if(!c->ismax && (arrange == dofloat || c->isfloat)) {
restack(c);
movemouse(c);
}
break;
case Button2:
if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) {
restack();
movemouse(c);
}
else if(ev->button == Button2)
zoom(NULL);
break;
case Button3:
if(!c->ismax && (arrange == dofloat || c->isfloat)) {
restack(c);
resizemouse(c);
}
break;
else if(ev->button == Button3 && (arrange == dofloat || c->isfloat)) {
restack();
resizemouse(c);
}
}
}
static void
configurerequest(XEvent *e)
{
configurerequest(XEvent *e) {
unsigned long newmask;
Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XEvent synev;
XWindowChanges wc;
if((c = getclient(ev->window))) {
c->ismax = False;
gravitate(c, True);
if(ev->value_mask & CWX)
c->x = ev->x;
@ -172,23 +175,14 @@ 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
configure(c);
XSync(dpy, False);
if(c->isfloat)
if(c->isfloat) {
resize(c, False, TopLeft);
if(!isvisible(c))
ban(c);
}
else
arrange(NULL);
}
@ -206,8 +200,7 @@ configurerequest(XEvent *e)
}
static void
destroynotify(XEvent *e)
{
destroynotify(XEvent *e) {
Client *c;
XDestroyWindowEvent *ev = &e->xdestroywindow;
@ -216,15 +209,14 @@ destroynotify(XEvent *e)
}
static void
enternotify(XEvent *e)
{
enternotify(XEvent *e) {
Client *c;
XCrossingEvent *ev = &e->xcrossing;
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
return;
if((c = getclient(ev->window)) || (c = getctitle(ev->window)))
if(((c = getclient(ev->window)) || (c = getctitle(ev->window))) && isvisible(c))
focus(c);
else if(ev->window == root) {
issel = True;
@ -234,8 +226,7 @@ enternotify(XEvent *e)
}
static void
expose(XEvent *e)
{
expose(XEvent *e) {
Client *c;
XExposeEvent *ev = &e->xexpose;
@ -248,8 +239,7 @@ expose(XEvent *e)
}
static void
keypress(XEvent *e)
{
keypress(XEvent *e) {
static unsigned int len = sizeof(key) / sizeof(key[0]);
unsigned int i;
KeySym keysym;
@ -257,8 +247,8 @@ keypress(XEvent *e)
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < len; i++) {
if(keysym == key[i].keysym &&
CLEANMASK(key[i].mod) == CLEANMASK(ev->state))
if(keysym == key[i].keysym
&& CLEANMASK(key[i].mod) == CLEANMASK(ev->state))
{
if(key[i].func)
key[i].func(&key[i].arg);
@ -268,8 +258,7 @@ keypress(XEvent *e)
}
static void
leavenotify(XEvent *e)
{
leavenotify(XEvent *e) {
XCrossingEvent *ev = &e->xcrossing;
if((ev->window == root) && !ev->same_screen) {
@ -279,8 +268,7 @@ leavenotify(XEvent *e)
}
static void
mappingnotify(XEvent *e)
{
mappingnotify(XEvent *e) {
XMappingEvent *ev = &e->xmapping;
XRefreshKeyboardMapping(ev);
@ -289,8 +277,7 @@ mappingnotify(XEvent *e)
}
static void
maprequest(XEvent *e)
{
maprequest(XEvent *e) {
static XWindowAttributes wa;
XMapRequestEvent *ev = &e->xmaprequest;
@ -308,8 +295,7 @@ maprequest(XEvent *e)
}
static void
propertynotify(XEvent *e)
{
propertynotify(XEvent *e) {
Client *c;
Window trans;
XPropertyEvent *ev = &e->xproperty;
@ -330,19 +316,19 @@ propertynotify(XEvent *e)
arrange(NULL);
break;
case XA_WM_NORMAL_HINTS:
setsize(c);
updatesize(c);
break;
}
if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
settitle(c);
updatetitle(c);
resizetitle(c);
drawtitle(c);
}
}
}
static void
unmapnotify(XEvent *e)
{
unmapnotify(XEvent *e) {
Client *c;
XUnmapEvent *ev = &e->xunmap;
@ -367,8 +353,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
};
void
grabkeys()
{
grabkeys(void) {
static unsigned int len = sizeof(key) / sizeof(key[0]);
unsigned int i;
KeyCode code;
@ -388,8 +373,7 @@ grabkeys()
}
void
procevent()
{
procevent(void) {
XEvent ev;
while(XPending(dpy)) {
@ -398,4 +382,3 @@ procevent()
(handler[ev.type])(&ev); /* call handler */
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

62
main.c
View File

@ -19,13 +19,14 @@
char stext[1024];
Bool *seltag;
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
unsigned int ntags, numlockmask;
int bx, by, bw, bh, bmw, masterd, screen, sx, sy, sw, sh;
unsigned int master, ntags, numlockmask;
Atom wmatom[WMLast], netatom[NetLast];
Bool running = True;
Bool issel = True;
Client *clients = NULL;
Client *sel = NULL;
Client *stack = NULL;
Cursor cursor[CurLast];
Display *dpy;
DC dc = {0};
@ -37,8 +38,7 @@ static int (*xerrorxlib)(Display *, XErrorEvent *);
static Bool otherwm, readin;
static void
cleanup()
{
cleanup(void) {
close(STDIN_FILENO);
while(sel) {
resize(sel, True, TopLeft);
@ -54,11 +54,11 @@ cleanup()
XDestroyWindow(dpy, barwin);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XSync(dpy, False);
free(seltag);
}
static void
scan()
{
scan(void) {
unsigned int i, num;
Window *wins, d1, d2;
XWindowAttributes wa;
@ -79,8 +79,7 @@ scan()
}
static void
setup()
{
setup(void) {
int i, j;
unsigned int mask;
Window w;
@ -109,7 +108,8 @@ setup()
}
XFree(modmap);
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask;
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask
| EnterWindowMask | LeaveWindowMask;
wa.cursor = cursor[CurNormal];
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
@ -121,19 +121,26 @@ setup()
seltag[0] = True;
/* style */
dc.bg = getcolor(BGCOLOR);
dc.fg = getcolor(FGCOLOR);
dc.border = getcolor(BORDERCOLOR);
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(VSTACKSYMBOL) > textw(BSTACKSYMBOL) ?
textw(VSTACKSYMBOL) : textw(BSTACKSYMBOL);
bmw = bmw > textw(FLOATSYMBOL) ?
bmw : textw(FLOATSYMBOL);
sx = sy = 0;
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
mw = (sw * MASTERW) / 100;
master = MASTER;
bx = by = 0;
bw = sw;
dc.h = bh = dc.font.height + 4;
dc.h = bh = dc.font.height + 2;
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
wa.event_mask = ButtonPressMask | ExposureMask;
@ -156,8 +163,7 @@ setup()
* is already running.
*/
static int
xerrorstart(Display *dsply, XErrorEvent *ee)
{
xerrorstart(Display *dsply, XErrorEvent *ee) {
otherwm = True;
return -1;
}
@ -165,8 +171,7 @@ xerrorstart(Display *dsply, XErrorEvent *ee)
/* extern */
int
getproto(Window w)
{
getproto(Window w) {
int i, format, protos, status;
unsigned long extra, res;
Atom *protocols, real;
@ -184,8 +189,7 @@ getproto(Window w)
}
void
sendevent(Window w, Atom a, long value)
{
sendevent(Window w, Atom a, long value) {
XEvent e;
e.type = ClientMessage;
@ -199,35 +203,33 @@ sendevent(Window w, Atom a, long value)
}
void
quit(Arg *arg)
{
quit(Arg *arg) {
readin = running = False;
}
/*
* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which calls exit().
* default error handler, which may call exit.
*/
int
xerror(Display *dpy, XErrorEvent *ee)
{
xerror(Display *dpy, XErrorEvent *ee) {
if(ee->error_code == BadWindow
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess))
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
return 0;
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
ee->request_code, ee->error_code);
return xerrorxlib(dpy, ee); /* may call exit() */
return xerrorxlib(dpy, ee); /* may call exit */
}
int
main(int argc, char *argv[])
{
main(int argc, char *argv[]) {
int r, xfd;
fd_set rd;

41
tag.c
View File

@ -33,22 +33,19 @@ static unsigned int len = 0;
/* extern */
Client *
getnext(Client *c)
{
getnext(Client *c) {
for(; c && !isvisible(c); c = c->next);
return c;
}
Client *
getprev(Client *c)
{
getprev(Client *c) {
for(; c && !isvisible(c); c = c->prev);
return c;
}
void
initrregs()
{
initrregs(void) {
unsigned int i;
regex_t *reg;
@ -76,15 +73,18 @@ initrregs()
}
void
settags(Client *c)
{
settags(Client *c, Client *trans) {
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)) {
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 : "", c->name);
@ -106,11 +106,11 @@ settags(Client *c)
if(!matched)
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
tag(Arg *arg)
{
tag(Arg *arg) {
unsigned int i;
if(!sel)
@ -119,16 +119,12 @@ tag(Arg *arg)
for(i = 0; i < ntags; i++)
sel->tags[i] = False;
sel->tags[arg->i] = True;
settitle(sel);
if(!isvisible(sel))
arrange(NULL);
else
drawstatus();
sel->weight = arg->i;
arrange(NULL);
}
void
toggletag(Arg *arg)
{
toggletag(Arg *arg) {
unsigned int i;
if(!sel)
@ -138,9 +134,6 @@ toggletag(Arg *arg)
for(i = 0; i < ntags && !sel->tags[i]; i++);
if(i == ntags)
sel->tags[arg->i] = True;
settitle(sel);
if(!isvisible(sel))
arrange(NULL);
else
drawstatus();
sel->weight = (i == ntags) ? arg->i : i;
arrange(NULL);
}

14
util.c
View File

@ -12,8 +12,7 @@
/* extern */
void *
emallocz(unsigned int size)
{
emallocz(unsigned int size) {
void *res = calloc(1, size);
if(!res)
@ -22,8 +21,7 @@ emallocz(unsigned int size)
}
void
eprint(const char *errstr, ...)
{
eprint(const char *errstr, ...) {
va_list ap;
va_start(ap, errstr);
@ -33,8 +31,7 @@ eprint(const char *errstr, ...)
}
void *
erealloc(void *ptr, unsigned int size)
{
erealloc(void *ptr, unsigned int size) {
void *res = realloc(ptr, size);
if(!res)
eprint("fatal: could not malloc() %u bytes\n", size);
@ -42,8 +39,7 @@ erealloc(void *ptr, unsigned int size)
}
void
spawn(Arg *arg)
{
spawn(Arg *arg) {
static char *shell = NULL;
if(!shell && !(shell = getenv("SHELL")))
@ -51,6 +47,8 @@ spawn(Arg *arg)
if(!arg->cmd)
return;
/* The double-fork construct avoids zombie processes and keeps the code
* clean from stupid signal handlers. */
if(fork() == 0) {
if(fork() == 0) {
if(dpy)

364
view.c
View File

@ -4,81 +4,182 @@
*/
#include "dwm.h"
/* static */
static Client *
minclient(void) {
Client *c, *min;
if((clients && clients->isfloat) || arrange == dofloat)
return clients; /* don't touch floating order */
for(min = c = clients; c; c = c->next)
if(c->weight < min->weight)
min = c;
return min;
}
static Client *
nexttiled(Client *c) {
for(c = getnext(c); c && c->isfloat; c = getnext(c->next));
return c;
}
static void
reorder(void) {
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 void
togglemax(Client *c)
{
XEvent ev;
if((c->ismax = !c->ismax)) {
c->rx = c->x; c->x = sx;
c->ry = c->y; c->y = bh;
c->rw = c->w; c->w = sw - 2 * BORDERPX;
c->rh = c->h; c->h = sh - bh - 2 * BORDERPX;
}
else {
c->x = c->rx;
c->y = c->ry;
c->w = c->rw;
c->h = c->rh;
}
resize(c, True, TopLeft);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
/* extern */
void (*arrange)(Arg *) = DEFMODE;
StackPos stackpos = STACKPOS;
void
dofloat(Arg *arg)
{
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;
for(c = clients; c; c = c->next) {
c->ismax = False;
if(isvisible(c)) {
resize(c, True, TopLeft);
}
else
ban(c);
}
if(!sel || !isvisible(sel))
sel = getnext(clients);
if(sel)
focus(sel);
else
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
if(!sel || !isvisible(sel)) {
for(c = stack; c && !isvisible(c); c = c->snext);
focus(c);
}
restack();
}
/* This algorithm is based on a (M)aster area and a (S)tacking area.
* It supports following arrangements:
* SSMMM MMMMM MMMSS
* SSMMM SSSSS MMMSS
*/
void
dotile(Arg *arg)
{
int h, i, n, w;
dotile(Arg *arg) {
unsigned int i, n, md, stackw, stackh, tw, th;
Client *c;
w = sw - mw;
for(n = 0, c = clients; c; c = c->next)
if(isvisible(c) && !c->isfloat)
n++;
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++;
if(stackpos == StackBottom) {
md = ((sh - bh) * master) / 100;
stackw = sw;
stackh = sh - bh - md;
}
else {
md = (sw * master) / 100;
stackw = sw - md;
stackh = sh - bh;
}
tw = stackw;
if(n > 1)
h = (sh - bh) / (n - 1);
th = stackh / (n - 1);
else
h = sh - bh;
th = stackh;
for(i = 0, c = clients; c; c = c->next) {
c->ismax = False;
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;
c->ismax = False;
c->x = sx;
c->y = sy + bh;
if(n == 1) { /* only 1 window */
c->w = sw - 2 * BORDERPX;
c->h = sh - 2 * BORDERPX - bh;
}
else if(i == 0) {
c->x = sx;
c->y = sy + bh;
c->w = mw - 2;
c->h = sh - 2 - bh;
else if(i == 0) { /* master window */
if(stackpos == StackLeft)
c->x += stackw;
switch(stackpos) {
case StackLeft:
case StackRight:
c->w = md - 2 * BORDERPX;
c->h = sh - bh - 2 * BORDERPX;
break;
case StackBottom:
c->w = sw - 2 * BORDERPX;
c->h = md - 2 * BORDERPX;
break;
}
}
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;
else { /* tile window */
if(stackpos == StackRight)
c->x += md;
if(th > bh) {
switch(stackpos) {
case StackLeft:
case StackRight:
c->y = sy + (i - 1) * th + bh;
if(i + 1 == n)
c->h = sh - c->y - 2 * BORDERPX;
break;
case StackBottom:
c->y = sy + md + (i - 1) * th + bh;
if(i + 1 == n)
c->h = sh - c->y - 2 * BORDERPX;
break;
}
c->w = tw - 2 * BORDERPX;
c->h = th - 2 * BORDERPX;
}
else { /* fallback if th < bh */
if(stackpos == StackBottom)
c->y += md;
c->w = stackw - 2 * BORDERPX;
c->h = stackh - 2 * BORDERPX;
}
}
resize(c, False, TopLeft);
i++;
@ -86,18 +187,15 @@ dotile(Arg *arg)
else
ban(c);
}
if(!sel || !isvisible(sel))
sel = getnext(clients);
if(sel)
focus(sel);
else
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
if(!sel || !isvisible(sel)) {
for(c = stack; c && !isvisible(c); c = c->snext);
focus(c);
}
restack();
}
void
focusnext(Arg *arg)
{
focusnext(Arg *arg) {
Client *c;
if(!sel)
@ -112,8 +210,7 @@ focusnext(Arg *arg)
}
void
focusprev(Arg *arg)
{
focusprev(Arg *arg) {
Client *c;
if(!sel)
@ -130,8 +227,7 @@ focusprev(Arg *arg)
}
Bool
isvisible(Client *c)
{
isvisible(Client *c) {
unsigned int i;
for(i = 0; i < ntags; i++)
@ -141,60 +237,61 @@ isvisible(Client *c)
}
void
restack()
{
static unsigned int nwins = 0;
static Window *wins = NULL;
unsigned int f, fi, m, mi, n;
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 == dofloat))
return;
if(sel == getnext(clients)) {
if(master + arg->i > 95 || master + arg->i < 5)
return;
master += arg->i;
}
else {
if(master - arg->i > 95 || master - arg->i < 5)
return;
master -= arg->i;
}
arrange(NULL);
}
void
restack(void) {
Client *c;
XEvent ev;
for(f = 0, m = 0, c = clients; c; c = c->next)
if(isvisible(c)) {
if(c->isfloat || arrange == dofloat)
f++;
else
m++;
}
if(!(n = 2 * (f + m))) {
if(!sel) {
drawstatus();
return;
}
if(nwins < n) {
nwins = n;
wins = erealloc(wins, nwins * sizeof(Window));
}
fi = 0;
mi = 2 * f;
if(sel->isfloat || arrange == dofloat) {
wins[fi++] = sel->twin;
wins[fi++] = sel->win;
XRaiseWindow(dpy, sel->win);
XRaiseWindow(dpy, sel->twin);
}
else {
wins[mi++] = sel->twin;
wins[mi++] = sel->win;
}
for(c = clients; c; c = c->next)
if(isvisible(c) && c != sel) {
if(c->isfloat || arrange == dofloat) {
wins[fi++] = c->twin;
wins[fi++] = c->win;
}
else {
wins[mi++] = c->twin;
wins[mi++] = c->win;
}
if(arrange != dofloat) {
if(!sel->isfloat) {
XLowerWindow(dpy, sel->twin);
XLowerWindow(dpy, sel->win);
}
XRestackWindows(dpy, wins, n);
for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
if(c == sel)
continue;
XLowerWindow(dpy, c->twin);
XLowerWindow(dpy, c->win);
}
}
drawall();
XSync(dpy, False);
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
void
togglemode(Arg *arg)
{
togglemode(Arg *arg) {
arrange = (arrange == dofloat) ? dotile : dofloat;
if(sel)
arrange(NULL);
@ -203,51 +300,78 @@ togglemode(Arg *arg)
}
void
toggleview(Arg *arg)
{
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)
{
togglestackpos(Arg *arg) {
if(arrange == dofloat)
return;
if(stackpos == StackBottom)
stackpos = STACKPOS;
else
stackpos = StackBottom;
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
zoom(Arg *arg)
{
Client *c;
viewall(Arg *arg) {
unsigned int i;
if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
return;
if(sel == getnext(clients)) {
if((c = getnext(sel->next)))
sel = c;
else
return;
}
/* pop */
sel->prev->next = sel->next;
if(sel->next)
sel->next->prev = sel->prev;
sel->prev = NULL;
clients->prev = sel;
sel->next = clients;
clients = sel;
focus(sel);
for(i = 0; i < ntags; i++)
seltag[i] = True;
reorder();
arrange(NULL);
}
void
zoom(Arg *arg) {
unsigned int n;
Client *c;
if(!sel)
return;
if(sel->isfloat || (arrange == dofloat)) {
togglemax(sel);
return;
}
for(n = 0, c = clients; c; c = c->next)
if(isvisible(c) && !c->isfloat)
n++;
if(n < 2 || (arrange == dofloat))
return;
if((c = sel) == nexttiled(clients))
if(!(c = nexttiled(c->next)))
return;
detach(c);
if(clients)
clients->prev = c;
c->next = clients;
clients = c;
focus(c);
arrange(NULL);
}