st-xresources-20200204-cfdf3f0.diff - sites - public wiki contents of suckless.… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-xresources-20200204-cfdf3f0.diff (5555B) | |
--- | |
1 From cfdf3f0fcd81c3fe29bf4717d3276e078efc5787 Mon Sep 17 00:00:00 2001 | |
2 From: Malcolm VanOrder <[email protected]> | |
3 Date: Tue, 4 Feb 2020 00:29:16 -0500 | |
4 Subject: [PATCH] Apply modified xresources patch to version 0.8.2 | |
5 | |
6 Modified verion of https://git.suckless.org/sites/file/st.suckless.org/p… | |
7 | |
8 * Add doc strings for new functions | |
9 * Moved XOpenDisplay back into xinit | |
10 * Rename config_init to xresources_init and call it in xinit after | |
11 XOpenDisplay. | |
12 | |
13 Signed-off-by: Malcolm VanOrder <[email protected]> | |
14 --- | |
15 config.def.h | 36 +++++++++++++++++++++ | |
16 x.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++-- | |
17 2 files changed, 124 insertions(+), 2 deletions(-) | |
18 | |
19 diff --git a/config.def.h b/config.def.h | |
20 index 546edda..e1457af 100644 | |
21 --- a/config.def.h | |
22 +++ b/config.def.h | |
23 @@ -150,6 +150,42 @@ static unsigned int mousebg = 0; | |
24 */ | |
25 static unsigned int defaultattr = 11; | |
26 | |
27 +/* | |
28 + * Xresources preferences to load at startup | |
29 + */ | |
30 +ResourcePref resources[] = { | |
31 + { "font", STRING, &font }, | |
32 + { "color0", STRING, &colorname[0] }, | |
33 + { "color1", STRING, &colorname[1] }, | |
34 + { "color2", STRING, &colorname[2] }, | |
35 + { "color3", STRING, &colorname[3] }, | |
36 + { "color4", STRING, &colorname[4] }, | |
37 + { "color5", STRING, &colorname[5] }, | |
38 + { "color6", STRING, &colorname[6] }, | |
39 + { "color7", STRING, &colorname[7] }, | |
40 + { "color8", STRING, &colorname[8] }, | |
41 + { "color9", STRING, &colorname[9] }, | |
42 + { "color10", STRING, &colorname[10] }, | |
43 + { "color11", STRING, &colorname[11] }, | |
44 + { "color12", STRING, &colorname[12] }, | |
45 + { "color13", STRING, &colorname[13] }, | |
46 + { "color14", STRING, &colorname[14] }, | |
47 + { "color15", STRING, &colorname[15] }, | |
48 + { "background", STRING, &colorname[256] }, | |
49 + { "foreground", STRING, &colorname[257] }, | |
50 + { "cursorColor", STRING, &colorname[258] }, | |
51 + { "termname", STRING, &termname }, | |
52 + { "shell", STRING, &shell }, | |
53 + { "xfps", INTEGER, &xfps }, | |
54 + { "actionfps", INTEGER, &actionfps }, | |
55 + { "blinktimeout", INTEGER, &blinktimeout }, | |
56 + { "bellvolume", INTEGER, &bellvolume }, | |
57 + { "tabspaces", INTEGER, &tabspaces }, | |
58 + { "borderpx", INTEGER, &borderpx }, | |
59 + { "cwscale", FLOAT, &cwscale }, | |
60 + { "chscale", FLOAT, &chscale }, | |
61 +}; | |
62 + | |
63 /* | |
64 * Force mouse select/shortcuts while mask is active (when MODE_MOUSE i… | |
65 * Note that if you want to use ShiftMask with selmasks, set this to an… | |
66 diff --git a/x.c b/x.c | |
67 index 1f62129..8ccaf58 100644 | |
68 --- a/x.c | |
69 +++ b/x.c | |
70 @@ -14,6 +14,7 @@ | |
71 #include <X11/keysym.h> | |
72 #include <X11/Xft/Xft.h> | |
73 #include <X11/XKBlib.h> | |
74 +#include <X11/Xresource.h> | |
75 | |
76 static char *argv0; | |
77 #include "arg.h" | |
78 @@ -45,6 +46,19 @@ typedef struct { | |
79 signed char appcursor; /* application cursor */ | |
80 } Key; | |
81 | |
82 +/* Xresources preferences */ | |
83 +enum resource_type { | |
84 + STRING = 0, | |
85 + INTEGER = 1, | |
86 + FLOAT = 2 | |
87 +}; | |
88 + | |
89 +typedef struct { | |
90 + char *name; | |
91 + enum resource_type type; | |
92 + void *dst; | |
93 +} ResourcePref; | |
94 + | |
95 /* X modifiers */ | |
96 #define XK_ANY_MOD UINT_MAX | |
97 #define XK_NO_MOD 0 | |
98 @@ -813,8 +827,8 @@ xclear(int x1, int y1, int x2, int y2) | |
99 void | |
100 xhints(void) | |
101 { | |
102 - XClassHint class = {opt_name ? opt_name : termname, | |
103 - opt_class ? opt_class : termname}; | |
104 + XClassHint class = {opt_name ? opt_name : "st", | |
105 + opt_class ? opt_class : "St"}; | |
106 XWMHints wm = {.flags = InputHint, .input = 1}; | |
107 XSizeHints *sizeh; | |
108 | |
109 @@ -1081,6 +1095,77 @@ xicdestroy(XIC xim, XPointer client, XPointer cal… | |
110 return 1; | |
111 } | |
112 | |
113 +/* | |
114 + * Function: resource_load | |
115 + * ----------------------- | |
116 + * Load the value of a resource from the provided db | |
117 + * | |
118 + * db: XrmDatabase to load from | |
119 + * name: name of the resource to load | |
120 + * rtype: type for resource being loaded | |
121 + * dst: pointer to destination for loaded value | |
122 + * | |
123 + * returns: 1 if no value returned or resource's type is not "String" | |
124 + * 0 on success | |
125 + */ | |
126 +int | |
127 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, voi… | |
128 +{ | |
129 + char **sdst = dst; | |
130 + int *idst = dst; | |
131 + float *fdst = dst; | |
132 + | |
133 + char fullname[256]; | |
134 + char fullclass[256]; | |
135 + char *type; | |
136 + XrmValue ret; | |
137 + | |
138 + snprintf(fullname, sizeof(fullname), "%s.%s", | |
139 + opt_name ? opt_name : "st", name); | |
140 + snprintf(fullclass, sizeof(fullclass), "%s.%s", | |
141 + opt_class ? opt_class : "St", name); | |
142 + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - … | |
143 + | |
144 + XrmGetResource(db, fullname, fullclass, &type, &ret); | |
145 + if (ret.addr == NULL || strncmp("String", type, 64)) | |
146 + return 1; | |
147 + | |
148 + switch (rtype) { | |
149 + case STRING: | |
150 + *sdst = ret.addr; | |
151 + break; | |
152 + case INTEGER: | |
153 + *idst = strtoul(ret.addr, NULL, 10); | |
154 + break; | |
155 + case FLOAT: | |
156 + *fdst = strtof(ret.addr, NULL); | |
157 + break; | |
158 + } | |
159 + return 0; | |
160 +} | |
161 + | |
162 +/* | |
163 + * Function: xresources_init | |
164 + * ------------------------- | |
165 + * Initializes xresources values defined in resources | |
166 + */ | |
167 +void | |
168 +xresources_init(void) | |
169 +{ | |
170 + char *resm; | |
171 + XrmDatabase db; | |
172 + ResourcePref *p; | |
173 + | |
174 + XrmInitialize(); | |
175 + resm = XResourceManagerString(xw.dpy); | |
176 + if (!resm) | |
177 + return; | |
178 + | |
179 + db = XrmGetStringDatabase(resm); | |
180 + for (p = resources; p < resources + LEN(resources); p++) | |
181 + resource_load(db, p->name, p->type, p->dst); | |
182 +} | |
183 + | |
184 void | |
185 xinit(int cols, int rows) | |
186 { | |
187 @@ -1092,6 +1177,7 @@ xinit(int cols, int rows) | |
188 | |
189 if (!(xw.dpy = XOpenDisplay(NULL))) | |
190 die("can't open display\n"); | |
191 + xresources_init(); | |
192 xw.scr = XDefaultScreen(xw.dpy); | |
193 xw.vis = XDefaultVisual(xw.dpy, xw.scr); | |
194 | |
195 -- | |
196 2.25.0 | |
197 |