sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-r1533-stdin.diff (3803B)


      1 This backports pre-dwm-5.3 behaviour where the status bar content was read from
      2 stdin instead of the root window title. I did this, because I had several
      3 problems with the "new" method, on different machines, with different
      4 configurations, including vanilla, where the statusbar froze.
      5 It adds some LOC, but is not broken for me.
      6 
      7 diff -r ba7d976f74d3 config.def.h
      8 --- a/config.def.h	Fri Mar 25 14:06:46 2011 +0000
      9 +++ b/config.def.h	Sun Apr 10 19:07:26 2011 +0200
     10 @@ -12,6 +12,7 @@
     11  static const unsigned int snap      = 32;       /* snap pixel */
     12  static const Bool showbar           = True;     /* False means no bar */
     13  static const Bool topbar            = True;     /* False means bottom bar */
     14 +static Bool readin                  = True;     /* False means do not read stdin */
     15  
     16  /* tagging */
     17  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
     18 diff -r ba7d976f74d3 dwm.c
     19 --- a/dwm.c	Fri Mar 25 14:06:46 2011 +0000
     20 +++ b/dwm.c	Sun Apr 10 19:07:26 2011 +0200
     21 @@ -28,6 +28,7 @@
     22  #include <stdlib.h>
     23  #include <string.h>
     24  #include <unistd.h>
     25 +#include <sys/select.h>
     26  #include <sys/types.h>
     27  #include <sys/wait.h>
     28  #include <X11/cursorfont.h>
     29 @@ -232,7 +233,6 @@
     30  static void updatebars(void);
     31  static void updatenumlockmask(void);
     32  static void updatesizehints(Client *c);
     33 -static void updatestatus(void);
     34  static void updatetitle(Client *c);
     35  static void updatewmhints(Client *c);
     36  static void view(const Arg *arg);
     37 @@ -1251,9 +1251,7 @@
     38  	Window trans;
     39  	XPropertyEvent *ev = &e->xproperty;
     40  
     41 -	if((ev->window == root) && (ev->atom == XA_WM_NAME))
     42 -		updatestatus();
     43 -	else if(ev->state == PropertyDelete)
     44 +	if(ev->state == PropertyDelete)
     45  		return; /* ignore */
     46  	else if((c = wintoclient(ev->window))) {
     47  		switch (ev->atom) {
     48 @@ -1413,12 +1411,60 @@
     49  
     50  void
     51  run(void) {
     52 +	char *p;
     53 +	char sbuf[sizeof stext];
     54 +	fd_set rd;
     55 +	int r, xfd;
     56 +	unsigned int len, offset;
     57  	XEvent ev;
     58 -	/* main event loop */
     59 +
     60 +	/* main event loop, also reads status text from stdin */
     61  	XSync(dpy, False);
     62 -	while(running && !XNextEvent(dpy, &ev)) {
     63 -		if(handler[ev.type])
     64 -			handler[ev.type](&ev); /* call handler */
     65 +	xfd = ConnectionNumber(dpy);
     66 +	offset = 0;
     67 +	len = sizeof stext - 1;
     68 +	sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
     69 +	while(running) {
     70 +		FD_ZERO(&rd);
     71 +		if(readin)
     72 +			FD_SET(STDIN_FILENO, &rd);
     73 +		FD_SET(xfd, &rd);
     74 +		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
     75 +			if(errno == EINTR)
     76 +				continue;
     77 +			die("select failed\n");
     78 +		}
     79 +		if(FD_ISSET(STDIN_FILENO, &rd)) {
     80 +			switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
     81 +			case -1:
     82 +				strncpy(stext, strerror(errno), len);
     83 +				readin = False;
     84 +				break;
     85 +			case 0:
     86 +				strncpy(stext, "EOF", 4);
     87 +				readin = False;
     88 +				break;
     89 +			default:
     90 +				for(p = sbuf + offset; r > 0; p++, r--, offset++)
     91 +					if(*p == '\n' || *p == '\0') {
     92 +						*p = '\0';
     93 +						strncpy(stext, sbuf, len);
     94 +						p += r - 1; /* p is sbuf + offset + r - 1 */
     95 +						for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
     96 +						offset = r;
     97 +						if(r)
     98 +							memmove(sbuf, p - r + 1, r);
     99 +						break;
    100 +					}
    101 +				break;
    102 +			}
    103 +			drawbars();
    104 +		}
    105 +		while(XPending(dpy)) {
    106 +			XNextEvent(dpy, &ev);
    107 +			if(handler[ev.type])
    108 +				(handler[ev.type])(&ev); /* call handler */
    109 +		}
    110  	}
    111  }
    112  
    113 @@ -1539,7 +1585,6 @@
    114  		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
    115  	/* init bars */
    116  	updatebars();
    117 -	updatestatus();
    118  	/* EWMH support per view */
    119  	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
    120  			PropModeReplace, (unsigned char *) netatom, NetLast);
    121 @@ -1916,13 +1961,6 @@
    122  }
    123  
    124  void
    125 -updatestatus(void) {
    126 -	if(!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
    127 -		strcpy(stext, "dwm-"VERSION);
    128 -	drawbar(selmon);
    129 -}
    130 -
    131 -void
    132  updatewmhints(Client *c) {
    133  	XWMHints *wmh;
    134