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