From 892341ae280eb6cd5f8ccd32f78407f459294f6f Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Sat, 9 Jul 2022 09:59:17 +0530 Subject: [PATCH 1/4] Add RGBA support --- config.def.h | 31 ------------------------------- dmenu.c | 9 --------- drw.c | 44 ++++++++++++++++++++++++++++++-------------- drw.h | 7 ++----- 4 files changed, 32 insertions(+), 59 deletions(-) diff --git a/config.def.h b/config.def.h index 84e984c..07affcf 100644 --- a/config.def.h +++ b/config.def.h @@ -51,37 +51,6 @@ static const char *symbol_1 = "<"; static const char *symbol_2 = ">"; #endif // SYMBOLS_PATCH -#if ALPHA_PATCH -static const unsigned int baralpha = 0xd0; -static const unsigned int borderalpha = OPAQUE; -static const unsigned int alphas[][3] = { - /* fg bg border */ - [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, - [SchemeSel] = { OPAQUE, baralpha, borderalpha }, - #if BORDER_PATCH - [SchemeBorder] = { OPAQUE, OPAQUE, OPAQUE }, - #endif // BORDER_PATCH - #if MORECOLOR_PATCH - [SchemeMid] = { OPAQUE, baralpha, borderalpha }, - #endif // MORECOLOR_PATCH - #if HIGHLIGHT_PATCH || FUZZYHIGHLIGHT_PATCH - [SchemeSelHighlight] = { OPAQUE, baralpha, borderalpha }, - [SchemeNormHighlight] = { OPAQUE, baralpha, borderalpha }, - #endif // HIGHLIGHT_PATCH | FUZZYHIGHLIGHT_PATCH - #if HIGHPRIORITY_PATCH - [SchemeHp] = { OPAQUE, baralpha, borderalpha }, - #endif // HIGHPRIORITY_PATCH - #if EMOJI_HIGHLIGHT_PATCH - [SchemeHover] = { OPAQUE, baralpha, borderalpha }, - [SchemeGreen] = { OPAQUE, baralpha, borderalpha }, - [SchemeRed] = { OPAQUE, baralpha, borderalpha }, - [SchemeYellow] = { OPAQUE, baralpha, borderalpha }, - [SchemeBlue] = { OPAQUE, baralpha, borderalpha }, - [SchemePurple] = { OPAQUE, baralpha, borderalpha }, - #endif // EMOJI_HIGHLIGHT_PATCH -}; -#endif // ALPHA_PATCH - static #if !XRESOURCES_PATCH const diff --git a/dmenu.c b/dmenu.c index 7990a3b..27d9d7e 100644 --- a/dmenu.c +++ b/dmenu.c @@ -50,7 +50,6 @@ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) #endif // PANGO_PATCH #if ALPHA_PATCH -#define OPAQUE 0xffU #define OPACITY "_NET_WM_WINDOW_OPACITY" #endif // ALPHA_PATCH @@ -1529,18 +1528,10 @@ setup(void) /* init appearance */ #if XRESOURCES_PATCH for (j = 0; j < SchemeLast; j++) - #if ALPHA_PATCH - scheme[j] = drw_scm_create(drw, (const char**)colors[j], alphas[j], 2); - #else scheme[j] = drw_scm_create(drw, (const char**)colors[j], 2); - #endif // ALPHA_PATCH #else for (j = 0; j < SchemeLast; j++) - #if ALPHA_PATCH - scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2); - #else scheme[j] = drw_scm_create(drw, colors[j], 2); - #endif // ALPHA_PATCH #endif // XRESOURCES_PATCH clip = XInternAtom(dpy, "CLIPBOARD", False); diff --git a/drw.c b/drw.c index a9c2916..b0b0832 100644 --- a/drw.c +++ b/drw.c @@ -18,6 +18,30 @@ static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8} static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; +#if ALPHA_PATCH +unsigned short +hextodec(const char *hex) +{ + if (hex[0] == 0) + return 0xff; + + unsigned short dec = 0; + for (int i = 0; i < 2; i++) { + char digit = hex[i]; + if (digit >= '0' && digit <= '9') + digit -= '0'; + else if (digit >= 'a' && digit <= 'f') + digit += 10 - 'a'; + else if (digit >= 'A' && digit <= 'F') + digit += 10 - 'A'; + else + digit = 0; + dec = (dec << 4) + digit; + } + return dec; +} +#endif // ALPHA_PATCH + static long utf8decodebyte(const char c, size_t *i) { @@ -284,20 +308,20 @@ drw_fontset_free(Fnt *font) #endif // PANGO_PATCH void -#if ALPHA_PATCH -drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha) -#else drw_clr_create(Drw *drw, Clr *dest, const char *clrname) -#endif // ALPHA_PATCH { if (!drw || !dest || !clrname) return; #if ALPHA_PATCH + char color[8]; + strncpy(color, clrname, 7); + color[7] = 0; if (!XftColorAllocName(drw->dpy, drw->visual, drw->cmap, - clrname, dest)) - die("error, cannot allocate color '%s'", clrname); + color, dest)) + die("error, cannot allocate color '%s'", color); + unsigned short alpha = hextodec(clrname + 7); dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); #else if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), @@ -310,11 +334,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) /* Wrapper to create color schemes. The caller has to call free(3) on the * returned color scheme when done using it. */ Clr * -#if ALPHA_PATCH -drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount) -#else drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) -#endif // ALPHA_PATCH { size_t i; Clr *ret; @@ -324,11 +344,7 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) return NULL; for (i = 0; i < clrcount; i++) - #if ALPHA_PATCH - drw_clr_create(drw, &ret[i], clrnames[i], alphas[i]); - #else drw_clr_create(drw, &ret[i], clrnames[i]); - #endif // ALPHA_PATCH return ret; } diff --git a/drw.h b/drw.h index af4af4d..ff1bb20 100644 --- a/drw.h +++ b/drw.h @@ -44,6 +44,8 @@ typedef struct { #endif // PANGO_PATCH } Drw; +unsigned short hextodec(const char *hex); + /* Drawable abstraction */ #if ALPHA_PATCH Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); @@ -69,13 +71,8 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in #endif // PANGO_PATCH /* Colorscheme abstraction */ -#if ALPHA_PATCH -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname, unsigned int alpha); -Clr *drw_scm_create(Drw *drw, const char *clrnames[], const unsigned int alphas[], size_t clrcount); -#else void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); -#endif // ALPHA_PATCH /* Cursor abstraction */ Cur *drw_cur_create(Drw *drw, int shape); From 5bbbc87e2a278268c10fc68eb930a895cb871a59 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Thu, 16 Feb 2023 11:06:30 +0530 Subject: [PATCH 2/4] Switch to strtol for hex conversion --- drw.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/drw.c b/drw.c index b0b0832..1ab9a14 100644 --- a/drw.c +++ b/drw.c @@ -18,30 +18,6 @@ static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8} static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; -#if ALPHA_PATCH -unsigned short -hextodec(const char *hex) -{ - if (hex[0] == 0) - return 0xff; - - unsigned short dec = 0; - for (int i = 0; i < 2; i++) { - char digit = hex[i]; - if (digit >= '0' && digit <= '9') - digit -= '0'; - else if (digit >= 'a' && digit <= 'f') - digit += 10 - 'a'; - else if (digit >= 'A' && digit <= 'F') - digit += 10 - 'A'; - else - digit = 0; - dec = (dec << 4) + digit; - } - return dec; -} -#endif // ALPHA_PATCH - static long utf8decodebyte(const char c, size_t *i) { @@ -321,7 +297,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) color, dest)) die("error, cannot allocate color '%s'", color); - unsigned short alpha = hextodec(clrname + 7); + unsigned short alpha = (unsigned short) strtol(clrname + 7, NULL, 16); dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); #else if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), From 23cc338e2303a935d09de2215fffbba50e6adbca Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Thu, 16 Feb 2023 16:42:22 +0530 Subject: [PATCH 3/4] Handle #rrggbb values properly --- drw.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drw.c b/drw.c index 1ab9a14..9848aac 100644 --- a/drw.c +++ b/drw.c @@ -297,7 +297,11 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) color, dest)) die("error, cannot allocate color '%s'", color); - unsigned short alpha = (unsigned short) strtol(clrname + 7, NULL, 16); + + unsigned short alpha = 0xff; + if (clrname[7]) + alpha = (unsigned short) strtol(clrname + 7, NULL, 16); + dest->pixel = (dest->pixel & 0x00ffffffU) | (alpha << 24); #else if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), From a3bae8c5bf3597402932bdc09be3d6895c0ac1d8 Mon Sep 17 00:00:00 2001 From: Utkarsh Verma Date: Sun, 19 Feb 2023 11:16:08 +0530 Subject: [PATCH 4/4] Remove dangling function definition --- drw.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drw.h b/drw.h index ff1bb20..81bca87 100644 --- a/drw.h +++ b/drw.h @@ -44,8 +44,6 @@ typedef struct { #endif // PANGO_PATCH } Drw; -unsigned short hextodec(const char *hex); - /* Drawable abstraction */ #if ALPHA_PATCH Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h, Visual *visual, unsigned int depth, Colormap cmap); @@ -97,4 +95,4 @@ void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) #if SCROLL_PATCH #include "patch/scroll.h" -#endif \ No newline at end of file +#endif