2019-09-16 12:21:09 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-04-23 22:17:23 +00:00
|
|
|
void
|
|
|
|
config_init(Display *dpy)
|
2021-05-07 07:27:05 +00:00
|
|
|
{
|
2019-09-16 12:21:09 +00:00
|
|
|
char *resm;
|
|
|
|
XrmDatabase db;
|
|
|
|
ResourcePref *p;
|
|
|
|
|
|
|
|
XrmInitialize();
|
2021-04-23 22:17:23 +00:00
|
|
|
resm = XResourceManagerString(dpy);
|
2019-09-16 12:21:09 +00:00
|
|
|
if (!resm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
db = XrmGetStringDatabase(resm);
|
|
|
|
for (p = resources; p < resources + LEN(resources); p++)
|
|
|
|
resource_load(db, p->name, p->type, p->dst);
|
2021-04-23 22:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if XRESOURCES_RELOAD_PATCH
|
2021-05-07 07:27:05 +00:00
|
|
|
void
|
|
|
|
reload_config(int sig)
|
|
|
|
{
|
2021-04-23 22:17:23 +00:00
|
|
|
/* Recreate a Display object to have up to date Xresources entries */
|
|
|
|
Display *dpy;
|
|
|
|
if (!(dpy = XOpenDisplay(NULL)))
|
|
|
|
die("Can't open display\n");
|
|
|
|
|
|
|
|
config_init(dpy);
|
2022-04-11 13:56:12 +00:00
|
|
|
xloadcols();
|
2022-09-24 08:40:33 +00:00
|
|
|
|
|
|
|
/* nearly like zoomabs() */
|
|
|
|
xunloadfonts();
|
|
|
|
xloadfonts(font, 0); /* font <- config_init() */
|
|
|
|
#if FONT2_PATCH
|
|
|
|
xloadsparefonts();
|
|
|
|
#endif // FONT2_PATCH
|
|
|
|
cresize(0, 0);
|
2022-04-11 13:56:12 +00:00
|
|
|
redraw();
|
2022-09-24 08:40:33 +00:00
|
|
|
xhints();
|
|
|
|
|
2022-07-28 13:48:40 +00:00
|
|
|
XCloseDisplay(dpy);
|
2022-09-24 08:40:33 +00:00
|
|
|
|
|
|
|
/* from https://st.suckless.org/patches/xresources-with-reload-signal */
|
|
|
|
/* triggers re-render if we're visible */
|
|
|
|
ttywrite("\033[O", 3, 1);
|
2021-04-23 22:17:23 +00:00
|
|
|
}
|
|
|
|
#endif // XRESOURCES_RELOAD_PATCH
|