Adding xresources patch
This commit is contained in:
parent
7615c2f0aa
commit
4bd0ed3327
7 changed files with 131 additions and 0 deletions
|
|
@ -6,4 +6,8 @@
|
|||
|
||||
#if FIXIME_PATCH
|
||||
#include "fixime.c"
|
||||
#endif
|
||||
|
||||
#if XRESOURCES_PATCH
|
||||
#include "xresources.c"
|
||||
#endif
|
||||
|
|
@ -6,4 +6,8 @@
|
|||
|
||||
#if FIXIME_PATCH
|
||||
#include "fixime.h"
|
||||
#endif
|
||||
|
||||
#if XRESOURCES_PATCH
|
||||
#include "xresources.h"
|
||||
#endif
|
||||
52
patch/xresources.c
Normal file
52
patch/xresources.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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",
|
||||
opt_name ? opt_name : "st", name);
|
||||
snprintf(fullclass, sizeof(fullclass), "%s.%s",
|
||||
opt_class ? opt_class : "St", 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(void)
|
||||
{
|
||||
char *resm;
|
||||
XrmDatabase db;
|
||||
ResourcePref *p;
|
||||
|
||||
XrmInitialize();
|
||||
resm = XResourceManagerString(xw.dpy);
|
||||
if (!resm)
|
||||
return;
|
||||
|
||||
db = XrmGetStringDatabase(resm);
|
||||
for (p = resources; p < resources + LEN(resources); p++)
|
||||
resource_load(db, p->name, p->type, p->dst);
|
||||
}
|
||||
17
patch/xresources.h
Normal file
17
patch/xresources.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <X11/Xresource.h>
|
||||
|
||||
/* Xresources preferences */
|
||||
enum resource_type {
|
||||
STRING = 0,
|
||||
INTEGER = 1,
|
||||
FLOAT = 2
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
enum resource_type type;
|
||||
void *dst;
|
||||
} ResourcePref;
|
||||
|
||||
int resource_load(XrmDatabase, char *, enum resource_type, void *);
|
||||
void config_init(void);
|
||||
Loading…
Add table
Add a link
Reference in a new issue