st-flexipatch

My st-flexipatch configuration
git clone git://git.ethandl.dev/st-flexipatch
Log | Files | Refs | README | LICENSE

xresources.c (1728B)


      1 int
      2 resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
      3 {
      4 	char **sdst = dst;
      5 	int *idst = dst;
      6 	float *fdst = dst;
      7 
      8 	char fullname[256];
      9 	char fullclass[256];
     10 	char *type;
     11 	XrmValue ret;
     12 
     13 	snprintf(fullname, sizeof(fullname), "%s.%s",
     14 			opt_name ? opt_name : "st", name);
     15 	snprintf(fullclass, sizeof(fullclass), "%s.%s",
     16 			opt_class ? opt_class : "St", name);
     17 	fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
     18 
     19 	XrmGetResource(db, fullname, fullclass, &type, &ret);
     20 	if (ret.addr == NULL || strncmp("String", type, 64))
     21 		return 1;
     22 
     23 	switch (rtype) {
     24 	case STRING:
     25 		*sdst = ret.addr;
     26 		break;
     27 	case INTEGER:
     28 		*idst = strtoul(ret.addr, NULL, 10);
     29 		break;
     30 	case FLOAT:
     31 		*fdst = strtof(ret.addr, NULL);
     32 		break;
     33 	}
     34 	return 0;
     35 }
     36 
     37 void
     38 config_init(Display *dpy)
     39 {
     40 	char *resm;
     41 	XrmDatabase db;
     42 	ResourcePref *p;
     43 
     44 	XrmInitialize();
     45 	resm = XResourceManagerString(dpy);
     46 	if (!resm)
     47 		return;
     48 
     49 	db = XrmGetStringDatabase(resm);
     50 	for (p = resources; p < resources + LEN(resources); p++)
     51 		resource_load(db, p->name, p->type, p->dst);
     52 }
     53 
     54 #if XRESOURCES_RELOAD_PATCH
     55 void
     56 reload_config(int sig)
     57 {
     58 	/* Recreate a Display object to have up to date Xresources entries */
     59 	Display *dpy;
     60 	if (!(dpy = XOpenDisplay(NULL)))
     61 		die("Can't open display\n");
     62 
     63 	config_init(dpy);
     64 	xloadcols();
     65 
     66 	/* nearly like zoomabs() */
     67 	xunloadfonts();
     68 	xloadfonts(font, 0); /* font <- config_init() */
     69 	#if FONT2_PATCH
     70 	xloadsparefonts();
     71 	#endif // FONT2_PATCH
     72 	cresize(0, 0);
     73 	redraw();
     74 	xhints();
     75 
     76 	XCloseDisplay(dpy);
     77 
     78 	/* from https://st.suckless.org/patches/xresources-with-reload-signal */
     79 	/* triggers re-render if we're visible */
     80 	ttywrite("\033[O", 3, 1);
     81 }
     82 #endif // XRESOURCES_RELOAD_PATCH