Re: [dwm] 4.7 is delayed

From: Ritesh Kumar <ritesh_AT_cs.unc.edu>
Date: Mon, 5 Nov 2007 05:01:16 -0500

I have a few comments...

Do you want to keep LENGTH(), seltags and prevtags in config.def.h? My
configuration doesn't need them and I doubt if somebody else's will.

I think now I understand your concern about my solution to the inputtext
behavior. What do we do if we read in a string which has '\n' or '\0' in the
middle instead of at the end? It won't happen with well behaved scripts, but
we are certainly not fool proof with my patch.

The lines in run() that this discussion is about:
                        default:
                                stext[offset + r] = '\0';
                                for(p = stext; *p && *p != '\n'; p++);
                                if(*p == '\n') {
                                        *p = '\0';
                                        offset = 0;
                                }
                                else
                                        offset = (offset + r < len - 1) ?
offset + r : 0;

This is certainly cleaner than my solution :)
However, the lines above would keep the text till the read '\n' and
*discard* the rest of the text which was read in. Note that this will cause
the next iteration of read() to read in the partially available text and
display it from offset 0. Also, if it is terminated by a \n and a pause
follows then we have partial data showing for the pause duration in the
statusbar.
Now, we could try discarding the string *before* the middle \n. This means
that we will briefly display the partially available string and then
(hopefully in the next instant) read the rest of the string and display it.
That will cause flicker... again not so good.

I think the best option is to double buffer this thing. So while the input
is being read (till we encounter a \n), we keep displaying the old string.
So long as there is a pause between the read()ing of any two \n's we won't
have flicker or incomplete string display.

Here is my patch... The basic idea is to keep reading in a separate buffer
(buf). If a \n or \0 is read then take the front portion of buf (delimited
by \n or \0) and use it for stext and take the back portion of buf and use
it the new buf and offset.

Feedback is welcome :)

_r

diff -r 21aae6fc2bc5 dwm.c
--- a/dwm.c Mon Nov 05 02:55:33 2007 -0500
+++ b/dwm.c Mon Nov 05 04:27:54 2007 -0500
@@ -229,6 +229,12 @@ Regs *regs = NULL;
 /* configuration, allows nested code to access above variables */
 #include "config.h"

+/* convenience */
+#define LENGTH(x) (sizeof x / sizeof x[0])
+
+Bool seltags[LENGTH(tags)] = {[0] = True};
+Bool prevtags[LENGTH(tags)] = {[0] = True};
+
 /* function implementations */
 void
 applyrules(Client *c) {
@@ -1283,6 +1289,7 @@ run(void) {
        int r, xfd;
        unsigned int len, offset;
        XEvent ev;
+ char buf[sizeof(stext)];

        /* main event loop, also reads status text from stdin */
        XSync(dpy, False);
@@ -1302,7 +1309,7 @@ run(void) {
                        eprint("select failed\n");
                }
                if(FD_ISSET(STDIN_FILENO, &rd)) {
- switch((r = read(STDIN_FILENO, stext + offset, len -
offset))) {
+ switch((r = read(STDIN_FILENO, buf + offset, len -
offset))) {
                        case -1:
                                strncpy(stext, strerror(errno), len);
                                readin = False;
@@ -1312,14 +1319,18 @@ run(void) {
                                readin = False;
                                break;
                        default:
- stext[offset + r] = '\0';
- for(p = stext; *p && *p != '\n'; p++);
- if(*p == '\n') {
- *p = '\0';
- offset = 0;
+ for(p = buf + offset; r>0 ; p++, r--,
offset++) {
+ if(*p == '\n' || *p == '\0'){
+ *p = '\0';
+ strncpy(stext, buf, len);
+ p += r - 1; // p is buf
+ offset + r - 1
+ for(r = 0; *(p-r) && *(p-r)
!= '\n'; r++);
+ offset = r;
+ if(r)
+ memmove(buf, p - r +
1, r);
+ break;
+ }
                                }
- else
- offset = (offset + r < len - 1) ?
offset + r : 0;
                        }
                        drawbar();
                }
Received on Mon Nov 05 2007 - 11:01:19 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:04:57 UTC