Introduction
Introduction Statistics Contact Development Disclaimer Help
st-xresources-signal-reloading-20220407-ef05519.diff - sites - public wiki cont…
git clone git://git.suckless.org/sites
Log
Files
Refs
---
st-xresources-signal-reloading-20220407-ef05519.diff (3685B)
---
1 From b2a9c96cc3c9152c4e8188f341606c914741cb50 Mon Sep 17 00:00:00 2001
2 From: wael <[email protected]>
3 Date: Thu, 7 Apr 2022 17:14:02 +0300
4 Subject: [PATCH] fix xresources with signal reloading removing arg.h and…
5 & remove unneccesary xresources variables(?)
6
7 ---
8 x.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 1 file changed, 115 insertions(+)
10
11 diff --git a/x.c b/x.c
12 index 2a3bd38..e8fe7ad 100644
13 --- a/x.c
14 +++ b/x.c
15 @@ -14,6 +14,7 @@
16 #include <X11/keysym.h>
17 #include <X11/Xft/Xft.h>
18 #include <X11/XKBlib.h>
19 +#include <X11/Xresource.h>
20
21 char *argv0;
22 #include "arg.h"
23 @@ -2011,6 +2012,118 @@ run(void)
24 }
25 }
26
27 +
28 +#define XRESOURCE_LOAD_META(NAME) …
29 + if(!XrmGetResource(xrdb, "st." NAME, "st." NAME, &type, &ret)) …
30 + XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret)…
31 + if (ret.addr != NULL && !strncmp("String", type, 64))
32 +
33 +#define XRESOURCE_LOAD_STRING(NAME, DST) \
34 + XRESOURCE_LOAD_META(NAME) \
35 + DST = ret.addr;
36 +
37 +#define XRESOURCE_LOAD_CHAR(NAME, DST) \
38 + XRESOURCE_LOAD_META(NAME) \
39 + DST = ret.addr[0];
40 +
41 +#define XRESOURCE_LOAD_INTEGER(NAME, DST) \
42 + XRESOURCE_LOAD_META(NAME) \
43 + DST = strtoul(ret.addr, NULL, 10);
44 +
45 +#define XRESOURCE_LOAD_FLOAT(NAME, DST) \
46 + XRESOURCE_LOAD_META(NAME) \
47 + DST = strtof(ret.addr, NULL);
48 +
49 +void
50 +xrdb_load(void)
51 +{
52 + /* XXX */
53 + char *xrm;
54 + char *type;
55 + XrmDatabase xrdb;
56 + XrmValue ret;
57 + Display *dpy;
58 +
59 + if(!(dpy = XOpenDisplay(NULL)))
60 + die("Can't open display\n");
61 +
62 + XrmInitialize();
63 + xrm = XResourceManagerString(dpy);
64 +
65 + if (xrm != NULL) {
66 + xrdb = XrmGetStringDatabase(xrm);
67 +
68 + /* handling colors here without macros to do via loop. …
69 + int i = 0;
70 + char loadValue[12] = "";
71 + for (i = 0; i < 256; i++)
72 + {
73 + sprintf(loadValue, "%s%d", "st.color", i);
74 +
75 + if(!XrmGetResource(xrdb, loadValue, loadValue, …
76 + {
77 + sprintf(loadValue, "%s%d", "*.color", i…
78 + if (!XrmGetResource(xrdb, loadValue, lo…
79 + /* reset if not found (unless i…
80 + if (i > 15)
81 + colorname[i] = NULL;
82 + }
83 +
84 + if (ret.addr != NULL && !strncmp("String", type…
85 + colorname[i] = ret.addr;
86 + }
87 +
88 + XRESOURCE_LOAD_STRING("foreground", colorname[defaultfg…
89 + XRESOURCE_LOAD_STRING("background", colorname[defaultbg…
90 + XRESOURCE_LOAD_STRING("cursorColor", colorname[defaultc…
91 + else {
92 + // this looks confusing because we are chaining off o…
93 + // in the macro. probably we should be wrapping every…
94 + // so this isn't possible...
95 + defaultcs = defaultfg;
96 + }
97 + XRESOURCE_LOAD_STRING("reverse-cursor", colorname[defau…
98 + else {
99 + // see above.
100 + defaultrcs = defaultbg;
101 + }
102 +
103 + XRESOURCE_LOAD_STRING("font", font);
104 + XRESOURCE_LOAD_STRING("termname", termname);
105 +
106 + XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout);
107 + XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume);
108 + XRESOURCE_LOAD_INTEGER("borderpx", borderpx);
109 + XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape);
110 +
111 + XRESOURCE_LOAD_FLOAT("cwscale", cwscale);
112 + XRESOURCE_LOAD_FLOAT("chscale", chscale);
113 + }
114 + XFlush(dpy);
115 +}
116 +
117 +void
118 +reload(int sig)
119 +{
120 + xrdb_load();
121 +
122 + /* colors, fonts */
123 + xloadcols();
124 + xunloadfonts();
125 + xloadfonts(font, 0);
126 +
127 + /* pretend the window just got resized */
128 + cresize(win.w, win.h);
129 +
130 + redraw();
131 +
132 + /* triggers re-render if we're visible. */
133 + ttywrite("\033[O", 3, 1);
134 +
135 + signal(SIGUSR1, reload);
136 +}
137 +
138 +
139 void
140 usage(void)
141 {
142 @@ -2084,6 +2197,8 @@ run:
143
144 setlocale(LC_CTYPE, "");
145 XSetLocaleModifiers("");
146 + xrdb_load();
147 + signal(SIGUSR1, reload);
148 cols = MAX(cols, 1);
149 rows = MAX(rows, 1);
150 tnew(cols, rows);
151 --
152 2.35.1
153
You are viewing proxied material from suckless.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.