JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Fix bar to correctly handle external script partial output.
[spectrwm.git] / spectrwm.c
index 0020f39..b0835a7 100644 (file)
@@ -279,7 +279,6 @@ volatile sig_atomic_t   restart_wm = 0;
 xcb_timestamp_t                last_event_time = 0;
 int                    outputs = 0;
 int                    other_wm;
-int                    ss_enabled = 0;
 int                    xrandr_support;
 int                    xrandr_eventbase;
 unsigned int           numlockmask = 0;
@@ -349,6 +348,7 @@ double                      dialog_ratio = 0.6;
 char           *bar_argv[] = { NULL, NULL };
 int             bar_pipe[2];
 char            bar_ext[SWM_BAR_MAX];
+char            bar_ext_buf[SWM_BAR_MAX];
 char            bar_vertext[SWM_BAR_MAX];
 int             bar_version = 0;
 int             bar_enabled = 1;
@@ -2197,17 +2197,32 @@ bar_fmt_print(void)
 void
 bar_update(void)
 {
-       size_t                  len;
-       char                    *b;
+       size_t          len;
+       char            b[SWM_BAR_MAX];
 
        if (bar_enabled && bar_extra && bar_extra_running) {
-               /* Ignore short reads; it'll correct itself. */
-               while ((b = fgetln(stdin, &len)) != NULL)
-                       if (b && b[len - 1] == '\n') {
-                               b[len - 1] = '\0';
-                               strlcpy(bar_ext, b, sizeof bar_ext);
+               while (fgets(b, sizeof(b), stdin) != NULL) {
+                       len = strlen(b);
+                       if (b[len - 1] == '\n') {
+                               /* Remove newline. */
+                               b[--len] = '\0';
+
+                               /* "Clear" bar_ext. */
+                               bar_ext[0] = '\0';
+
+                               /* Flush buffered output. */
+                               strlcpy(bar_ext, bar_ext_buf, sizeof(bar_ext));
+                               bar_ext_buf[0] = '\0';
+
+                               /* Append new output to bar. */
+                               strlcat(bar_ext, b, sizeof(bar_ext));
+                       } else {
+                               /* Buffer output. */
+                               strlcat(bar_ext_buf, b, sizeof(bar_ext_buf));
                        }
-               if (b == NULL && errno != EAGAIN) {
+               }
+
+               if (errno != EAGAIN) {
                        warn("bar_update: bar_extra failed");
                        bar_extra_stop();
                }
@@ -2216,7 +2231,7 @@ bar_update(void)
                 * Attempt to drain stdin, so it doesn't cause the main loop to
                 * call us as fast as it can.
                 */
-               fgetln(stdin, &len);
+               fgets(b, sizeof(b), stdin);
 
                if (!bar_enabled)
                        return;
@@ -6622,9 +6637,10 @@ setconfvalue(char *selector, char *value, int flags)
                setconfspawn("spawn_term", value, 0);
                break;
        case SWM_S_SS_APP:
+               /* No longer needed; leave to not break old conf files. */
                break;
        case SWM_S_SS_ENABLED:
-               ss_enabled = atoi(value);
+               /* No longer needed; leave to not break old conf files. */
                break;
        case SWM_S_STACK_ENABLED:
                stack_enabled = atoi(value);
@@ -9019,6 +9035,7 @@ noconfig:
                if (do_bar_update) {
                        do_bar_update = 0;
                        bar_update();
+                       xcb_flush(conn);
                }
        }
 done: