From f8f67508d811e3ad92f159d5101e2da89e269e37 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Sun, 15 Sep 2019 22:45:22 +0200 Subject: [PATCH] Adding xrdb patch --- config.def.h | 69 ++++++++++++++++++++++++++++++++------------- drw.c | 18 ++++++++---- drw.h | 27 +++++++++++++----- dwm.c | 5 ++++ patch/include.c | 4 +++ patch/include.h | 8 ++++++ patch/xrdb.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ patch/xrdb.h | 21 ++++++++++++++ patches.h | 5 ++++ 9 files changed, 200 insertions(+), 32 deletions(-) create mode 100644 patch/xrdb.c create mode 100644 patch/xrdb.h diff --git a/config.def.h b/config.def.h index 8a26760..fc5b9f9 100644 --- a/config.def.h +++ b/config.def.h @@ -24,11 +24,39 @@ static const int showsystray = 1; /* 0 means no systray */ #endif // SYSTRAY_PATCH static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; -static const char col_gray1[] = "#222222"; -static const char col_gray2[] = "#444444"; -static const char col_gray3[] = "#bbbbbb"; -static const char col_gray4[] = "#eeeeee"; -static const char col_cyan[] = "#005577"; + +static char normfgcolor[] = "#bbbbbb"; +static char normbgcolor[] = "#222222"; +static char normbordercolor[] = "#444444"; +#if FLOAT_BORDER_COLOR_PATCH +static char normflcolor[] = "#db8fd9"; +#endif // FLOAT_BORDER_COLOR_PATCH + +static char selfgcolor[] = "#eeeeee"; +static char selbgcolor[] = "#005577"; +static char selbordercolor[] = "#005577"; +#if FLOAT_BORDER_COLOR_PATCH +static char selflcolor[] = "#005577"; +#endif // FLOAT_BORDER_COLOR_PATCH + +#if AWESOMEBAR_PATCH +static char hidfgcolor[] = "#005577"; +static char hidbgcolor[] = "#222222"; +static char hidbordercolor[] = "#005577"; +#if FLOAT_BORDER_COLOR_PATCH +static char hidflcolor[] = "#f76e0c"; +#endif // FLOAT_BORDER_COLOR_PATCH +#endif // AWESOMEBAR_PATCH + +#if TITLECOLOR_PATCH +static char titlefgcolor[] = "#eeeeee"; +static char titlebgcolor[] = "#005577"; +static char titlebordercolor[] = "#005577"; +#if FLOAT_BORDER_COLOR_PATCH +static char titleflcolor[] = "#005577"; +#endif // FLOAT_BORDER_COLOR_PATCH +#endif // TITLECOLOR_PATCH + #if ALPHA_PATCH static const unsigned int baralpha = 0xd0; static const unsigned int borderalpha = OPAQUE; @@ -36,7 +64,7 @@ static const unsigned int alphas[][3] = { /* fg bg border */ [SchemeNorm] = { OPAQUE, baralpha, borderalpha }, [SchemeSel] = { OPAQUE, baralpha, borderalpha }, - #if AWESOMEBA R_PATCH + #if AWESOMEBAR_PATCH [SchemeHid] = { OPAQUE, baralpha, borderalpha }, #endif // AWESOMEBAR_PATCH #if TITLECOLOR_PATCH @@ -45,27 +73,27 @@ static const unsigned int alphas[][3] = { }; #endif // ALPHA_PATCH #if FLOAT_BORDER_COLOR_PATCH -static const char *colors[][4] = { - /* fg bg border float */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan, col_cyan }, +static char *colors[][4] = { + /* fg bg border float */ + [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor, normflcolor }, + [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor, selflcolor }, #if AWESOMEBAR_PATCH - [SchemeHid] = { col_cyan, col_gray1, col_cyan, col_cyan }, + [SchemeHid] = { hidfgcolor, hidbgcolor, hidbordercolor, hidflcolor }, #endif // AWESOMEBAR_PATCH #if TITLECOLOR_PATCH - [SchemeTitle] = { col_gray4, col_cyan, col_cyan, col_cyan }, + [SchemeTitle] = { titlefgcolor, titlebgcolor, titlebordercolor, titleflcolor }, #endif // TITLECOLOR_PATCH }; #else -static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, +static char *colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, + [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, #if AWESOMEBAR_PATCH - [SchemeHid] = { col_cyan, col_gray1, col_cyan }, + [SchemeHid] = { hidfgcolor, hidbgcolor, hidbordercolor }, #endif // AWESOMEBAR_PATCH #if TITLECOLOR_PATCH - [SchemeTitle] = { col_gray4, col_cyan, col_cyan }, + [SchemeTitle] = { titlefgcolor, titlebgcolor, titlebordercolor }, #endif // TITLECOLOR_PATCH }; #endif // FLOAT_BORDER_COLOR_PATCH @@ -221,7 +249,7 @@ static const Layout layouts[] = { /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbgcolor, "-sf", selfgcolor, NULL }; static const char *termcmd[] = { "st", NULL }; static Key keys[] = { @@ -276,6 +304,9 @@ static Key keys[] = { { MODKEY|ShiftMask, XK_r, self_restart, {0} }, #endif // SELFRESTART_PATCH { MODKEY|ShiftMask, XK_q, quit, {0} }, + #if XRDB_PATCH + { MODKEY|ShiftMask, XK_F5, xrdb, {.v = NULL } }, + #endif // XRDB_PATCH { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, diff --git a/drw.c b/drw.c index 1d55382..45c7dec 100644 --- a/drw.c +++ b/drw.c @@ -237,12 +237,18 @@ 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 -{ +drw_scm_create( + Drw *drw, + #if XRDB_PATCH + char *clrnames[], + #else + const char *clrnames[], + #endif // XRDB_PATCH + #if ALPHA_PATCH + const unsigned int alphas[], + #endif // ALPHA_PATCH + size_t clrcount +) { size_t i; Clr *ret; diff --git a/drw.h b/drw.h index 5a02232..cdd112b 100644 --- a/drw.h +++ b/drw.h @@ -51,13 +51,26 @@ unsigned int drw_fontset_getwidth(Drw *drw, const char *text); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); /* 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 +void drw_clr_create( + Drw *drw, + Clr *dest, + const char *clrname + #if ALPHA_PATCH + , unsigned int alpha + #endif // ALPHA_PATCH +); +Clr *drw_scm_create( + Drw *drw, + #if XRDB_PATCH + char *clrnames[], + #else + const char *clrnames[], + #endif // XRDB_PATCH + #if ALPHA_PATCH + const unsigned int alphas[], + #endif // ALPHA_PATCH + size_t clrcount +); /* Cursor abstraction */ Cur *drw_cur_create(Drw *drw, int shape); diff --git a/dwm.c b/dwm.c index 1d4f2c4..eaa7e4f 100644 --- a/dwm.c +++ b/dwm.c @@ -3106,6 +3106,11 @@ main(int argc, char *argv[]) if (!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display"); checkotherwm(); + #if XRDB_PATCH + XrmInitialize(); + loadxrdb(); + #endif + setup(); #ifdef __OpenBSD__ if (pledge("stdio rpath proc exec", NULL) == -1) diff --git a/patch/include.c b/patch/include.c index cc528bc..4597d51 100644 --- a/patch/include.c +++ b/patch/include.c @@ -90,6 +90,10 @@ #include "zoomswap.c" #endif +#if XRDB_PATCH +#include "xrdb.c" +#endif + /* Layouts */ #if BSTACK_LAYOUT diff --git a/patch/include.h b/patch/include.h index 4957e09..2a6001b 100644 --- a/patch/include.h +++ b/patch/include.h @@ -78,10 +78,18 @@ #include "vanitygaps.h" #endif +#if WARP_PATCH +#include "warp.h" +#endif + #if ZOOMSWAP_PATCH #include "zoomswap.h" #endif +#if XRDB_PATCH +#include "xrdb.h" +#endif + /* Layouts */ #if BSTACK_LAYOUT diff --git a/patch/xrdb.c b/patch/xrdb.c new file mode 100644 index 0000000..07c6d96 --- /dev/null +++ b/patch/xrdb.c @@ -0,0 +1,75 @@ +void +loadxrdb() +{ + Display *display; + char * resm; + XrmDatabase xrdb; + char *type; + XrmValue value; + + display = XOpenDisplay(NULL); + + if (display != NULL) { + resm = XResourceManagerString(display); + + if (resm != NULL) { + xrdb = XrmGetStringDatabase(resm); + + if (xrdb != NULL) { + XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor); + XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor); + XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor); + #if FLOAT_BORDER_COLOR_PATCH + XRDB_LOAD_COLOR("dwm.normflcolor", normflcolor); + #endif // FLOAT_BORDER_COLOR_PATCH + + XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor); + XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor); + XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor); + #if FLOAT_BORDER_COLOR_PATCH + XRDB_LOAD_COLOR("dwm.selflcolor", selflcolor); + #endif // FLOAT_BORDER_COLOR_PATCH + + #if AWESOMEBAR_PATCH + XRDB_LOAD_COLOR("dwm.hidfgcolor", hidfgcolor); + XRDB_LOAD_COLOR("dwm.hidbgcolor", hidbgcolor); + XRDB_LOAD_COLOR("dwm.hidbordercolor", hidbordercolor); + #if FLOAT_BORDER_COLOR_PATCH + XRDB_LOAD_COLOR("dwm.hidflcolor", hidflcolor); + #endif // FLOAT_BORDER_COLOR_PATCH + #endif // AWESOMEBAR_PATCH + + #if TITLECOLOR_PATCH + XRDB_LOAD_COLOR("dwm.titlefgcolor", titlefgcolor); + XRDB_LOAD_COLOR("dwm.titlebgcolor", titlebgcolor); + XRDB_LOAD_COLOR("dwm.titlebordercolor", titlebordercolor); + #if FLOAT_BORDER_COLOR_PATCH + XRDB_LOAD_COLOR("dwm.titleflcolor", titleflcolor); + #endif // FLOAT_BORDER_COLOR_PATCH + #endif // TITLECOLOR_PATCH + } + } + } + + XCloseDisplay(display); +} + +void +xrdb(const Arg *arg) +{ + loadxrdb(); + int i; + 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 + #else + 3 + #endif // FLOAT_BORDER_COLOR_PATCH + ); + focus(NULL); + arrange(NULL); +} \ No newline at end of file diff --git a/patch/xrdb.h b/patch/xrdb.h new file mode 100644 index 0000000..304f2e2 --- /dev/null +++ b/patch/xrdb.h @@ -0,0 +1,21 @@ +#include + +#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \ + if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \ + int i = 1; \ + for (; i <= 6; i++) { \ + if (value.addr[i] < 48) break; \ + if (value.addr[i] > 57 && value.addr[i] < 65) break; \ + if (value.addr[i] > 70 && value.addr[i] < 97) break; \ + if (value.addr[i] > 102) break; \ + } \ + if (i == 7) { \ + strncpy(V, value.addr, 7); \ + V[7] = '\0'; \ + } \ + } \ + } + +static void loadxrdb(void); +static void xrdb(const Arg *arg); + diff --git a/patches.h b/patches.h index bd5359f..3ddb5c5 100644 --- a/patches.h +++ b/patches.h @@ -285,6 +285,11 @@ */ #define WINDOWROLERULE_PATCH 0 +/* Allows dwm to read colors from xrdb (.Xresources) at run time. + * https://dwm.suckless.org/patches/xrdb/ + */ +#define XRDB_PATCH 0 + /* The zoomswap patch allows a master and a stack window to swap places * rather than every window on the screen changing position. * https://dwm.suckless.org/patches/zoomswap/