Hi folks,
I came across this curious behavior for the input status text...
I used to run dwm using the following bash script:
while true; do
date;
sleep 1;
done | dwm
... and things used to run fine :).
I changed it to:
while true; do
cat $HOME/.dwm/status_* ;
date;
sleep 1;
done | dwm
The status_* files contain text without trailing \n's.
Surprisingly , the contents of the statusbar didn't change (only date, no
other status text) ... even though the while loop outputs something like
<some text> Tue Oct 30 22:46:56 EDT 2007
<some text> Tue Oct 30 22:46:57 EDT 2007
<some text> Tue Oct 30 22:46:58 EDT 2007
...
My guess is that read() reads the status_* text and date in two successive
calls causing the date to prevail till sleep 1 is done.
I went through the source code and fixed the status input handling code to
make sure it flushes the input status text only if in encounters a '\n'. The
patch is given... unfortunately it is over my (recently posted) status text
patch. I moved the trimming of trailing \n's to another function setstext()
(introduced by my status text patch)... however, the relevant code can be
moved to the function run().
What do you guys think... did I accidentally break something?
_r
diff -r a5b57a189379 dwm.c
--- a/dwm.c Tue Oct 30 22:17:27 2007 -0400
+++ b/dwm.c Tue Oct 30 22:31:24 2007 -0400
@@ -1295,8 +1295,7 @@ restack(void) {
void
run(void) {
- char *p;
- int r, xfd;
+ int r, pos, xfd;
fd_set rd;
XEvent ev;
@@ -1315,7 +1314,8 @@ run(void) {
eprint("select failed\n");
}
if(FD_ISSET(STDIN_FILENO, &rd)) {
- switch(r = read(STDIN_FILENO, inputtext, sizeof
inputtext - 1)) {
+ pos = inputtext[strlen(inputtext)-1] != '\n' ?
strlen(inputtext) : 0;
+ switch(r = read(STDIN_FILENO, &(inputtext[pos]),
sizeof inputtext - 1 - pos)) {
case -1:
strncpy(inputtext, strerror(errno), sizeof
inputtext - 1);
inputtext[sizeof inputtext - 1] = '\0';
@@ -1326,10 +1326,7 @@ run(void) {
readin = False;
break;
default:
- for(inputtext[r] = '\0', p = inputtext +
strlen(inputtext) - 1; p >= inputtext && *p == '\n'; *p-- = '\0');
- for(; p >= inputtext && *p != '\n'; --p);
- if(p > inputtext)
- strncpy(inputtext, p + 1, sizeof
inputtext);
+ inputtext[pos+r] = '\0' ;
}
drawbar();
}
@@ -1426,6 +1423,9 @@ setstext(void) {
stext[0] = '\0';
for(i=0; i<sizeof(statusbar)/sizeof(char*); i++)
strncat(stext, statusbar[i], sizeof(stext) - strlen(stext));
+ // Trim the trailing \n's
+ for(i=strlen(stext)-1; stext[i]=='\n'; i--)
+ stext[i] = '\0';
}
Received on Wed Oct 31 2007 - 04:04:36 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:03:32 UTC