[wiki] [sites] [dwm][patch] for sticky patch; adds a bar icon for sticky windows || Timmy Keller

From: <git_AT_suckless.org>
Date: Tue, 02 Mar 2021 05:53:56 +0100

commit f0fb3102cdcae8f771e90750cc126718e2e85e9c
Author: Timmy Keller <applesrcol8796_AT_gmail.com>
Date: Mon Mar 1 22:53:01 2021 -0600

    [dwm][patch] for sticky patch; adds a bar icon for sticky windows

diff --git a/dwm.suckless.org/patches/stickyindicator/bmicon.jpg b/dwm.suckless.org/patches/stickyindicator/bmicon.jpg
new file mode 100644
index 00000000..7bef838e
Binary files /dev/null and b/dwm.suckless.org/patches/stickyindicator/bmicon.jpg differ
diff --git a/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-6.2.diff b/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-6.2.diff
new file mode 100644
index 00000000..148f54f4
--- /dev/null
+++ b/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-6.2.diff
_AT_@ -0,0 +1,66 @@
+diff -pu dwm.stickypatch/config.def.h dwm.stickyindicator/config.def.h
+--- dwm.stickypatch/config.def.h 2021-02-28 23:51:25.118904642 -0600
++++ dwm.stickyindicator/config.def.h 2021-03-01 19:39:53.190077064 -0600
+_AT_@ -17,6 +17,9 @@ static const char *colors[][3] = {
+ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+ [SchemeSel] = { col_gray4, col_cyan, col_cyan },
+ };
++static const XPoint stickyicon[] = { {0,0}, {4,0}, {4,4}, {2,3}, {0,4}, {0,0} }; /* represents the icon as an array of vertices like in grade school math */
++static const XPoint stickyiconbb = {4,4}; /* defines the bottom right corner of the bounding box of the polygon (origin is always 0,0) */
++#define STICKYICONSH boxw + (boxw * 6 / 7) /* defines the height of the final, scaled polygon as it will be drawn. boxw is equal to the width of the shape */
+
+ /* tagging */
+ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+diff -pu dwm.stickypatch/drw.c dwm.stickyindicator/drw.c
+--- dwm.stickypatch/drw.c 2021-02-28 23:51:06.992237482 -0600
++++ dwm.stickyindicator/drw.c 2021-03-01 20:35:20.470241455 -0600
+_AT_@ -248,6 +248,26 @@ drw_rect(Drw *drw, int x, int y, unsigne
+ XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
+ }
+
++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) /* wrapper function to scale and draw a polygon with X11 */
++{
++ if (!drw || !drw->scheme)
++ return;
++ XSetForeground(drw->dpy, drw->gc, drw->scheme[ColFg].pixel);
++ if (!filled) { /* reduces the scaled width and height by 1 when drawing the outline to compensate for X11 drawing the line 1 pixel over */
++ sw -= 1;
++ sh -= 1;
++ }
++ XPoint scaledpoints[npoints];
++ memcpy(scaledpoints, points, npoints);
++ for (int v = 0; v < npoints; v++)
++ scaledpoints[v] = (XPoint){ .x = points[v].x * sw / ow + x, .y = points[v].y * sh / oh + y };
++ if (filled)
++ XFillPolygon(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, shape, CoordModeOrigin);
++ else
++ XDrawLines(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, CoordModeOrigin);
++}
++
+ int
+ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
+ {
+diff -pu dwm.stickypatch/drw.h dwm.stickyindicator/drw.h
+--- dwm.stickypatch/drw.h 2021-02-28 23:51:06.992237482 -0600
++++ dwm.stickyindicator/drw.h 2021-03-01 01:34:02.739074730 -0600
+_AT_@ -51,6 +51,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
+
+ /* Drawing functions */
+ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
++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);
+ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
+
+ /* Map functions */
+diff -pu dwm.stickypatch/dwm.c dwm.stickyindicator/dwm.c
+--- dwm.stickypatch/dwm.c 2021-02-28 23:51:25.118904642 -0600
++++ dwm.stickyindicator/dwm.c 2021-03-01 20:30:34.940227293 -0600
+_AT_@ -736,6 +736,8 @@ drawbar(Monitor *m)
+ drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
+ if (m->sel->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
++ if (m->sel->issticky)
++ drw_polygon(drw, x + boxs, m->sel->isfloating ? boxs * 2 + boxw : boxs, stickyiconbb.x, stickyiconbb.y, boxw, STICKYICONSH, stickyicon, LENGTH(stickyicon), Nonconvex, m->sel->tags & m->tagset[m->seltags]);
+ } else {
+ drw_setscheme(drw, scheme[SchemeNorm]);
+ drw_rect(drw, x, 0, w, bh, 1, 1);
diff --git a/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-fancybarfix-6.2.diff b/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-fancybarfix-6.2.diff
new file mode 100644
index 00000000..197e4549
--- /dev/null
+++ b/dwm.suckless.org/patches/stickyindicator/dwm-stickyindicator-fancybarfix-6.2.diff
_AT_@ -0,0 +1,66 @@
+diff -pu dwm.fancybarpatch/config.def.h dwm.stickyindicator-fancybarfix/config.def.h
+--- dwm.fancybarpatch/config.def.h 2021-03-01 20:52:06.470291172 -0600
++++ dwm.stickyindicator-fancybarfix/config.def.h 2021-03-01 20:51:02.120287996 -0600
+_AT_@ -17,6 +17,9 @@ static const char *colors[][3] = {
+ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+ [SchemeSel] = { col_gray4, col_cyan, col_cyan },
+ };
++static const XPoint stickyicon[] = { {0,0}, {4,0}, {4,4}, {2,3}, {0,4}, {0,0} }; /* represents the icon as an array of vertices like in grade school math */
++static const XPoint stickyiconbb = {4,4}; /* defines the bottom right corner of the bounding box of the polygon (origin is always 0,0) */
++#define STICKYICONSH boxw + (boxw * 6 / 7) /* defines the height of the final, scaled polygon as it will be drawn. boxw is equal to the width of the shape */
+
+ /* tagging */
+ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
+diff -pu dwm.fancybarpatch/drw.c dwm.stickyindicator-fancybarfix/drw.c
+--- dwm.fancybarpatch/drw.c 2021-03-01 20:39:31.890253915 -0600
++++ dwm.stickyindicator-fancybarfix/drw.c 2021-03-01 20:45:59.293606357 -0600
+_AT_@ -248,6 +248,26 @@ drw_rect(Drw *drw, int x, int y, unsigne
+ XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
+ }
+
++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) /* wrapper function to scale and draw a polygon with X11 */
++{
++ if (!drw || !drw->scheme)
++ return;
++ XSetForeground(drw->dpy, drw->gc, drw->scheme[ColFg].pixel);
++ if (!filled) { /* reduces the scaled width and height by 1 when drawing the outline to compensate for X11 drawing the line 1 pixel over */
++ sw -= 1;
++ sh -= 1;
++ }
++ XPoint scaledpoints[npoints];
++ memcpy(scaledpoints, points, npoints);
++ for (int v = 0; v < npoints; v++)
++ scaledpoints[v] = (XPoint){ .x = points[v].x * sw / ow + x, .y = points[v].y * sh / oh + y };
++ if (filled)
++ XFillPolygon(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, shape, CoordModeOrigin);
++ else
++ XDrawLines(drw->dpy, drw->drawable, drw->gc, scaledpoints, npoints, CoordModeOrigin);
++}
++
+ int
+ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert)
+ {
+diff -pu dwm.fancybarpatch/drw.h dwm.stickyindicator-fancybarfix/drw.h
+--- dwm.fancybarpatch/drw.h 2021-03-01 20:39:31.890253915 -0600
++++ dwm.stickyindicator-fancybarfix/drw.h 2021-03-01 20:46:24.320274275 -0600
+_AT_@ -51,6 +51,7 @@ void drw_setscheme(Drw *drw, Clr *scm);
+
+ /* Drawing functions */
+ void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
++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);
+ int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
+
+ /* Map functions */
+diff -pu dwm.fancybarpatch/dwm.c dwm.stickyindicator-fancybarfix/dwm.c
+--- dwm.fancybarpatch/dwm.c 2021-03-01 20:52:06.470291172 -0600
++++ dwm.stickyindicator-fancybarfix/dwm.c 2021-03-01 20:47:17.293610226 -0600
+_AT_@ -760,6 +760,8 @@ drawbar(Monitor *m)
+ drw_text(drw, x, 0, tw, bh, lrpad / 2, c->name, 0);
+ if (c->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, c->isfixed, 0);
++ if (c->issticky)
++ drw_polygon(drw, x + boxs, c->isfloating ? boxs * 2 + boxw : boxs, stickyiconbb.x, stickyiconbb.y, boxw, STICKYICONSH, stickyicon, LENGTH(stickyicon), Nonconvex, c->tags & c->mon->tagset[c->mon->seltags]);
+ x += tw;
+ w -= tw;
+ }
diff --git a/dwm.suckless.org/patches/stickyindicator/index.md b/dwm.suckless.org/patches/stickyindicator/index.md
new file mode 100644
index 00000000..88394f4f
--- /dev/null
+++ b/dwm.suckless.org/patches/stickyindicator/index.md
_AT_@ -0,0 +1,41 @@
+functionalgaps
+==========
+
+Description
+-----------
+This is a patch for [sticky](../sticky) users who want an indicator in their bar when a window is sticky. The icon will appear underneath the floating icon, and is highly customizable. The shape is filled in when you are on the sticky window's original tag(s), and appears as an outline otherwise.
+
+[![Default icon](bmicon.jpg)](bmicon.jpg)
+* (All screenshots are shown with [fancybar](../fancybar) and [hidevacanttags](../hidevacanttags) for demonstration purposes)
+
+This patch draws the indicator icon as a polygon using an added wrapper to handle drawing scaled polygons with X11. Because of this, the little icon is very versitile (although, that doesn't mean you will get good results). In fact, the icon can be changed just by editing the vertices stored in `stickyicon[]` in the config file. Some examples of alternate icons are shown below.
+
+Default bookmark icon (looks by far the best on high and low-dpi displays)
+* `stickyicon[] = { {0,0}, {4,0}, {4,4}, {2,3}, {0,4}, {0,0} }; /* represents the icon as an array of vertices like in grade school math */`
+* `stickyiconbb = {4,4}; /* defines the bottom right corner of the bounding box of the polygon (origin is always 0,0) */`
+* `#define STICKYICONSH boxw + (boxw * 6 / 7) /* defines the height of the final, scaled polygon as it will be drawn. boxw is equal to the width of the shape */`
+
+'S' icon (only readable on high-dpi displays)
+* `stickyicon[] = { {4,0}, {0,0}, {0,4}, {3,4}, {3,6}, {0,6}, {0,7}, {4,7}, {4,3}, {1,3}, {1,1}, {4,1}, {4,0} };`
+* `stickyiconbb = {4,7};`
+* `#define STICKYICONSH boxw * 2`
+
+[![Bad 'S' icon](sicon.jpg)](sicon.jpg)
+
+Octogon icon
+* `static const XPoint stickyicon[] = { {1,0}, {2,0}, {3,1}, {3,2}, {2,3}, {1,3}, {0,2}, {0,1}, {1,0} };`
+* `static const XPoint stickyiconbb = {3,3};`
+* `#define STICKYICONSH boxw`
+
+[![Oct-i-con](octicon.jpg)](octicon.jpg)
+
+Tip: The size of the icon (and thus, its resolution) is controlled by the fontsize used in your config file (same behavior as the floating indicator icon). This patch also works very well on high-dpi displays since they can show the detail of the tiny icon better. Simple icons also tend to look far better than complex ones.
+
+Download
+--------
+* [dwm-stickyindicator-6.2.diff](dwm-stickyindicator-6.2.diff)
+* [dwm-stickyindicator-fancybarfix-6.2.diff](dwm-stickyindicator-fancybarfix-6.2.diff) (this fix is for fancybar users, since there is a small conflict)
+
+Author
+------
+* Timmy Keller <applesrcol8796_AT_gmail.com>
diff --git a/dwm.suckless.org/patches/stickyindicator/octicon.jpg b/dwm.suckless.org/patches/stickyindicator/octicon.jpg
new file mode 100644
index 00000000..c222977e
Binary files /dev/null and b/dwm.suckless.org/patches/stickyindicator/octicon.jpg differ
diff --git a/dwm.suckless.org/patches/stickyindicator/sicon.jpg b/dwm.suckless.org/patches/stickyindicator/sicon.jpg
new file mode 100644
index 00000000..9cd71a05
Binary files /dev/null and b/dwm.suckless.org/patches/stickyindicator/sicon.jpg differ
Received on Tue Mar 02 2021 - 05:53:56 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 02 2021 - 06:00:48 CET