2021-09-13 10:48:56 +02:00
|
|
|
#include <X11/Xresource.h>
|
2019-11-27 08:42:00 +01:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
|
|
|
{
|
|
|
|
char **sdst = dst;
|
|
|
|
int *idst = dst;
|
|
|
|
float *fdst = dst;
|
|
|
|
|
|
|
|
char fullname[256];
|
|
|
|
char fullclass[256];
|
|
|
|
char *type;
|
|
|
|
XrmValue ret;
|
|
|
|
|
|
|
|
snprintf(fullname, sizeof(fullname), "%s.%s", "slock", name);
|
|
|
|
snprintf(fullclass, sizeof(fullclass), "%s.%s", "Slock", name);
|
|
|
|
fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
|
|
|
|
|
|
|
|
XrmGetResource(db, fullname, fullclass, &type, &ret);
|
|
|
|
if (ret.addr == NULL || strncmp("String", type, 64))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch (rtype) {
|
|
|
|
case STRING:
|
|
|
|
*sdst = ret.addr;
|
|
|
|
break;
|
|
|
|
case INTEGER:
|
|
|
|
*idst = strtoul(ret.addr, NULL, 10);
|
|
|
|
break;
|
|
|
|
case FLOAT:
|
|
|
|
*fdst = strtof(ret.addr, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
config_init(Display *dpy)
|
|
|
|
{
|
|
|
|
char *resm;
|
|
|
|
XrmDatabase db;
|
|
|
|
ResourcePref *p;
|
|
|
|
|
|
|
|
XrmInitialize();
|
|
|
|
resm = XResourceManagerString(dpy);
|
|
|
|
if (!resm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
db = XrmGetStringDatabase(resm);
|
2021-09-13 10:48:56 +02:00
|
|
|
for (p = resources; p < resources + LENGTH(resources); p++)
|
2019-11-27 08:42:00 +01:00
|
|
|
resource_load(db, p->name, p->type, p->dst);
|
|
|
|
}
|