diff --git a/README.md b/README.md index 00cf5c3..f03a68e 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) ### Changelog: +2019-12-29 - Added xresources patch + 2019-10-16 - Introduced [flexipatch-finalizer](https://github.com/bakkeby/flexipatch-finalizer) 2019-09-18 - Added border, center, fuzzymatch, incremental, initialtext, instant, line-height, mouse-support, navhistory, non-blocking-stdin, password, pipeout, printinputtext, rejectnomatch, scroll, vertfull, wmtype and xyw patches @@ -82,5 +84,9 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/) - [wmtype](https://github.com/Baitinq/dmenu/blob/master/patches/dmenu-wm_type.diff) - adds extended window manager hints such as \_NET_WM_WINDOW_TYPE and \_NET_WM_WINDOW_TYPE_DOCK + - [xresources](https://tools.suckless.org/dmenu/patches/xresources/) + - allows dmenu to read font and colors from Xresources + - note that with this patch the Xresources settings takes precedence over command line arguments + - [xyw](https://tools.suckless.org/dmenu/patches/xyw/) - adds options for specifying dmenu window position and width \ No newline at end of file diff --git a/dmenu.c b/dmenu.c index a626321..54b4f95 100644 --- a/dmenu.c +++ b/dmenu.c @@ -1186,7 +1186,11 @@ main(int argc, char *argv[]) if (!XGetWindowAttributes(dpy, parentwin, &wa)) die("could not get embedding window attributes: 0x%lx", parentwin); + drw = drw_create(dpy, screen, root, wa.width, wa.height); + #if XRESOURCES_PATCH + read_Xresources(); + #endif // XRESOURCES_PATCH if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); lrpad = drw->fonts->h; diff --git a/patch/include.c b/patch/include.c index 0e6c363..5892ed9 100644 --- a/patch/include.c +++ b/patch/include.c @@ -12,4 +12,7 @@ #endif #if NON_BLOCKING_STDIN_PATCH #include "nonblockingstdin.c" +#endif +#if XRESOURCES_PATCH +#include "xresources.c" #endif \ No newline at end of file diff --git a/patch/xresources.c b/patch/xresources.c new file mode 100644 index 0000000..b80ccdf --- /dev/null +++ b/patch/xresources.c @@ -0,0 +1,27 @@ +#include + +void +read_Xresources(void) +{ + XrmInitialize(); + + char* xrm = XResourceManagerString(drw->dpy); + if (xrm) { + char *type; + XrmDatabase xdb = XrmGetStringDatabase(xrm); + XrmValue xval; + + if (XrmGetResource(xdb, "dmenu.font", "*", &type, &xval) == True) /* font or font set */ + fonts[0] = strdup(xval.addr); + if (XrmGetResource(xdb, "dmenu.background", "*", &type, &xval) == True) /* normal background color */ + colors[SchemeSel][ColBg] = strdup(xval.addr); + if (XrmGetResource(xdb, "dmenu.foreground", "*", &type, &xval) == True) /* normal foreground color */ + colors[SchemeNorm][ColFg] = strdup(xval.addr); + if (XrmGetResource(xdb, "dmenu.selbackground", "*", &type, &xval) == True) /* selected background color */ + colors[SchemeSel][ColBg] = strdup(xval.addr); + if (XrmGetResource(xdb, "dmenu.selforeground", "*", &type, &xval) == True) /* selected foreground color */ + colors[SchemeSel][ColFg] = strdup(xval.addr); + + XrmDestroyDatabase(xdb); + } +} \ No newline at end of file diff --git a/patches.h b/patches.h index 1a94714..7352688 100644 --- a/patches.h +++ b/patches.h @@ -103,8 +103,19 @@ */ #define WMTYPE_PATCH 0 +/* This patch adds the ability to configure dmenu via Xresources. At startup, dmenu will read and + * apply the resources named below: + * dmenu.font : font or font set + * dmenu.background : normal background color + * dmenu.foreground : normal foreground color + * dmenu.selbackground : selected background color + * dmenu.selforeground : selected foreground color + * https://tools.suckless.org/dmenu/patches/xresources/ + */ +#define XRESOURCES_PATCH 0 + /* This patch adds options for specifying dmenu window position and width. * The center patch takes precedence over the XYW patch if enabled. * https://tools.suckless.org/dmenu/patches/xyw/ */ -#define XYW_PATCH 0 \ No newline at end of file +#define XYW_PATCH 0