tabbed-xresources-20230128-41e2b8f.diff - sites - public wiki contents of suckl… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
tabbed-xresources-20230128-41e2b8f.diff (6210B) | |
--- | |
1 From 46115eedb8ba1da17ea6fb76eb9ffba806faa828 Mon Sep 17 00:00:00 2001 | |
2 From: Casey Fitzpatrick <[email protected]> | |
3 Date: Sat, 28 Jan 2023 10:13:45 -0500 | |
4 Subject: [PATCH] xresources support | |
5 | |
6 Rename foreground to focusnew to avoid conflict with common usage in Xre… | |
7 --- | |
8 config.def.h | 51 +++++++++++++++++++++++++----------- | |
9 tabbed.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++-- | |
10 2 files changed, 107 insertions(+), 17 deletions(-) | |
11 | |
12 diff --git a/config.def.h b/config.def.h | |
13 index 51bb13d..76059d3 100644 | |
14 --- a/config.def.h | |
15 +++ b/config.def.h | |
16 @@ -1,27 +1,27 @@ | |
17 /* See LICENSE file for copyright and license details. */ | |
18 | |
19 /* appearance */ | |
20 -static const char font[] = "monospace:size=9"; | |
21 -static const char* normbgcolor = "#222222"; | |
22 -static const char* normfgcolor = "#cccccc"; | |
23 -static const char* selbgcolor = "#555555"; | |
24 -static const char* selfgcolor = "#ffffff"; | |
25 -static const char* urgbgcolor = "#111111"; | |
26 -static const char* urgfgcolor = "#cc0000"; | |
27 -static const char before[] = "<"; | |
28 -static const char after[] = ">"; | |
29 -static const char titletrim[] = "..."; | |
30 -static const int tabwidth = 200; | |
31 -static const Bool foreground = True; | |
32 -static Bool urgentswitch = False; | |
33 +static char* font = "monospace:size=9"; | |
34 +static char* normbgcolor = "#222222"; | |
35 +static char* normfgcolor = "#cccccc"; | |
36 +static char* selbgcolor = "#555555"; | |
37 +static char* selfgcolor = "#ffffff"; | |
38 +static char* urgbgcolor = "#111111"; | |
39 +static char* urgfgcolor = "#cc0000"; | |
40 +static char* before = "<"; | |
41 +static char* after = ">"; | |
42 +static char* titletrim = "..."; | |
43 +static int tabwidth = 200; | |
44 +static int focusnew = 1; | |
45 +static int urgentswitch = 0; | |
46 | |
47 /* | |
48 * Where to place a new tab when it is opened. When npisrelative is Tru… | |
49 * then the current position is changed + newposition. If npisrelative | |
50 * is False, then newposition is an absolute position. | |
51 */ | |
52 -static int newposition = 0; | |
53 -static Bool npisrelative = False; | |
54 +static int newposition = 0; | |
55 +static int npisrelative = 0; | |
56 | |
57 #define SETPROP(p) { \ | |
58 .v = (char *[]){ "/bin/sh", "-c", \ | |
59 @@ -33,6 +33,27 @@ static Bool npisrelative = False; | |
60 } \ | |
61 } | |
62 | |
63 +/* | |
64 + * Xresources preferences to load at startup | |
65 + */ | |
66 +ResourcePref resources[] = { | |
67 + { "font", STRING, &font}, | |
68 + { "normbgcolor", STRING, &normbgcolor}, | |
69 + { "normfgcolor", STRING, &normfgcolor}, | |
70 + { "selbgcolor", STRING, &selbgcolor}, | |
71 + { "selfgcolor", STRING, &selfgcolor}, | |
72 + { "urgbgcolor", STRING, &urgbgcolor}, | |
73 + { "urgfgcolor", STRING, &urgfgcolor}, | |
74 + { "before", STRING, &before}, | |
75 + { "after", STRING, &after}, | |
76 + { "titletrim", STRING, &titletrim}, | |
77 + { "tabwidth", INTEGER, &tabwidth}, | |
78 + { "focusnew", INTEGER, &focusnew}, | |
79 + { "urgentswitch", INTEGER, &urgentswitch}, | |
80 + { "newposition", INTEGER, &newposition}, | |
81 + { "npisrelative", INTEGER, &npisrelative}, | |
82 +}; | |
83 + | |
84 #define MODKEY ControlMask | |
85 static const Key keys[] = { | |
86 /* modifier key function argument */ | |
87 diff --git a/tabbed.c b/tabbed.c | |
88 index eafe28a..6ca3454 100644 | |
89 --- a/tabbed.c | |
90 +++ b/tabbed.c | |
91 @@ -13,6 +13,7 @@ | |
92 #include <X11/Xatom.h> | |
93 #include <X11/Xlib.h> | |
94 #include <X11/Xproto.h> | |
95 +#include <X11/Xresource.h> | |
96 #include <X11/Xutil.h> | |
97 #include <X11/XKBlib.h> | |
98 #include <X11/Xft/Xft.h> | |
99 @@ -85,11 +86,26 @@ typedef struct { | |
100 Bool urgent; | |
101 Bool closed; | |
102 } Client; | |
103 + | |
104 +/* Xresources preferences */ | |
105 +enum resource_type { | |
106 + STRING = 0, | |
107 + INTEGER = 1, | |
108 + FLOAT = 2 | |
109 +}; | |
110 + | |
111 +typedef struct { | |
112 + char *name; | |
113 + enum resource_type type; | |
114 + void *dst; | |
115 +} ResourcePref; | |
116 + | |
117 | |
118 /* function declarations */ | |
119 static void buttonpress(const XEvent *e); | |
120 static void cleanup(void); | |
121 static void clientmessage(const XEvent *e); | |
122 +static void config_init(void); | |
123 static void configurenotify(const XEvent *e); | |
124 static void configurerequest(const XEvent *e); | |
125 static void createnotify(const XEvent *e); | |
126 @@ -120,6 +136,7 @@ static void move(const Arg *arg); | |
127 static void movetab(const Arg *arg); | |
128 static void propertynotify(const XEvent *e); | |
129 static void resize(int c, int w, int h); | |
130 +static int resource_load(XrmDatabase db, char *name, enum resource_type… | |
131 static void rotate(const Arg *arg); | |
132 static void run(void); | |
133 static void sendxembed(int c, long msg, long detail, long d1, long d2); | |
134 @@ -245,6 +262,23 @@ clientmessage(const XEvent *e) | |
135 } | |
136 } | |
137 | |
138 +void | |
139 +config_init(void) | |
140 +{ | |
141 + char *resm; | |
142 + XrmDatabase db; | |
143 + ResourcePref *p; | |
144 + | |
145 + XrmInitialize(); | |
146 + resm = XResourceManagerString(dpy); | |
147 + if (!resm) | |
148 + return; | |
149 + | |
150 + db = XrmGetStringDatabase(resm); | |
151 + for (p = resources; p < resources + LENGTH(resources); p++) | |
152 + resource_load(db, p->name, p->type, p->dst); | |
153 +} | |
154 + | |
155 void | |
156 configurenotify(const XEvent *e) | |
157 { | |
158 @@ -771,7 +805,7 @@ manage(Window w) | |
159 focus(nextfocus ? nextpos : | |
160 sel < 0 ? 0 : | |
161 sel); | |
162 - nextfocus = foreground; | |
163 + nextfocus = focusnew; | |
164 } | |
165 } | |
166 | |
167 @@ -897,6 +931,40 @@ resize(int c, int w, int h) | |
168 (XEvent *)&ce); | |
169 } | |
170 | |
171 +int | |
172 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, voi… | |
173 +{ | |
174 + char **sdst = dst; | |
175 + int *idst = dst; | |
176 + float *fdst = dst; | |
177 + | |
178 + char fullname[256]; | |
179 + char fullclass[256]; | |
180 + char *type; | |
181 + XrmValue ret; | |
182 + | |
183 + snprintf(fullname, sizeof(fullname), "%s.%s", "tabbed", name); | |
184 + snprintf(fullclass, sizeof(fullclass), "%s.%s", "tabbed", name); | |
185 + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - … | |
186 + | |
187 + XrmGetResource(db, fullname, fullclass, &type, &ret); | |
188 + if (ret.addr == NULL || strncmp("String", type, 64)) | |
189 + return 1; | |
190 + | |
191 + switch (rtype) { | |
192 + case STRING: | |
193 + *sdst = ret.addr; | |
194 + break; | |
195 + case INTEGER: | |
196 + *idst = strtoul(ret.addr, NULL, 10); | |
197 + break; | |
198 + case FLOAT: | |
199 + *fdst = strtof(ret.addr, NULL); | |
200 + break; | |
201 + } | |
202 + return 0; | |
203 +} | |
204 + | |
205 void | |
206 rotate(const Arg *arg) | |
207 { | |
208 @@ -1074,7 +1142,7 @@ setup(void) | |
209 snprintf(winid, sizeof(winid), "%lu", win); | |
210 setenv("XEMBED", winid, 1); | |
211 | |
212 - nextfocus = foreground; | |
213 + nextfocus = focusnew; | |
214 focus(-1); | |
215 } | |
216 | |
217 @@ -1354,6 +1422,7 @@ main(int argc, char *argv[]) | |
218 if (!(dpy = XOpenDisplay(NULL))) | |
219 die("%s: cannot open display\n", argv0); | |
220 | |
221 + config_init(); | |
222 setup(); | |
223 printf("0x%lx\n", win); | |
224 fflush(NULL); | |
225 -- | |
226 2.25.1 | |
227 |