summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorLuke Smith <luke@lukesmith.xyz>2020-11-07 07:13:09 -0500
committerLuke Smith <luke@lukesmith.xyz>2020-11-07 07:13:09 -0500
commitbc040702d9cd576a055f87dab7db92528fadfef2 (patch)
tree7e6f24743d77f91d4cfb90bd20030ac6a16b88a4 /dwm.c
parentad08183a60d259387955c8e5f5f319cc5b8a19c9 (diff)
rm xrdb patch to xresources to load non-color vars
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c136
1 files changed, 72 insertions, 64 deletions
diff --git a/dwm.c b/dwm.c
index 2e43282..c18ac9c 100644
--- a/dwm.c
+++ b/dwm.c
@@ -35,8 +35,8 @@
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xproto.h>
-#include <X11/Xresource.h>
#include <X11/Xutil.h>
+#include <X11/Xresource.h>
#ifdef XINERAMA
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
@@ -68,21 +68,6 @@
#define SPTAGMASK (((1 << LENGTH(scratchpads))-1) << LENGTH(tags))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define TRUNC(X,A,B) (MAX((A), MIN((X), (B))))
-#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'; \
- } \
- } \
- }
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@@ -176,6 +161,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);
@@ -214,7 +212,6 @@ static void grabkeys(void);
static void incnmaster(const Arg *arg);
static void keypress(XEvent *e);
static void killclient(const Arg *arg);
-static void loadxrdb(void);
static void manage(Window w, XWindowAttributes *wa);
static void mappingnotify(XEvent *e);
static void maprequest(XEvent *e);
@@ -281,8 +278,9 @@ static Monitor *wintomon(Window w);
static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
-static void xrdb(const Arg *arg);
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);
@@ -1176,37 +1174,6 @@ killclient(const Arg *arg)
}
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.color0", normbordercolor);
- XRDB_LOAD_COLOR("dwm.color8", selbordercolor);
- XRDB_LOAD_COLOR("dwm.color0", normbgcolor);
- XRDB_LOAD_COLOR("dwm.color4", normfgcolor);
- XRDB_LOAD_COLOR("dwm.color0", selfgcolor);
- XRDB_LOAD_COLOR("dwm.color4", selbgcolor);
- }
- }
- }
-
- XCloseDisplay(display);
-}
-
-void
manage(Window w, XWindowAttributes *wa)
{
Client *c, *t = NULL, *term = NULL;
@@ -1934,8 +1901,6 @@ sigdwmblocks(const Arg *arg)
void
spawn(const Arg *arg)
{
- if (arg->v == dmenucmd)
- dmenumon[0] = '0' + selmon->num;
if (fork() == 0) {
if (dpy)
close(ConnectionNumber(dpy));
@@ -2545,17 +2510,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee)
}
void
-xrdb(const Arg *arg)
-{
- loadxrdb();
- int i;
- for (i = 0; i < LENGTH(colors); i++)
- scheme[i] = drw_scm_create(drw, colors[i], 3);
- focus(NULL);
- arrange(NULL);
-}
-
-void
zoom(const Arg *arg)
{
Client *c = selmon->sel;
@@ -2569,6 +2523,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[])
{
@@ -2583,8 +2591,8 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n");
checkotherwm();
- XrmInitialize();
- loadxrdb();
+ XrmInitialize();
+ load_xresources();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1)