dwm-stickyindicator-fancybarfix-6.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-stickyindicator-fancybarfix-6.2.diff (3585B)
       ---
            1 diff -pu dwm.fancybarpatch/config.def.h dwm.stickyindicator-fancybarfix/config.def.h
            2 --- dwm.fancybarpatch/config.def.h        2021-03-01 20:52:06.470291172 -0600
            3 +++ dwm.stickyindicator-fancybarfix/config.def.h        2021-03-15 21:12:57.823301478 -0500
            4 @@ -17,6 +17,8 @@ static const char *colors[][3]      = {
            5          [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
            6          [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
            7  };
            8 +static const XPoint stickyicon[]    = { {0,0}, {4,0}, {4,8}, {2,6}, {0,8}, {0,0} }; /* represents the icon as an array of vertices */
            9 +static const XPoint stickyiconbb    = {4,8};        /* defines the bottom right corner of the polygon's bounding box (speeds up scaling) */
           10  
           11  /* tagging */
           12  static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
           13 diff -pu dwm.fancybarpatch/drw.c dwm.stickyindicator-fancybarfix/drw.c
           14 --- dwm.fancybarpatch/drw.c        2021-03-01 20:39:31.890253915 -0600
           15 +++ dwm.stickyindicator-fancybarfix/drw.c        2021-03-15 21:13:39.643301192 -0500
           16 @@ -248,6 +248,26 @@ drw_rect(Drw *drw, int x, int y, unsigne
           17                  XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
           18  }
           19  
           20 +void
           21 +drw_polygon(Drw *drw, int x, int y, int ow, int oh, int sw, int sh, const XPoint *points, int npoints, int shape, int filled) /* wrapper function to scale and draw a polygon with X11 */
           22 +{
           23 +        if (!drw || !drw->scheme)
           24 +                return;
           25 +        XSetForeground(drw->dpy, drw->gc, drw->scheme[ColFg].pixel);
           26 +        if (!filled) { /* reduces the scaled width and height by 1 when drawing the outline to compensate for X11 drawing the line 1 pixel over */
           27 +                sw -= 1;
           28 +                sh -= 1;
           29 +        }
           30 +        XPoint scaledpoints[npoints];
           31 +        memcpy(scaledpoints, points, npoints);
           32 +        for (int v = 0; v < npoints; v++)
           33 +                scaledpoints[v] = (XPoint){ .x = points[v].x * sw / ow + x, .y = points[v].y * sh / oh + y };
           34 +        if (filled)
           35 +                XFillPolygon(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, shape, CoordModeOrigin); /* Change shape to 'Convex' or 'Complex' in dwm.c if the shape is not 'Nonconvex' */
           36 +        else
           37 +                XDrawLines(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, CoordModeOrigin);
           38 +}
           39 +
           40  int
           41  drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
           42  {
           43 diff -pu dwm.fancybarpatch/drw.h dwm.stickyindicator-fancybarfix/drw.h
           44 --- dwm.fancybarpatch/drw.h        2021-03-01 20:39:31.890253915 -0600
           45 +++ dwm.stickyindicator-fancybarfix/drw.h        2021-03-15 21:14:04.169967692 -0500
           46 @@ -51,6 +51,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
           47  
           48  /* Drawing functions */
           49  void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
           50 +void drw_polygon(Drw *drw, int x, int y, int ow, int oh, int sw, int sh, const XPoint *points, int npoints, int shape, int filled);
           51  int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
           52  
           53  /* Map functions */
           54 diff -pu dwm.fancybarpatch/dwm.c dwm.stickyindicator-fancybarfix/dwm.c
           55 --- dwm.fancybarpatch/dwm.c        2021-03-01 20:52:06.470291172 -0600
           56 +++ dwm.stickyindicator-fancybarfix/dwm.c        2021-03-15 21:16:48.056633227 -0500
           57 @@ -760,6 +760,8 @@ drawbar(Monitor *m)
           58                                          drw_text(drw, x, 0, tw, bh, lrpad / 2, c->name, 0);
           59                                  if (c->isfloating)
           60                                          drw_rect(drw, x + boxs, boxs, boxw, boxw, c->isfixed, 0);
           61 +                                if (c->issticky)
           62 +                                        drw_polygon(drw, x + boxs, c->isfloating ? boxs * 2 + boxw : boxs, stickyiconbb.x, stickyiconbb.y, boxw, boxw * stickyiconbb.y / stickyiconbb.x, stickyicon, LENGTH(stickyicon), Nonconvex, c->tags & c->mon->tagset[c->mon->seltags]);
           63                                  x += tw;
           64                                  w -= tw;
           65                          }