diff options
Diffstat (limited to 'dwm.c')
| -rw-r--r-- | dwm.c | 72 | 
1 files changed, 72 insertions, 0 deletions
@@ -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)  | 
