all repos — dotfiles @ 3a6c38bffd2f463c5bb914e426066acbdbc02201

my *nix dotfiles

nix/patches/st/xres.diff (view raw)

  1From 2752a599ee01305a435729bfacf43b1dde7cf0ef Mon Sep 17 00:00:00 2001
  2From: Benji Encalada Mora <benji@encalada.dev>
  3Date: Thu, 4 Jun 2020 00:41:10 -0500
  4Subject: [PATCH] fix: replace xfps and actionfps variables
  5
  6---
  7 config.def.h | 36 ++++++++++++++++++++++++
  8 x.c          | 78 +++++++++++++++++++++++++++++++++++++++++++++++++---
  9 2 files changed, 110 insertions(+), 4 deletions(-)
 10
 11diff --git a/config.def.h b/config.def.h
 12index 6f05dce..9b99782 100644
 13--- a/config.def.h
 14+++ b/config.def.h
 15@@ -168,6 +168,42 @@ static unsigned int defaultattr = 11;
 16  */
 17 static uint forcemousemod = ShiftMask;
 18 
 19+/*
 20+ * Xresources preferences to load at startup
 21+ */
 22+ResourcePref resources[] = {
 23+		{ "font",         STRING,  &font },
 24+		{ "color0",       STRING,  &colorname[0] },
 25+		{ "color1",       STRING,  &colorname[1] },
 26+		{ "color2",       STRING,  &colorname[2] },
 27+		{ "color3",       STRING,  &colorname[3] },
 28+		{ "color4",       STRING,  &colorname[4] },
 29+		{ "color5",       STRING,  &colorname[5] },
 30+		{ "color6",       STRING,  &colorname[6] },
 31+		{ "color7",       STRING,  &colorname[7] },
 32+		{ "color8",       STRING,  &colorname[8] },
 33+		{ "color9",       STRING,  &colorname[9] },
 34+		{ "color10",      STRING,  &colorname[10] },
 35+		{ "color11",      STRING,  &colorname[11] },
 36+		{ "color12",      STRING,  &colorname[12] },
 37+		{ "color13",      STRING,  &colorname[13] },
 38+		{ "color14",      STRING,  &colorname[14] },
 39+		{ "color15",      STRING,  &colorname[15] },
 40+		{ "background",   STRING,  &colorname[256] },
 41+		{ "foreground",   STRING,  &colorname[257] },
 42+		{ "cursorColor",  STRING,  &colorname[258] },
 43+		{ "termname",     STRING,  &termname },
 44+		{ "shell",        STRING,  &shell },
 45+		{ "minlatency",   INTEGER, &minlatency },
 46+		{ "maxlatency",   INTEGER, &maxlatency },
 47+		{ "blinktimeout", INTEGER, &blinktimeout },
 48+		{ "bellvolume",   INTEGER, &bellvolume },
 49+		{ "tabspaces",    INTEGER, &tabspaces },
 50+		{ "borderpx",     INTEGER, &borderpx },
 51+		{ "cwscale",      FLOAT,   &cwscale },
 52+		{ "chscale",      FLOAT,   &chscale },
 53+};
 54+
 55 /*
 56  * Internal mouse shortcuts.
 57  * Beware that overloading Button1 will disable the selection.
 58diff --git a/x.c b/x.c
 59index 210f184..76f167f 100644
 60--- a/x.c
 61+++ b/x.c
 62@@ -14,6 +14,7 @@
 63 #include <X11/keysym.h>
 64 #include <X11/Xft/Xft.h>
 65 #include <X11/XKBlib.h>
 66+#include <X11/Xresource.h>
 67 
 68 char *argv0;
 69 #include "arg.h"
 70@@ -45,6 +46,19 @@ typedef struct {
 71 	signed char appcursor; /* application cursor */
 72 } Key;
 73 
 74+/* Xresources preferences */
 75+enum resource_type {
 76+	STRING = 0,
 77+	INTEGER = 1,
 78+	FLOAT = 2
 79+};
 80+
 81+typedef struct {
 82+	char *name;
 83+	enum resource_type type;
 84+	void *dst;
 85+} ResourcePref;
 86+
 87 /* X modifiers */
 88 #define XK_ANY_MOD    UINT_MAX
 89 #define XK_NO_MOD     0
 90@@ -828,8 +842,8 @@ xclear(int x1, int y1, int x2, int y2)
 91 void
 92 xhints(void)
 93 {
 94-	XClassHint class = {opt_name ? opt_name : termname,
 95-	                    opt_class ? opt_class : termname};
 96+	XClassHint class = {opt_name ? opt_name : "st",
 97+	                    opt_class ? opt_class : "St"};
 98 	XWMHints wm = {.flags = InputHint, .input = 1};
 99 	XSizeHints *sizeh;
100 
101@@ -1104,8 +1118,6 @@ xinit(int cols, int rows)
102 	pid_t thispid = getpid();
103 	XColor xmousefg, xmousebg;
104 
105-	if (!(xw.dpy = XOpenDisplay(NULL)))
106-		die("can't open display\n");
107 	xw.scr = XDefaultScreen(xw.dpy);
108 	xw.vis = XDefaultVisual(xw.dpy, xw.scr);
109 
110@@ -1964,6 +1976,59 @@ run(void)
111 	}
112 }
113 
114+int
115+resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
116+{
117+	char **sdst = dst;
118+	int *idst = dst;
119+	float *fdst = dst;
120+
121+	char fullname[256];
122+	char fullclass[256];
123+	char *type;
124+	XrmValue ret;
125+
126+	snprintf(fullname, sizeof(fullname), "%s.%s",
127+			opt_name ? opt_name : "st", name);
128+	snprintf(fullclass, sizeof(fullclass), "%s.%s",
129+			opt_class ? opt_class : "St", name);
130+	fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
131+
132+	XrmGetResource(db, fullname, fullclass, &type, &ret);
133+	if (ret.addr == NULL || strncmp("String", type, 64))
134+		return 1;
135+
136+	switch (rtype) {
137+	case STRING:
138+		*sdst = ret.addr;
139+		break;
140+	case INTEGER:
141+		*idst = strtoul(ret.addr, NULL, 10);
142+		break;
143+	case FLOAT:
144+		*fdst = strtof(ret.addr, NULL);
145+		break;
146+	}
147+	return 0;
148+}
149+
150+void
151+config_init(void)
152+{
153+	char *resm;
154+	XrmDatabase db;
155+	ResourcePref *p;
156+
157+	XrmInitialize();
158+	resm = XResourceManagerString(xw.dpy);
159+	if (!resm)
160+		return;
161+
162+	db = XrmGetStringDatabase(resm);
163+	for (p = resources; p < resources + LEN(resources); p++)
164+		resource_load(db, p->name, p->type, p->dst);
165+}
166+
167 void
168 usage(void)
169 {
170@@ -2037,6 +2102,11 @@ run:
171 
172 	setlocale(LC_CTYPE, "");
173 	XSetLocaleModifiers("");
174+
175+	if(!(xw.dpy = XOpenDisplay(NULL)))
176+		die("Can't open display\n");
177+
178+	config_init();
179 	cols = MAX(cols, 1);
180 	rows = MAX(rows, 1);
181 	tnew(cols, rows);
182-- 
1832.26.2
184
185