summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--config.def.h1
-rw-r--r--dwm.114
-rw-r--r--dwm.c87
4 files changed, 31 insertions, 73 deletions
diff --git a/README b/README
index 2dcaedd..b11cb00 100644
--- a/README
+++ b/README
@@ -40,7 +40,7 @@ like this in your .xinitrc:
40 40
41 while true 41 while true
42 do 42 do
43 echo `date` `uptime | sed 's/.*,//'` 43 xsetroot -name "`date` `uptime | sed 's/.*,//'`"
44 sleep 1 44 sleep 1
45 done | dwm 45 done | dwm
46 46
diff --git a/config.def.h b/config.def.h
index 7c19b2f..bb60471 100644
--- a/config.def.h
+++ b/config.def.h
@@ -12,7 +12,6 @@ static unsigned int borderpx = 1; /* border pixel of windows */
12static unsigned int snap = 32; /* snap pixel */ 12static unsigned int snap = 32; /* snap pixel */
13static Bool showbar = True; /* False means no bar */ 13static Bool showbar = True; /* False means no bar */
14static Bool topbar = True; /* False means bottom bar */ 14static Bool topbar = True; /* False means bottom bar */
15static Bool readin = True; /* False means do not read stdin */
16static Bool usegrab = False; /* True means grabbing the X server 15static Bool usegrab = False; /* True means grabbing the X server
17 during mouse-based resizals */ 16 during mouse-based resizals */
18 17
diff --git a/dwm.1 b/dwm.1
index a6416e0..178de7c 100644
--- a/dwm.1
+++ b/dwm.1
@@ -20,13 +20,13 @@ Windows are grouped by tags. Each window can be tagged with one or multiple
20tags. Selecting certain tags displays all windows with these tags. 20tags. Selecting certain tags displays all windows with these tags.
21.P 21.P
22dwm contains a small status bar which displays all available tags, the layout, 22dwm contains a small status bar which displays all available tags, the layout,
23the title of the focused window, and the text read from standard input. A 23the title of the focused window, and the text read from the root window name
24floating window is indicated with an empty square and a maximised 24property. A floating window is indicated with an empty square and a maximised
25floating window is indicated with a filled square before the windows 25floating window is indicated with a filled square before the windows title.
26title. The selected tags are indicated with a different color. The tags of 26The selected tags are indicated with a different color. The tags of the focused
27the focused window are indicated with a filled square in the top left 27window are indicated with a filled square in the top left corner. The tags
28corner. The tags which are applied to one or more windows are indicated 28which are applied to one or more windows are indicated with an empty square in
29with an empty square in the top left corner. 29the top left corner.
30.P 30.P
31dwm draws a small border around windows to indicate the focus state. 31dwm draws a small border around windows to indicate the focus state.
32.SH OPTIONS 32.SH OPTIONS
diff --git a/dwm.c b/dwm.c
index c9c2994..dc63a0b 100644
--- a/dwm.c
+++ b/dwm.c
@@ -6,12 +6,9 @@
6 * events about window (dis-)appearance. Only one X connection at a time is 6 * events about window (dis-)appearance. Only one X connection at a time is
7 * allowed to select for this event mask. 7 * allowed to select for this event mask.
8 * 8 *
9 * Calls to fetch an X event from the event queue are blocking. Due reading 9 * The event handlers of dwm are organized in an array which is accessed
10 * status text from standard input, a select()-driven main loop has been 10 * whenever a new event has been fetched. This allows event dispatching
11 * implemented which selects for reads on the X connection and STDIN_FILENO to 11 * in O(1) time.
12 * handle all data smoothly. The event handlers of dwm are organized in an
13 * array which is accessed whenever a new event has been fetched. This allows
14 * event dispatching in O(1) time.
15 * 12 *
16 * Each child of the root window is called a client, except windows which have 13 * Each child of the root window is called a client, except windows which have
17 * set the override_redirect flag. Clients are organized in a global 14 * set the override_redirect flag. Clients are organized in a global
@@ -30,7 +27,6 @@
30#include <stdlib.h> 27#include <stdlib.h>
31#include <string.h> 28#include <string.h>
32#include <unistd.h> 29#include <unistd.h>
33#include <sys/select.h>
34#include <sys/types.h> 30#include <sys/types.h>
35#include <sys/wait.h> 31#include <sys/wait.h>
36#include <X11/cursorfont.h> 32#include <X11/cursorfont.h>
@@ -196,6 +192,7 @@ static void updatebar(void);
196static void updategeom(void); 192static void updategeom(void);
197static void updatenumlockmask(void); 193static void updatenumlockmask(void);
198static void updatesizehints(Client *c); 194static void updatesizehints(Client *c);
195static void updatestatus(void);
199static void updatetitle(Client *c); 196static void updatetitle(Client *c);
200static void updatewmhints(Client *c); 197static void updatewmhints(Client *c);
201static void view(const Arg *arg); 198static void view(const Arg *arg);
@@ -998,9 +995,11 @@ propertynotify(XEvent *e) {
998 Window trans; 995 Window trans;
999 XPropertyEvent *ev = &e->xproperty; 996 XPropertyEvent *ev = &e->xproperty;
1000 997
1001 if(ev->state == PropertyDelete) 998 if((ev->window == root) && (ev->atom = XA_WM_NAME))
999 updatestatus();
1000 else if(ev->state == PropertyDelete)
1002 return; /* ignore */ 1001 return; /* ignore */
1003 if((c = getclient(ev->window))) { 1002 else if((c = getclient(ev->window))) {
1004 switch (ev->atom) { 1003 switch (ev->atom) {
1005 default: break; 1004 default: break;
1006 case XA_WM_TRANSIENT_FOR: 1005 case XA_WM_TRANSIENT_FOR:
@@ -1026,7 +1025,7 @@ propertynotify(XEvent *e) {
1026 1025
1027void 1026void
1028quit(const Arg *arg) { 1027quit(const Arg *arg) {
1029 readin = running = False; 1028 running = False;
1030} 1029}
1031 1030
1032void 1031void
@@ -1180,60 +1179,13 @@ restack(void) {
1180 1179
1181void 1180void
1182run(void) { 1181run(void) {
1183 char *p;
1184 char sbuf[sizeof stext];
1185 fd_set rd;
1186 int r, xfd;
1187 unsigned int len, offset;
1188 XEvent ev; 1182 XEvent ev;
1189 1183
1190 /* main event loop, also reads status text from stdin */ 1184 /* main event loop */
1191 XSync(dpy, False); 1185 XSync(dpy, False);
1192 xfd = ConnectionNumber(dpy); 1186 while(running && !XNextEvent(dpy, &ev)) {
1193 offset = 0; 1187 if(handler[ev.type])
1194 len = sizeof stext - 1; 1188 (handler[ev.type])(&ev); /* call handler */
1195 sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
1196 while(running) {
1197 FD_ZERO(&rd);
1198 if(readin)
1199 FD_SET(STDIN_FILENO, &rd);
1200 FD_SET(xfd, &rd);
1201 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
1202 if(errno == EINTR)
1203 continue;
1204 die("select failed\n");
1205 }
1206 if(FD_ISSET(STDIN_FILENO, &rd)) {
1207 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
1208 case -1:
1209 strncpy(stext, strerror(errno), len);
1210 readin = False;
1211 break;
1212 case 0:
1213 strncpy(stext, "EOF", 4);
1214 readin = False;
1215 break;
1216 default:
1217 for(p = sbuf + offset; r > 0; p++, r--, offset++)
1218 if(*p == '\n' || *p == '\0') {
1219 *p = '\0';
1220 strncpy(stext, sbuf, len);
1221 p += r - 1; /* p is sbuf + offset + r - 1 */
1222 for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
1223 offset = r;
1224 if(r)
1225 memmove(sbuf, p - r + 1, r);
1226 break;
1227 }
1228 break;
1229 }
1230 drawbar();
1231 }
1232 while(XPending(dpy)) {
1233 XNextEvent(dpy, &ev);
1234 if(handler[ev.type])
1235 (handler[ev.type])(&ev); /* call handler */
1236 }
1237 } 1189 }
1238} 1190}
1239 1191
@@ -1356,8 +1308,7 @@ setup(void) {
1356 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa); 1308 CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
1357 XDefineCursor(dpy, barwin, cursor[CurNormal]); 1309 XDefineCursor(dpy, barwin, cursor[CurNormal]);
1358 XMapRaised(dpy, barwin); 1310 XMapRaised(dpy, barwin);
1359 strcpy(stext, "dwm-"VERSION); 1311 updatestatus();
1360 drawbar();
1361 1312
1362 /* EWMH support per view */ 1313 /* EWMH support per view */
1363 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, 1314 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
@@ -1365,7 +1316,8 @@ setup(void) {
1365 1316
1366 /* select for events */ 1317 /* select for events */
1367 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask 1318 wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
1368 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask; 1319 |EnterWindowMask|LeaveWindowMask|StructureNotifyMask
1320 |PropertyChangeMask;
1369 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa); 1321 XChangeWindowAttributes(dpy, root, CWEventMask|CWCursor, &wa);
1370 XSelectInput(dpy, root, wa.event_mask); 1322 XSelectInput(dpy, root, wa.event_mask);
1371 1323
@@ -1647,6 +1599,13 @@ updatetitle(Client *c) {
1647} 1599}
1648 1600
1649void 1601void
1602updatestatus() {
1603 if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
1604 strcpy(stext, "dwm-"VERSION);
1605 drawbar();
1606}
1607
1608void
1650updatewmhints(Client *c) { 1609updatewmhints(Client *c) {
1651 XWMHints *wmh; 1610 XWMHints *wmh;
1652 1611