summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
authora@null <unknown>2008-12-12 19:49:06 +0000
committera@null <unknown>2008-12-12 19:49:06 +0000
commit0b5dcf229f64a23438e6ef5929d78b7f9bd48355 (patch)
tree12bebf28ea6e33a9ee470ffee9f6fd399bd34991 /dwm.c
parentapplied yiyus fix (diff)
downloaddwm-0b5dcf229f64a23438e6ef5929d78b7f9bd48355.tar.gz
dwm-0b5dcf229f64a23438e6ef5929d78b7f9bd48355.zip
applied Neale Pickett's xprop status reading patch, updated README and dwm.1 accordingly
Diffstat (limited to '')
-rw-r--r--dwm.c87
1 files changed, 23 insertions, 64 deletions
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