X-Git-Url: https://git.danieliu.xyz/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=4edd7cef2f668920f09c2d0270ae5b982ccb5dd6;hp=527bea23d6d2b3d68a2fb2e0c6d3fe60170e7f3e;hb=e4db2af451d1b7838ffc7c65f855eb38b40f7cc6;hpb=899b4f41f9a432cd6518adb25ee6409943a9789e diff --git a/dwm.c b/dwm.c index 527bea2..4edd7ce 100644 --- a/dwm.c +++ b/dwm.c @@ -37,6 +37,7 @@ #include #include #include +#include #ifdef XINERAMA #include #endif /* XINERAMA */ @@ -143,6 +144,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); @@ -238,6 +252,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 autostartblocksh[] = "autostart_blocking.sh"; @@ -2223,6 +2239,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[]) { @@ -2235,6 +2305,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)