From e79aec52c28af424adf4b31ff5d4504303c61383 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Tue, 26 May 2020 20:53:53 +0200 Subject: [PATCH] Adding status2d patch --- README.md | 7 ++- config.def.h | 14 ++--- drw.h | 4 +- dwm.c | 46 ++++++++++++----- patch/include.c | 3 ++ patch/include.h | 3 ++ patch/status2d.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ patch/status2d.h | 1 + patch/statuscmd.c | 4 ++ patches.def.h | 13 +++++ 10 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 patch/status2d.c create mode 100644 patch/status2d.h diff --git a/README.md b/README.md index fedd68e..36b1c71 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-05-26 - Added the status2d patch (with alpha, systray, statuspadding and dwmblocks compatibility, no statuscolors or extrabar compatibility) + 2020-05-21 - Added the moveplace and moveresize patches 2020-05-03 - Added the shiftviewclients patch and the no transparent borders patch which removes opacity from window borders when the alpha patch is not used @@ -347,7 +349,10 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t - provides comprehensive utilities for managing the client stack - [statuscmd](https://dwm.suckless.org/patches/statuscmd/) - - adds the ability to execute shell commands based on the mouse button and position when clicking the status bar + - adds the ability to execute shell commands based on the mouse button and position when clicking the status bar + + - [status2d](https://dwm.suckless.org/patches/status2d/) + - allows colors and rectangle drawing in the dwm status bar - [statusallmons](https://dwm.suckless.org/patches/statuspadding/) - this patch draws and updates the statusbar on all monitors diff --git a/config.def.h b/config.def.h index bbb9ccb..2483f20 100644 --- a/config.def.h +++ b/config.def.h @@ -105,7 +105,7 @@ static char titlefloatcolor[] = "#005577"; static const unsigned int baralpha = 0xd0; static const unsigned int borderalpha = OPAQUE; static const unsigned int alphas[][3] = { - /* fg bg border */ + /* fg bg border */ [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, [SchemeSel] = { OPAQUE, baralpha, borderalpha }, #if STATUSCOLORS_PATCH @@ -131,7 +131,7 @@ static const unsigned int alphas[][3] = { #if VTCOLORS_PATCH && FLOAT_BORDER_COLOR_PATCH static const char title_bg_dark[] = "#303030"; static const char title_bg_light[] = "#fdfdfd"; -static const int color_ptrs[][4] = { +static const int color_ptrs[][ColCount] = { /* fg bg border float */ [SchemeNorm] = { -1, -1, 5, 12 }, [SchemeSel] = { -1, -1, 11, 13 }, @@ -150,7 +150,7 @@ static const int color_ptrs[][4] = { [SchemeTitleSel] = { 6, -1, -1, -1 }, [SchemeStatus] = { 2, 0, 0, -1 }, }; -static char colors[][4][8] = { +static char colors[][ColCount][8] = { /* fg bg border float */ [SchemeNorm] = { "#000000", "#000000", "#000000", "#000000" }, [SchemeSel] = { "#000000", "#000000", "#000000", "#000000" }, @@ -172,7 +172,7 @@ static char colors[][4][8] = { #elif VTCOLORS_PATCH static const char title_bg_dark[] = "#303030"; static const char title_bg_light[] = "#fdfdfd"; -static const int color_ptrs[][3] = { +static const int color_ptrs[][ColCount] = { /* fg bg border */ [SchemeNorm] = { -1, -1, 5 }, [SchemeSel] = { -1, -1, 11 }, @@ -191,7 +191,7 @@ static const int color_ptrs[][3] = { [SchemeTitleSel] = { 6, -1, -1 }, [SchemeStatus] = { 2, 0, 0 }, }; -static char colors[][3][8] = { +static char colors[][ColCount][8] = { /* fg bg border */ [SchemeNorm] = { "#000000", "#000000", "#000000" }, [SchemeSel] = { "#000000", "#000000", "#000000" }, @@ -215,7 +215,7 @@ static #if !XRDB_PATCH const #endif // XRDB_PATCH -char *colors[][4] = { +char *colors[][ColCount] = { /* fg bg border float */ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor, normfloatcolor }, [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor, selfloatcolor }, @@ -237,7 +237,7 @@ static #if !XRDB_PATCH const #endif // XRDB_PATCH -char *colors[][3] = { +char *colors[][ColCount] = { /* fg bg border */ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, diff --git a/drw.h b/drw.h index 13a74d2..e3934f2 100644 --- a/drw.h +++ b/drw.h @@ -13,9 +13,9 @@ typedef struct Fnt { } Fnt; #if FLOAT_BORDER_COLOR_PATCH -enum { ColFg, ColBg, ColBorder, ColFloat }; /* Clr scheme index */ +enum { ColFg, ColBg, ColBorder, ColFloat, ColCount }; /* Clr scheme index */ #else -enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ +enum { ColFg, ColBg, ColBorder, ColCount }; /* Clr scheme index */ #endif // FLOAT_BORDER_COLOR_PATCH typedef XftColor Clr; diff --git a/dwm.c b/dwm.c index d665066..17c95fd 100644 --- a/dwm.c +++ b/dwm.c @@ -435,9 +435,17 @@ static void zoom(const Arg *arg); /* variables */ static const char broken[] = "broken"; +#if STATUS2D_PATCH && !STATUSCOLORS_PATCH +static char stext[1024]; +#else static char stext[256]; +#endif // STATUS2D_PATCH #if EXTRABAR_PATCH +#if STATUS2D_PATCH && !STATUSCOLORS_PATCH +static char estext[1024]; +#else static char estext[256]; +#endif // STATUS2D_PATCH #endif // EXTRABAR_PATCH static int screen; static int sw, sh; /* X display screen geometry width, height */ @@ -1002,7 +1010,11 @@ cleanup(void) #endif // SYSTRAY_PATCH for (i = 0; i < CurLast; i++) drw_cur_free(drw, cursor[i]); + #if STATUS2D_PATCH && !STATUSCOLORS_PATCH + for (i = 0; i < LENGTH(colors) + 1; i++) + #else for (i = 0; i < LENGTH(colors); i++) + #endif // STATUS2D_PATCH free(scheme[i]); free(scheme); XDestroyWindow(dpy, wmcheckwin); @@ -1490,11 +1502,7 @@ drawbar(Monitor *m) #if SYSTRAY_PATCH if (showsystray && m == systraytomon(m)) - #if BARPADDING_PATCH - stw = getsystraywidth() + 2 * sp; - #else - stw = getsystraywidth(); - #endif // BARPADDING_PATCH + stw += getsystraywidth(); #endif // SYSTRAY_PATCH /* draw status first so it can be overdrawn by tags later */ @@ -1520,13 +1528,15 @@ drawbar(Monitor *m) ctmp = *ts; *ts = '\0'; drw_text(drw, m->ww - tw - stw + tx, 0, tw - tx, bh, stp, tp, 0); - tx += TEXTW(tp) -lrpad; + tx += TEXTW(tp) - lrpad; if (ctmp == '\0') break; drw_setscheme(drw, scheme[(unsigned int)(ctmp-1)]); *ts = ctmp; tp = ++ts; } + #elif STATUS2D_PATCH + tw = m->ww - drawstatusbar(m, bh, stext, stw, stp); #else // STATUSCOLORS_PATCH #if STATUSPADDING_PATCH tw = TEXTW(stext); @@ -3074,18 +3084,22 @@ setup(void) strcpy(colors[SchemeTitleSel][ColBg], title_bg_dark); } #endif // VTCOLORS_PATCH + #if STATUS2D_PATCH && !STATUSCOLORS_PATCH + scheme = ecalloc(LENGTH(colors) + 1, sizeof(Clr *)); + #if ALPHA_PATCH + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], alphas[0], ColCount); + #else + scheme[LENGTH(colors)] = drw_scm_create(drw, colors[0], ColCount); + #endif // ALPHA_PATCH | FLOAT_BORDER_COLOR_PATCH + #else scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); + #endif // STATUS2D_PATCH for (i = 0; i < LENGTH(colors); i++) - scheme[i] = drw_scm_create(drw, colors[i], #if ALPHA_PATCH - alphas[i], - #endif // ALPHA_PATCH - #if FLOAT_BORDER_COLOR_PATCH - 4 + scheme[i] = drw_scm_create(drw, colors[i], alphas[i], ColCount); #else - 3 - #endif // FLOAT_BORDER_COLOR_PATCH - ); + scheme[i] = drw_scm_create(drw, colors[i], ColCount); + #endif // ALPHA_PATCH #if SYSTRAY_PATCH /* init system tray */ if (showsystray) @@ -3907,7 +3921,11 @@ updatestatus(void) Monitor* m; #endif // STATUSALLMONS_PATCH #if EXTRABAR_PATCH + #if STATUS2D_PATCH + char text[1024]; + #else char text[512]; + #endif // STATUS2D_PATCH if (!gettextprop(root, XA_WM_NAME, text, sizeof(text))) { strcpy(stext, "dwm-"VERSION); estext[0] = '\0'; diff --git a/patch/include.c b/patch/include.c index dc516fe..5113dc6 100644 --- a/patch/include.c +++ b/patch/include.c @@ -122,6 +122,9 @@ #if STACKER_PATCH #include "stacker.c" #endif +#if STATUS2D_PATCH && !STATUSCOLORS_PATCH +#include "status2d.c" +#endif #if STATUSCOLORS_PATCH #include "statuscolors.c" #endif diff --git a/patch/include.h b/patch/include.h index 5164236..bb0197d 100644 --- a/patch/include.h +++ b/patch/include.h @@ -125,6 +125,9 @@ #if STACKER_PATCH #include "stacker.h" #endif +#if STATUS2D_PATCH && !STATUSCOLORS_PATCH +#include "status2d.h" +#endif #if STATUSCMD_PATCH #include "statuscmd.h" #endif diff --git a/patch/status2d.c b/patch/status2d.c new file mode 100644 index 0000000..1ab9043 --- /dev/null +++ b/patch/status2d.c @@ -0,0 +1,128 @@ +int +drawstatusbar(Monitor *m, int bh, char* stext, int stw, int stp) +{ + int ret, i, w, x, len; + short isCode = 0; + char *text; + char *p; + + len = strlen(stext) + 1 ; + if (!(text = (char*) malloc(sizeof(char)*len))) + die("malloc"); + p = text; + memcpy(text, stext, len); + + /* compute width of the status text */ + w = stp * 2;; + i = -1; + while (text[++i]) { + if (text[i] == '^') { + if (!isCode) { + isCode = 1; + text[i] = '\0'; + w += TEXTW(text) - lrpad; + text[i] = '^'; + if (text[++i] == 'f') + w += atoi(text + ++i); + } else { + isCode = 0; + text = text + i + 1; + i = -1; + } + } + } + if (!isCode) + w += TEXTW(text) - lrpad; + else + isCode = 0; + text = p; + w += 2; /* 1px padding on both sides */ + x = m->ww - w - stw + stp; + ret = m->ww - w; + + drw_setscheme(drw, scheme[LENGTH(colors)]); + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; + drw_rect(drw, x - stp - 1, 0, w, bh, 1, 1); + x++; + + /* process status text */ + i = -1; + while (text[++i]) { + if (text[i] == '^' && !isCode) { + isCode = 1; + + text[i] = '\0'; + w = TEXTW(text) - lrpad; + drw_text(drw, x, 0, w, bh, 0, text, 0); + + x += w; + + /* process code */ + while (text[++i] != '^') { + if (text[i] == 'c') { + char buf[8]; + if (i + 7 > len) { + i += 7; + break; + } + memcpy(buf, (char*)text+i+1, 7); + buf[7] = '\0'; + #if ALPHA_PATCH && STATUS2D_NO_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColFg], buf, 0xff); + #elif ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColFg], buf, alphas[SchemeNorm][ColFg]); + #else + drw_clr_create(drw, &drw->scheme[ColFg], buf); + #endif // ALPHA_PATCH + i += 7; + } else if (text[i] == 'b') { + char buf[8]; + if (i + 7 > len) { + i += 7; + break; + } + memcpy(buf, (char*)text+i+1, 7); + buf[7] = '\0'; + #if ALPHA_PATCH && STATUS2D_NO_ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColBg], buf, 0xff); + #elif ALPHA_PATCH + drw_clr_create(drw, &drw->scheme[ColBg], buf, alphas[SchemeNorm][ColBg]); + #else + drw_clr_create(drw, &drw->scheme[ColBg], buf); + #endif // ALPHA_PATCH + i += 7; + } else if (text[i] == 'd') { + drw->scheme[ColFg] = scheme[SchemeNorm][ColFg]; + drw->scheme[ColBg] = scheme[SchemeNorm][ColBg]; + } else if (text[i] == 'r') { + int rx = atoi(text + ++i); + while (text[++i] != ','); + int ry = atoi(text + ++i); + while (text[++i] != ','); + int rw = atoi(text + ++i); + while (text[++i] != ','); + int rh = atoi(text + ++i); + + drw_rect(drw, rx + x, ry, rw, rh, 1, 0); + } else if (text[i] == 'f') { + x += atoi(text + ++i); + } + } + + text = text + i + 1; + i=-1; + isCode = 0; + } + } + + if (!isCode) { + w = TEXTW(text) - lrpad; + drw_text(drw, x, 0, w, bh, 0, text, 0); + } + + drw_setscheme(drw, scheme[SchemeNorm]); + free(p); + + return ret; +} \ No newline at end of file diff --git a/patch/status2d.h b/patch/status2d.h new file mode 100644 index 0000000..af9c0ed --- /dev/null +++ b/patch/status2d.h @@ -0,0 +1 @@ +static int drawstatusbar(Monitor *m, int bh, char* text, int stw, int stp); \ No newline at end of file diff --git a/patch/statuscmd.c b/patch/statuscmd.c index bddd529..ddb0c87 100644 --- a/patch/statuscmd.c +++ b/patch/statuscmd.c @@ -1,4 +1,8 @@ +#if STATUS2D_PATCH +static char rawstext[1024]; +#else static char rawstext[256]; +#endif // STATUS2D_PATCH #if !DWMBLOCKS_PATCH static const char statusexport[] = "export BUTTON=-;"; static int statuscmdn; diff --git a/patches.def.h b/patches.def.h index 7b8a1bb..873a81a 100644 --- a/patches.def.h +++ b/patches.def.h @@ -495,6 +495,18 @@ */ #define STACKER_PATCH 0 +/* Status2d allows colors and rectangle drawing in the dwm status bar. + * This patch is incompatible with the statuscolors patch which takes precedence. + * This patch is incompatible with the extrabar patch. + * NB: If using this with dwmblocks then make sure to increase CMDLENGTH in dwmblocks.c + * from 50 (default) to 1024. + * https://dwm.suckless.org/patches/status2d/ + */ +#define STATUS2D_PATCH 0 + +/* Supplementary patch should you want to disable alpha for the status2d section */ +#define STATUS2D_NO_ALPHA_PATCH 0 + /* This patch draws and updates the statusbar on all monitors. * https://dwm.suckless.org/patches/statusallmons/ */ @@ -502,6 +514,7 @@ /* This patch enables colored text in the status bar. It changes the way colors are defined * in config.h allowing multiple color combinations for use in the status script. + * This patch is incompatible with and takes precedence over the status2d patch. * https://dwm.suckless.org/patches/statuscolors/ */ #define STATUSCOLORS_PATCH 0