summaryrefslogtreecommitdiff
path: root/archive/st/patch/xresources.c
diff options
context:
space:
mode:
authorauric <auric7@protonmail.com>2025-09-08 21:27:55 -0500
committerauric <auric7@protonmail.com>2025-09-08 21:27:55 -0500
commitde07b49b3249da05605f8c802b991a8588ab63b3 (patch)
tree295d6003f08dfce1d1b779892ce9c0be97d426a3 /archive/st/patch/xresources.c
parent04cfeeb799b4ee6ac990e5d6e1b5302251133d77 (diff)
parente61da07522a060da98fa3a56db3d0360469b26cf (diff)
Resolved conflict, indulging new file layout
Diffstat (limited to 'archive/st/patch/xresources.c')
-rw-r--r--archive/st/patch/xresources.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/archive/st/patch/xresources.c b/archive/st/patch/xresources.c
new file mode 100644
index 0000000..ba3d985
--- /dev/null
+++ b/archive/st/patch/xresources.c
@@ -0,0 +1,82 @@
+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(Display *dpy)
+{
+ char *resm;
+ XrmDatabase db;
+ ResourcePref *p;
+
+ XrmInitialize();
+ resm = XResourceManagerString(dpy);
+ if (!resm)
+ return;
+
+ db = XrmGetStringDatabase(resm);
+ for (p = resources; p < resources + LEN(resources); p++)
+ resource_load(db, p->name, p->type, p->dst);
+}
+
+#if XRESOURCES_RELOAD_PATCH
+void
+reload_config(int sig)
+{
+ /* 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);
+ xloadcols();
+
+ /* nearly like zoomabs() */
+ xunloadfonts();
+ xloadfonts(font, 0); /* font <- config_init() */
+ #if FONT2_PATCH
+ xloadsparefonts();
+ #endif // FONT2_PATCH
+ cresize(0, 0);
+ redraw();
+ xhints();
+
+ XCloseDisplay(dpy);
+
+ /* from https://st.suckless.org/patches/xresources-with-reload-signal */
+ /* triggers re-render if we're visible */
+ ttywrite("\033[O", 3, 1);
+}
+#endif // XRESOURCES_RELOAD_PATCH