commit 14423ee9786f546d1a8688070ff06640171138df
Author: Dave Kennedy <[email protected]>
Date:   Sat Nov 28 13:54:07 2015 -0700

    Fixed bug in width calculation

diff --git a/dwm.suckless.org/patches/dwm-6.1-statuscolors.diff 
b/dwm.suckless.org/patches/dwm-6.1-statuscolors.diff
index a266add..d841712 100644
--- a/dwm.suckless.org/patches/dwm-6.1-statuscolors.diff
+++ b/dwm.suckless.org/patches/dwm-6.1-statuscolors.diff
@@ -1,9 +1,48 @@
 diff -up dwm/drw.c dwm-statuscolors/drw.c
 --- dwm/drw.c  2015-11-08 15:39:37.000000000 -0700
-+++ dwm-statuscolors/drw.c     2015-11-24 00:43:15.735118401 -0700
-@@ -207,11 +207,35 @@ drw_setscheme(Drw *drw, ClrScheme *schem
++++ dwm-statuscolors/drw.c     2015-11-28 13:47:09.814892374 -0700
+@@ -206,12 +206,74 @@ drw_setscheme(Drw *drw, ClrScheme *schem
+       drw->scheme = scheme;
  }
  
++int
++drw_get_width(Drw *drw, int numcolors, const char *text)
++{
++      int i;
++      Fnt *curfont = drw->fonts[0];
++      int w = drw_text(drw, 0, 0, 0, 0, text) + curfont->h;
++
++      for (i = 0; i < strlen(text); i++) {
++              if (text[i] > 0 && text[i] <= numcolors) {
++                      /* we found a color code
++                       * drw_text counted it as a normal character and added 
one character's width
++                       * we aren't going to render this character, so we 
remove one character's width */
++                      w -= curfont->xfont->max_advance_width;
++
++                      if (i == 0 || i + 1 == strlen(text)) {
++                              /* we're on the first or the last character of 
the string
++                               * drw_text already added one character's 
height (divided by 2) as padding to the beginning and end
++                               * we don't want to double this padding, so we 
skip this character */
++                              continue;
++                      }
++
++                      if (text[i - 1] > 0 && text[i - 1] <= numcolors) {
++                              /* the previous character was also a color code
++                               * we already added padding in the previous 
iteration
++                               * we don't want to double this padding, so we 
skip this character */
++                              continue;
++                      }
++
++                      /* we are somewhere in the middle of the string and the 
color has changed
++                       * we want to add one character's height (divided by 2) 
as padding to the end of the previous colored text
++                       * and to the beginning of the new colored text */
++                      w += curfont->h;
++              }
++      }
++
++  return w;
++}
++
 +void
 +drw_colored_text(Drw *drw, ClrScheme *scheme, int numcolors, int x, int y, 
unsigned int w, unsigned int h, char *text)
 +{
@@ -39,7 +78,7 @@ diff -up dwm/drw.c dwm-statuscolors/drw.c
        if (filled)
                XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w + 1, h 
+ 1);
        else if (empty)
-@@ -219,7 +243,7 @@ drw_rect(Drw *drw, int x, int y, unsigne
+@@ -219,7 +281,7 @@ drw_rect(Drw *drw, int x, int y, unsigne
  }
  
  int
@@ -48,7 +87,7 @@ diff -up dwm/drw.c dwm-statuscolors/drw.c
  {
        char buf[1024];
        int tx, ty, th;
-@@ -242,8 +266,7 @@ drw_text(Drw *drw, int x, int y, unsigne
+@@ -242,8 +304,7 @@ drw_text(Drw *drw, int x, int y, unsigne
        if (!(render = x || y || w || h)) {
                w = ~w;
        } else {
@@ -58,7 +97,7 @@ diff -up dwm/drw.c dwm-statuscolors/drw.c
                XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
                d = XftDrawCreate(drw->dpy, drw->drawable,
                                  DefaultVisual(drw->dpy, drw->screen),
-@@ -292,7 +315,7 @@ drw_text(Drw *drw, int x, int y, unsigne
+@@ -292,7 +353,7 @@ drw_text(Drw *drw, int x, int y, unsigne
                                        th = curfont->ascent + curfont->descent;
                                        ty = y + (h / 2) - (th / 2) + 
curfont->ascent;
                                        tx = x + (h / 2);
@@ -69,13 +108,14 @@ diff -up dwm/drw.c dwm-statuscolors/drw.c
                                w -= tex.w;
 diff -up dwm/drw.h dwm-statuscolors/drw.h
 --- dwm/drw.h  2015-11-08 15:39:37.000000000 -0700
-+++ dwm-statuscolors/drw.h     2015-11-24 00:43:15.735118401 -0700
-@@ -67,8 +67,9 @@ void drw_setfont(Drw *, Fnt *);
++++ dwm-statuscolors/drw.h     2015-11-28 13:47:26.411558366 -0700
+@@ -67,8 +67,10 @@ void drw_setfont(Drw *, Fnt *);
  void drw_setscheme(Drw *, ClrScheme *);
  
  /* Drawing functions */
 -void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int, int);
 -int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *, int);
++int drw_get_width(Drw *, int, const char *);
 +void drw_colored_text(Drw *, ClrScheme *, int, int, int, unsigned int, 
unsigned int, char *);
 +void drw_rect(Drw *, int, int, unsigned int, unsigned int, int, int);
 +int drw_text(Drw *, int, int, unsigned int, unsigned int, const char *);
@@ -84,7 +124,7 @@ diff -up dwm/drw.h dwm-statuscolors/drw.h
  void drw_map(Drw *, Window, int, int, unsigned int, unsigned int);
 diff -up dwm/dwm.c dwm-statuscolors/dwm.c
 --- dwm/dwm.c  2015-11-08 15:39:37.000000000 -0700
-+++ dwm-statuscolors/dwm.c     2015-11-24 00:43:15.735118401 -0700
++++ dwm-statuscolors/dwm.c     2015-11-28 13:44:22.744899168 -0700
 @@ -51,11 +51,12 @@
                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - 
MAX((y),(m)->wy)))
  #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
@@ -108,7 +148,7 @@ diff -up dwm/dwm.c dwm-statuscolors/dwm.c
  static Display *dpy;
  static Drw *drw;
  static Monitor *mons, *selmon;
-@@ -718,15 +719,15 @@ drawbar(Monitor *m)
+@@ -718,36 +719,36 @@ drawbar(Monitor *m)
        x = 0;
        for (i = 0; i < LENGTH(tags); i++) {
                w = TEXTW(tags[i]);
@@ -129,7 +169,10 @@ diff -up dwm/dwm.c dwm-statuscolors/dwm.c
        x += w;
        xx = x;
        if (m == selmon) { /* status is only drawn on selected monitor */
-@@ -736,18 +737,18 @@ drawbar(Monitor *m)
+-              w = TEXTW(stext);
++              w = drw_get_width(drw, NUMCOLORS, stext);
+               x = m->ww - w;
+               if (x < xx) {
                        x = xx;
                        w = m->ww - xx;
                }


Reply via email to