1 From 2752a599ee01305a435729bfacf43b1dde7cf0ef Mon Sep 17 00:00:00 2001
2 From: Benji Encalada Mora <benji@encalada.dev>
3 Date: Thu, 4 Jun 2020 00:41:10 -0500
4 Subject: [PATCH] fix: replace xfps and actionfps variables
7 config.def.h | 36 ++++++++++++++++++++++++
8 x.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++---
9 2 files changed, 110 insertions(+), 4 deletions(-)
11 diff --git a/config.def.h b/config.def.h
12 index 6f05dce..9b99782 100644
15 @@ -168,6 +168,42 @@ static unsigned int defaultattr = 11;
17 static uint forcemousemod = ShiftMask;
20 + * Xresources preferences to load at startup
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 },
56 * Internal mouse shortcuts.
57 * Beware that overloading Button1 will disable the selection.
58 diff --git a/x.c b/x.c
59 index 210f184..76f167f 100644
63 #include <X11/keysym.h>
64 #include <X11/Xft/Xft.h>
65 #include <X11/XKBlib.h>
66 +#include <X11/Xresource.h>
70 @@ -45,6 +46,19 @@ typedef struct {
71 signed char appcursor; /* application cursor */
74 +/* Xresources preferences */
83 + enum resource_type type;
88 #define XK_ANY_MOD UINT_MAX
90 @@ -828,8 +842,8 @@ xclear(int x1, int y1, int x2, int y2)
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};
101 @@ -1104,8 +1118,6 @@ xinit(int cols, int rows)
102 pid_t thispid = getpid();
103 XColor xmousefg, xmousebg;
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);
110 @@ -1964,6 +1976,59 @@ run(void)
115 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
121 + char fullname[256];
122 + char fullclass[256];
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';
132 + XrmGetResource(db, fullname, fullclass, &type, &ret);
133 + if (ret.addr == NULL || strncmp("String", type, 64))
141 + *idst = strtoul(ret.addr, NULL, 10);
144 + *fdst = strtof(ret.addr, NULL);
158 + resm = XResourceManagerString(xw.dpy);
162 + db = XrmGetStringDatabase(resm);
163 + for (p = resources; p < resources + LEN(resources); p++)
164 + resource_load(db, p->name, p->type, p->dst);
170 @@ -2037,6 +2102,11 @@ run:
172 setlocale(LC_CTYPE, "");
173 XSetLocaleModifiers("");
175 + if(!(xw.dpy = XOpenDisplay(NULL)))
176 + die("Can't open display\n");