summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2022-08-09 23:53:57 -0500
committerzachir <zachir@librem.one>2022-08-09 23:53:57 -0500
commit81439ee0f45ba56835cbfa070453554354ad9fed (patch)
treeb4cc75c69639b4497c7eb869bc83cf0ecfedb115
parentf141c882d48ebd1d6175ef8ce6b43611b4559fa9 (diff)
dwm: add xresources patch, clean up color names
-rw-r--r--config.def.h66
-rw-r--r--config.h71
-rw-r--r--drw.c2
-rw-r--r--drw.h2
-rw-r--r--dwm.c72
-rw-r--r--patches/dwm-xresources-6.2.diff235
6 files changed, 401 insertions, 47 deletions
diff --git a/config.def.h b/config.def.h
index 4901408..7542a16 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,29 +1,32 @@
/* See LICENSE file for copyright and license details. */
/* appearance */
-static const unsigned int borderpx = 1; /* border pixel of windows */
-static const unsigned int gappx = 6; /* gaps between windows */
-static const unsigned int snap = 32; /* snap pixel */
+static unsigned int borderpx = 1; /* border pixel of windows */
+static unsigned int gappx = 6; /* gaps between windows */
+static unsigned int snap = 32; /* snap pixel */
static const unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const unsigned int systrayspacing = 2; /* systray spacing */
static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor */
static const int showsystray = 1; /* 0 means no systray */
static const int swallowfloating = 0; /* 1 means swallow floating windows by default */
-static const int showbar = 1; /* 0 means no bar */
-static const int topbar = 1; /* 0 means bottom bar */
+static int showbar = 1; /* 0 means no bar */
+static int topbar = 1; /* 0 means bottom bar */
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 const char col_urgborder[] = "#ff0000";
-static const char *colors[][3] = {
+static char normbgcolor[] = "#222222";
+static char normbordercolor[] = "#444444";
+static char normfgcolor[] = "#bbbbbb";
+static char selfgcolor[] = "#eeeeee";
+static char selbordercolor[] = "#005577";
+static char selbgcolor[] = "#005577";
+static char urgbgcolor[] = "#ff0000";
+static char urgbordercolor[] = "#ff0000";
+static char urgfgcolor[] = "#ffffff";
+static char *colors[][3] = {
/* fg bg border */
- [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
- [SchemeSel] = { col_gray4, col_cyan, col_cyan },
- [SchemeUrg] = { col_gray4, col_cyan, col_urgborder },
+ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
+ [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
+ [SchemeUrg] = { urgfgcolor, urgbgcolor, urgbordercolor },
};
typedef struct {
@@ -58,10 +61,10 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
-static const int nmaster = 1; /* number of clients in master area */
-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
-static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
+static float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static int nmaster = 1; /* number of clients in master area */
+static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+static int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static int attachbelow = 1; /* 1 means attach after the currently active window */
@@ -87,9 +90,32 @@ 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", selbordercolor, "-sf", selfgcolor, NULL };
static const char *termcmd[] = { "st", NULL };
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "normbgcolor", STRING, &normbgcolor },
+ { "normbordercolor", STRING, &normbordercolor },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "selbordercolor", STRING, &selbordercolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "urgbgcolor", STRING, &urgbgcolor },
+ { "urgbordercolor", STRING, &urgbordercolor },
+ { "urgfgcolor", STRING, &urgfgcolor },
+ { "borderpx", INTEGER, &borderpx },
+ { "gappx", INTEGER, &gappx },
+ { "snap", INTEGER, &snap },
+ { "showbar", INTEGER, &showbar },
+ { "topbar", INTEGER, &topbar },
+ { "nmaster", INTEGER, &nmaster },
+ { "resizehints", INTEGER, &resizehints },
+ { "mfact", FLOAT, &mfact },
+};
+
static Key keys[] = {
/* modifier key function argument */
diff --git a/config.h b/config.h
index 23a56c6..a196ceb 100644
--- a/config.h
+++ b/config.h
@@ -2,42 +2,40 @@
#include <X11/XF86keysym.h>
-static const char normfgcolor[] = "#bbbbbb";
-static const char selbordercolor[] = "#005577";
-static const char selbgcolor[] = "#005577";
-static const char urgbordercolor[] = "#ff0000";
/* appearance */
-static const unsigned int borderpx = 1; /* border pixel of windows */
-static const unsigned int gappx = 6; /* gaps between windows */
-static const unsigned int snap = 32; /* snap pixel */
+static unsigned int borderpx = 1; /* border pixel of windows */
+static unsigned int gappx = 6; /* gaps between windows */
+static unsigned int snap = 32; /* snap pixel */
static const int swallowfloating = 0;
static const unsigned int systraypinning = 0; /* 0: sloppy systray follows selected monitor, >0: pin systray to monitor X */
static const unsigned int systrayspacing = 2; /* systray spacing */
static const int systraypinningfailfirst = 1; /* 1: if pinning fails, display systray on the first monitor, False: display systray on the last monitor*/
static const int showsystray = 1; /* 0 means no systray */
-static const int showbar = 1; /* 0 means no bar */
-static const int topbar = 1; /* 0 means bottom bar */
+static int showbar = 1; /* 0 means no bar */
+static int topbar = 1; /* 0 means bottom bar */
static const char *fonts[] = { "mononoki Nerd Font Mono:size=12", "symbola:size=10" };
static const char dmenufont[] = "mononoki Nerd Font Mono:size=12";
-static const char col_gray1[] = "#151219";
-static const char col_gray2[] = "#6e6f6c";
-static const char col_gray3[] = "#898883";
-static const char col_gray4[] = "#c5c3bc";
-static const char col_cyan[] = "#2783a1";
-static const char col_other[] = "#675f58";
+static char normbgcolor[] = "#151219";
+static char normbordercolor[] = "#6e6f6c";
+static char normfgcolor[] = "#898883";
+static char selfgcolor[] = "#c5c3bc";
+static char selbordercolor[] = "#2783a1";
+static char selbgcolor[] = "#675f58";
+static char urgfgcolor[] = "#c5c3bc";
+static char urgbordercolor[] = "#2783a1";
+static char urgbgcolor[] = "#675f58";
-static const char *colors[][3] = {
- /* fg bg border */
- [SchemeNorm] = { col_gray4, col_gray1, col_gray3 }, // unfocused wins
- [SchemeSel] = { col_gray4, col_gray2, col_gray4 }, // the focused win
- [SchemeUrg] = { col_gray4, col_gray1, col_other },
+static char *colors[][3] = {
+ /* fg bg border */
+ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, // unfocused wins
+ [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, // the focused win
+ [SchemeUrg] = { urgfgcolor, urgbgcolor, urgbordercolor },
};
typedef struct {
const char *name;
const void *cmd;
} Sp;
-<<<<<<< HEAD
const char *spcmd0[] = { "st", "-g", "100x33", "-c", "sphtop", "-e", "htop", NULL };
const char *spcmd1[] = { "st", "-g", "100x33", "-c", "spterm", NULL };
const char *spcmd2[] = { "st", "-g", "100x33", "-c", "sppmxr", "-e", "pulsemixer", NULL };
@@ -108,9 +106,9 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.50; /* factor of master area size [0.05..0.95] */
-static const int nmaster = 1; /* number of clients in master area */
-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+static float mfact = 0.50; /* factor of master area size [0.05..0.95] */
+static int nmaster = 1; /* number of clients in master area */
+static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
static int attachbelow = 1; /* 1 means attach after the currently active window */
@@ -137,7 +135,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 *rmenucmd[] = { "/usr/sbin/j4-dmenu-desktop", NULL }; */
/* static const char *passmenu[] = { "passmenu", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; */
static const char *termcmd[] = { "st", NULL };
@@ -159,6 +157,29 @@ static const char *sxhkdsig[] = { "doas", "pkill", "-HUP", "swhkd", NULL };
/* static const char *xidletog[] = { "xidletog", NULL }; */
/* static const char *xkillcmd[] = { "xkill", NULL }; */
+/*
+ * Xresources preferences to load at startup
+ */
+ResourcePref resources[] = {
+ { "normbgcolor", STRING, &normbgcolor },
+ { "normbordercolor", STRING, &normbordercolor },
+ { "normfgcolor", STRING, &normfgcolor },
+ { "selbgcolor", STRING, &selbgcolor },
+ { "selbordercolor", STRING, &selbordercolor },
+ { "selfgcolor", STRING, &selfgcolor },
+ { "urgbgcolor", STRING, &urgbgcolor },
+ { "urgbordercolor", STRING, &urgbordercolor },
+ { "urgfgcolor", STRING, &urgfgcolor },
+ { "borderpx", INTEGER, &borderpx },
+ { "gappx", INTEGER, &borderpx },
+ { "snap", INTEGER, &snap },
+ { "showbar", INTEGER, &showbar },
+ { "topbar", INTEGER, &topbar },
+ { "nmaster", INTEGER, &nmaster },
+ { "resizehints", INTEGER, &resizehints },
+ { "mfact", FLOAT, &mfact },
+};
+
static Key keys[] = {
/* modifier key function argument */
/* { MODKEY, XK_d, spawn, {.v = dmenucmd } }, */
diff --git a/drw.c b/drw.c
index 4cdbcbe..8f1059e 100644
--- a/drw.c
+++ b/drw.c
@@ -208,7 +208,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 *
-drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
+drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
{
size_t i;
Clr *ret;
diff --git a/drw.h b/drw.h
index 4bcd5ad..42b04ce 100644
--- a/drw.h
+++ b/drw.h
@@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
/* Colorscheme abstraction */
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
-Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
+Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
/* Cursor abstraction */
Cur *drw_cur_create(Drw *drw, int shape);
diff --git a/dwm.c b/dwm.c
index a049ff4..e007970 100644
--- a/dwm.c
+++ b/dwm.c
@@ -36,6 +36,7 @@
#include <X11/Xlib.h>
#include <X11/Xproto.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -180,6 +181,19 @@ struct Systray {
Client *icons;
};
+/* Xresources preferences */
+enum resource_type {
+ STRING = 0,
+ INTEGER = 1,
+ FLOAT = 2
+};
+
+typedef struct {
+ char *name;
+ enum resource_type type;
+ void *dst;
+} ResourcePref;
+
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
@@ -299,6 +313,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void load_xresources(void);
+static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
@@ -3088,6 +3104,60 @@ zoom(const Arg *arg)
arrange(c->mon);
}
+void
+resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
+{
+ char *sdst = NULL;
+ int *idst = NULL;
+ float *fdst = NULL;
+
+ sdst = dst;
+ idst = dst;
+ fdst = dst;
+
+ char fullname[256];
+ char *type;
+ XrmValue ret;
+
+ snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
+ fullname[sizeof(fullname) - 1] = '\0';
+
+ XrmGetResource(db, fullname, "*", &type, &ret);
+ if (!(ret.addr == NULL || strncmp("String", type, 64)))
+ {
+ switch (rtype) {
+ case STRING:
+ strcpy(sdst, ret.addr);
+ break;
+ case INTEGER:
+ *idst = strtoul(ret.addr, NULL, 10);
+ break;
+ case FLOAT:
+ *fdst = strtof(ret.addr, NULL);
+ break;
+ }
+ }
+}
+
+void
+load_xresources(void)
+{
+ Display *display;
+ char *resm;
+ XrmDatabase db;
+ ResourcePref *p;
+
+ display = XOpenDisplay(NULL);
+ resm = XResourceManagerString(display);
+ if (!resm)
+ return;
+
+ db = XrmGetStringDatabase(resm);
+ for (p = resources; p < resources + LENGTH(resources); p++)
+ resource_load(db, p->name, p->type, p->dst);
+ XCloseDisplay(display);
+}
+
int
main(int argc, char *argv[])
{
@@ -3102,6 +3172,8 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
+ XrmInitialize();
+ load_xresources();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1)
diff --git a/patches/dwm-xresources-6.2.diff b/patches/dwm-xresources-6.2.diff
new file mode 100644
index 0000000..c1875c0
--- /dev/null
+++ b/patches/dwm-xresources-6.2.diff
@@ -0,0 +1,235 @@
+From 2832bd78a690606a48a7e1d370cd60fd92ee4988 Mon Sep 17 00:00:00 2001
+From: MLquest8 <miskuzius@gmail.com>
+Date: Fri, 12 Jun 2020 15:43:31 +0400
+Subject: [PATCH] handle various setting of various types from Xresources
+
+---
+ config.def.h | 54 ++++++++++++++++++++++++++-------------
+ drw.c | 2 +-
+ drw.h | 2 +-
+ dwm.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ 4 files changed, 111 insertions(+), 19 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 1c0b587..e69f288 100644
+--- a/config.def.h
++++ b/config.def.h
+@@ -1,21 +1,22 @@
+ /* See LICENSE file for copyright and license details. */
+
+ /* appearance */
+-static const unsigned int borderpx = 1; /* border pixel of windows */
+-static const unsigned int snap = 32; /* snap pixel */
+-static const int showbar = 1; /* 0 means no bar */
+-static const int topbar = 1; /* 0 means bottom bar */
++static unsigned int borderpx = 1; /* border pixel of windows */
++static unsigned int snap = 32; /* snap pixel */
++static int showbar = 1; /* 0 means no bar */
++static int topbar = 1; /* 0 means bottom bar */
+ 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 const char *colors[][3] = {
+- /* fg bg border */
+- [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
+- [SchemeSel] = { col_gray4, col_cyan, col_cyan },
++static char normbgcolor[] = "#222222";
++static char normbordercolor[] = "#444444";
++static char normfgcolor[] = "#bbbbbb";
++static char selfgcolor[] = "#eeeeee";
++static char selbordercolor[] = "#005577";
++static char selbgcolor[] = "#005577";
++static char *colors[][3] = {
++ /* fg bg border */
++ [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor },
++ [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor },
+ };
+
+ /* tagging */
+@@ -32,9 +33,9 @@ static const Rule rules[] = {
+ };
+
+ /* layout(s) */
+-static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+-static const int nmaster = 1; /* number of clients in master area */
+-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
++static float mfact = 0.55; /* factor of master area size [0.05..0.95] */
++static int nmaster = 1; /* number of clients in master area */
++static int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+
+ static const Layout layouts[] = {
+ /* symbol arrange function */
+@@ -56,9 +57,28 @@ 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", selbordercolor, "-sf", selfgcolor, NULL };
+ static const char *termcmd[] = { "st", NULL };
+
++/*
++ * Xresources preferences to load at startup
++ */
++ResourcePref resources[] = {
++ { "normbgcolor", STRING, &normbgcolor },
++ { "normbordercolor", STRING, &normbordercolor },
++ { "normfgcolor", STRING, &normfgcolor },
++ { "selbgcolor", STRING, &selbgcolor },
++ { "selbordercolor", STRING, &selbordercolor },
++ { "selfgcolor", STRING, &selfgcolor },
++ { "borderpx", INTEGER, &borderpx },
++ { "snap", INTEGER, &snap },
++ { "showbar", INTEGER, &showbar },
++ { "topbar", INTEGER, &topbar },
++ { "nmaster", INTEGER, &nmaster },
++ { "resizehints", INTEGER, &resizehints },
++ { "mfact", FLOAT, &mfact },
++};
++
+ static Key keys[] = {
+ /* modifier key function argument */
+ { MODKEY, XK_p, spawn, {.v = dmenucmd } },
+diff --git a/drw.c b/drw.c
+index 4cdbcbe..8f1059e 100644
+--- a/drw.c
++++ b/drw.c
+@@ -208,7 +208,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 *
+-drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
++drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
+ {
+ size_t i;
+ Clr *ret;
+diff --git a/drw.h b/drw.h
+index 4bcd5ad..42b04ce 100644
+--- a/drw.h
++++ b/drw.h
+@@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
+
+ /* Colorscheme abstraction */
+ void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
+-Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
++Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
+
+ /* Cursor abstraction */
+ Cur *drw_cur_create(Drw *drw, int shape);
+diff --git a/dwm.c b/dwm.c
+index 9fd0286..dc0d219 100644
+--- a/dwm.c
++++ b/dwm.c
+@@ -36,6 +36,7 @@
+ #include <X11/Xlib.h>
+ #include <X11/Xproto.h>
+ #include <X11/Xutil.h>
++#include <X11/Xresource.h>
+ #ifdef XINERAMA
+ #include <X11/extensions/Xinerama.h>
+ #endif /* XINERAMA */
+@@ -141,6 +142,19 @@ typedef struct {
+ int monitor;
+ } Rule;
+
++/* Xresources preferences */
++enum resource_type {
++ STRING = 0,
++ INTEGER = 1,
++ FLOAT = 2
++};
++
++typedef struct {
++ char *name;
++ enum resource_type type;
++ void *dst;
++} ResourcePref;
++
+ /* function declarations */
+ static void applyrules(Client *c);
+ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
+@@ -234,6 +248,8 @@ static int xerror(Display *dpy, XErrorEvent *ee);
+ static int xerrordummy(Display *dpy, XErrorEvent *ee);
+ static int xerrorstart(Display *dpy, XErrorEvent *ee);
+ static void zoom(const Arg *arg);
++static void load_xresources(void);
++static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
+
+ /* variables */
+ static const char broken[] = "broken";
+@@ -2127,6 +2143,60 @@ zoom(const Arg *arg)
+ pop(c);
+ }
+
++void
++resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
++{
++ char *sdst = NULL;
++ int *idst = NULL;
++ float *fdst = NULL;
++
++ sdst = dst;
++ idst = dst;
++ fdst = dst;
++
++ char fullname[256];
++ char *type;
++ XrmValue ret;
++
++ snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
++ fullname[sizeof(fullname) - 1] = '\0';
++
++ XrmGetResource(db, fullname, "*", &type, &ret);
++ if (!(ret.addr == NULL || strncmp("String", type, 64)))
++ {
++ switch (rtype) {
++ case STRING:
++ strcpy(sdst, ret.addr);
++ break;
++ case INTEGER:
++ *idst = strtoul(ret.addr, NULL, 10);
++ break;
++ case FLOAT:
++ *fdst = strtof(ret.addr, NULL);
++ break;
++ }
++ }
++}
++
++void
++load_xresources(void)
++{
++ Display *display;
++ char *resm;
++ XrmDatabase db;
++ ResourcePref *p;
++
++ display = XOpenDisplay(NULL);
++ resm = XResourceManagerString(display);
++ if (!resm)
++ return;
++
++ db = XrmGetStringDatabase(resm);
++ for (p = resources; p < resources + LENGTH(resources); p++)
++ resource_load(db, p->name, p->type, p->dst);
++ XCloseDisplay(display);
++}
++
+ int
+ main(int argc, char *argv[])
+ {
+@@ -2139,6 +2209,8 @@ main(int argc, char *argv[])
+ if (!(dpy = XOpenDisplay(NULL)))
+ die("dwm: cannot open display");
+ checkotherwm();
++ XrmInitialize();
++ load_xresources();
+ setup();
+ #ifdef __OpenBSD__
+ if (pledge("stdio rpath proc exec", NULL) == -1)
+--
+2.26.2
+