]> git.corax.cc Git - dwm/commitdiff
Update status bar on all monitors
authorMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 21:47:22 +0000 (06:47 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 28 Mar 2021 21:47:22 +0000 (06:47 +0900)
The status bar is not updated on all monitors when certain events occur.
This is particularly problematic if information is displayed that changes
frequently, and different screens show different information.
This commit modifies dwm so that the status bar on all monitors is redrawn
when its content changes.

dwm.c

diff --git a/dwm.c b/dwm.c
index 60e4104108981702b7e431c730a9ffcfe04c0d51..32bb1c1d08e28613f5d21321b2c0bbd67ce7ed0b 100755 (executable)
--- a/dwm.c
+++ b/dwm.c
@@ -524,7 +524,21 @@ Bool applysizehints(struct client *c, int *x, int *y, int *w, int *h, Bool inter
        }
 
        if(resizehints || c->isfloating || !c->mon->lt[c->mon->sellt]->arrange) {
-               /* see last two sentences in ICCCM 4.1.2.3 */
+               /*
+                * "The min_aspect and max_aspect fields are fractions with the
+                * numerator first and the denominator second, and they allow a
+                * client to specify the range of aspect ratios it prefers.
+                * Window managers that honor aspect ratios should take into
+                * account the base size in determining the preferred window
+                * size. If a base size is provided along with the aspect ratio
+                * fields, the base size should be subtracted from the window
+                * size prior to checking that the aspect ratio falls in range.
+                * If a base size is not provided, nothing should be subtracted
+                * from the window size. (The minimum size is not to be used in
+                * place of the base size for this purpose.)"
+                *
+                *  -- ICCCM 4.1.2.3 (https://tronche.com/gui/x/icccm/sec-4.html)
+                */
                baseismin = c->basew == c->minw && c->baseh == c->minh;
 
                if(!baseismin) { /* temporarily remove base dimensions */
@@ -1014,6 +1028,14 @@ struct monitor *dirtomon(int dir)
        return(m);
 }
 
+void wipe_bar(struct monitor *mon, unsigned long *col)
+{
+       XSetForeground(dpy, dc.gc, col[ColBG]);
+       XFillRectangle(dpy, dc.drawable, dc.gc,
+                      0, 0, mon->win_geom.w, bar_height);
+       return;
+}
+
 void drawbar(struct monitor *m)
 {
        int x;
@@ -1031,6 +1053,8 @@ void drawbar(struct monitor *m)
                }
        }
 
+       wipe_bar(m, m == selmon ? dc.sel : dc.norm);
+
        dc.geom.x = 0;
 
        for(i = 0; i < LENGTH(tags); i++) {
@@ -1048,9 +1072,13 @@ void drawbar(struct monitor *m)
        dc.geom.x += dc.geom.w;
        x = dc.geom.x;
 
+       /* x = end of the layout symbol */
+
        dc.geom.w = TEXTW(stext);
        dc.geom.x = m->win_geom.w - dc.geom.w;
 
+       /* dc.geom.x = start of the status text */
+
        if(dc.geom.x < x) {
                dc.geom.x = x;
                dc.geom.w = m->win_geom.w - x;
@@ -1058,18 +1086,6 @@ void drawbar(struct monitor *m)
 
        drawtext(stext, dc.norm, False);
 
-       if((dc.geom.w = dc.geom.x - x) > bar_height) {
-               dc.geom.x = x;
-
-               if(m->sel) {
-                       col = m == selmon ? dc.sel : dc.norm;
-                       /* drawtext(m->sel->name, col, False); */
-                       drawsquare(m->sel->isfixed, m->sel->isfloating, False, col);
-               } else {
-                       drawtext(NULL, dc.norm, False);
-               }
-       }
-
        XCopyArea(dpy, dc.drawable, m->barwin, dc.gc, 0, 0,
                  m->win_geom.w, bar_height, 0, 0);
        XSync(dpy, False);
@@ -1807,35 +1823,43 @@ void propertynotify(XEvent *e)
 {
         struct client *c;
        Window trans;
-       XPropertyEvent *ev = &e->xproperty;
+       XPropertyEvent *ev;
 
-       if((ev->window == root) && (ev->atom == XA_WM_NAME))
+       ev = &e->xproperty;
+
+       if((ev->window == root) && (ev->atom == XA_WM_NAME)) {
                updatestatus();
-       else if(ev->state == PropertyDelete)
+       } else if(ev->state == PropertyDelete) {
                return; /* ignore */
-       else if((c = wintoclient(ev->window))) {
+       else if((c = wintoclient(ev->window))) {
                switch(ev->atom) {
-               default: break;
+               default:
+                       break;
+
                case XA_WM_TRANSIENT_FOR:
                        if(!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
                           (c->isfloating = (wintoclient(trans)) != NULL))
                                arrange(c->mon);
                        break;
+
                case XA_WM_NORMAL_HINTS:
                        updatesizehints(c);
                        break;
+
                case XA_WM_HINTS:
                        updatewmhints(c);
                        drawbars();
                        break;
                }
+
                if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
                        updatetitle(c);
-                       if(c == c->mon->sel)
-                               drawbar(c->mon);
+                       drawbars();
                }
-               if(ev->atom == netatom[NetWMWindowType])
+
+               if(ev->atom == netatom[NetWMWindowType]) {
                        updatewindowtype(c);
+               }
        }
 
        return;
@@ -2993,7 +3017,8 @@ void updatestatus(void)
                strcpy(stext, "d "VERSION);
        }
 
-       drawbar(selmon);
+       drawbars();
+
        return;
 }