aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-05-13 17:10:29 -0700
committerMike Crute <mike@crute.us>2020-05-13 17:22:33 -0700
commitf127cc37c788d597bd68a543badf212d11fe17f7 (patch)
treed20228d37f716cdd310e31bde75d0dc886e21796
parentc414978de545c851e5e2ffcc531cd1066f70994a (diff)
downloadst-patched-f127cc37c788d597bd68a543badf212d11fe17f7.tar.bz2
st-patched-f127cc37c788d597bd68a543badf212d11fe17f7.tar.xz
st-patched-f127cc37c788d597bd68a543badf212d11fe17f7.zip
apply xresources patch
-rw-r--r--config.def.h48
-rw-r--r--x.c80
2 files changed, 118 insertions, 10 deletions
diff --git a/config.def.h b/config.def.h
index e71b6a2..b1160b5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -126,19 +126,21 @@ static const char *colorname[] = {
126 [255] = 0, 126 [255] = 0,
127 127
128 /* more colors can be added after 255 to use with DefaultXX */ 128 /* more colors can be added after 255 to use with DefaultXX */
129
130 "gray90",
131 "black",
129 "#cccccc", 132 "#cccccc",
130 "#555555", 133 "#555555",
131}; 134};
132 135
133
134/* 136/*
135 * Default colors (colorname index) 137 * Default colors (colorname index)
136 * foreground, background, cursor, reverse cursor 138 * foreground, background, cursor, reverse cursor
137 */ 139 */
138unsigned int defaultfg = 7; 140unsigned int defaultfg = 257;
139unsigned int defaultbg = 0; 141unsigned int defaultbg = 256;
140static unsigned int defaultcs = 256; 142static unsigned int defaultcs = 258;
141static unsigned int defaultrcs = 257; 143static unsigned int defaultrcs = 259;
142 144
143/* 145/*
144 * Default shape of cursor 146 * Default shape of cursor
@@ -170,6 +172,42 @@ static unsigned int mousebg = 0;
170static unsigned int defaultattr = 11; 172static unsigned int defaultattr = 11;
171 173
172/* 174/*
175 * Xresources preferences to load at startup
176 */
177ResourcePref resources[] = {
178 { "font", STRING, &font },
179 { "color0", STRING, &colorname[0] },
180 { "color1", STRING, &colorname[1] },
181 { "color2", STRING, &colorname[2] },
182 { "color3", STRING, &colorname[3] },
183 { "color4", STRING, &colorname[4] },
184 { "color5", STRING, &colorname[5] },
185 { "color6", STRING, &colorname[6] },
186 { "color7", STRING, &colorname[7] },
187 { "color8", STRING, &colorname[8] },
188 { "color9", STRING, &colorname[9] },
189 { "color10", STRING, &colorname[10] },
190 { "color11", STRING, &colorname[11] },
191 { "color12", STRING, &colorname[12] },
192 { "color13", STRING, &colorname[13] },
193 { "color14", STRING, &colorname[14] },
194 { "color15", STRING, &colorname[15] },
195 { "background", STRING, &colorname[256] },
196 { "foreground", STRING, &colorname[257] },
197 { "cursorColor", STRING, &colorname[258] },
198 { "cursorColorReverse", STRING, &colorname[259] },
199 { "termname", STRING, &termname },
200 { "shell", STRING, &shell },
201 { "cursorShape", INTEGER, &cursorshape },
202 { "blinktimeout", INTEGER, &blinktimeout },
203 { "bellvolume", INTEGER, &bellvolume },
204 { "tabspaces", INTEGER, &tabspaces },
205 { "borderpx", INTEGER, &borderpx },
206 { "cwscale", FLOAT, &cwscale },
207 { "chscale", FLOAT, &chscale },
208};
209
210/*
173 * Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set). 211 * Force mouse select/shortcuts while mask is active (when MODE_MOUSE is set).
174 * Note that if you want to use ShiftMask with selmasks, set this to an other 212 * Note that if you want to use ShiftMask with selmasks, set this to an other
175 * modifier, set to 0 to not use it. 213 * modifier, set to 0 to not use it.
diff --git a/x.c b/x.c
index bd4fff6..a012e74 100644
--- a/x.c
+++ b/x.c
@@ -14,6 +14,7 @@
14#include <X11/keysym.h> 14#include <X11/keysym.h>
15#include <X11/Xft/Xft.h> 15#include <X11/Xft/Xft.h>
16#include <X11/XKBlib.h> 16#include <X11/XKBlib.h>
17#include <X11/Xresource.h>
17 18
18char *argv0; 19char *argv0;
19#include "arg.h" 20#include "arg.h"
@@ -45,6 +46,19 @@ typedef struct {
45 signed char appcursor; /* application cursor */ 46 signed char appcursor; /* application cursor */
46} Key; 47} Key;
47 48
49/* Xresources preferences */
50enum resource_type {
51 STRING = 0,
52 INTEGER = 1,
53 FLOAT = 2
54};
55
56typedef struct {
57 char *name;
58 enum resource_type type;
59 void *dst;
60} ResourcePref;
61
48/* X modifiers */ 62/* X modifiers */
49#define XK_ANY_MOD UINT_MAX 63#define XK_ANY_MOD UINT_MAX
50#define XK_NO_MOD 0 64#define XK_NO_MOD 0
@@ -834,8 +848,8 @@ xclear(int x1, int y1, int x2, int y2)
834void 848void
835xhints(void) 849xhints(void)
836{ 850{
837 XClassHint class = {opt_name ? opt_name : termname, 851 XClassHint class = {opt_name ? opt_name : "st",
838 opt_class ? opt_class : termname}; 852 opt_class ? opt_class : "St"};
839 XWMHints wm = {.flags = InputHint, .input = 1}; 853 XWMHints wm = {.flags = InputHint, .input = 1};
840 XSizeHints *sizeh; 854 XSizeHints *sizeh;
841 855
@@ -1111,8 +1125,6 @@ xinit(int cols, int rows)
1111 pid_t thispid = getpid(); 1125 pid_t thispid = getpid();
1112 XColor xmousefg, xmousebg; 1126 XColor xmousefg, xmousebg;
1113 1127
1114 if (!(xw.dpy = XOpenDisplay(NULL)))
1115 die("can't open display\n");
1116 xw.scr = XDefaultScreen(xw.dpy); 1128 xw.scr = XDefaultScreen(xw.dpy);
1117 xw.vis = XDefaultVisual(xw.dpy, xw.scr); 1129 xw.vis = XDefaultVisual(xw.dpy, xw.scr);
1118 1130
@@ -1983,6 +1995,59 @@ run(void)
1983 } 1995 }
1984} 1996}
1985 1997
1998int
1999resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
2000{
2001 char **sdst = dst;
2002 int *idst = dst;
2003 float *fdst = dst;
2004
2005 char fullname[256];
2006 char fullclass[256];
2007 char *type;
2008 XrmValue ret;
2009
2010 snprintf(fullname, sizeof(fullname), "%s.%s",
2011 opt_name ? opt_name : "st", name);
2012 snprintf(fullclass, sizeof(fullclass), "%s.%s",
2013 opt_class ? opt_class : "St", name);
2014 fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
2015
2016 XrmGetResource(db, fullname, fullclass, &type, &ret);
2017 if (ret.addr == NULL || strncmp("String", type, 64))
2018 return 1;
2019
2020 switch (rtype) {
2021 case STRING:
2022 *sdst = ret.addr;
2023 break;
2024 case INTEGER:
2025 *idst = strtoul(ret.addr, NULL, 10);
2026 break;
2027 case FLOAT:
2028 *fdst = strtof(ret.addr, NULL);
2029 break;
2030 }
2031 return 0;
2032}
2033
2034void
2035config_init(void)
2036{
2037 char *resm;
2038 XrmDatabase db;
2039 ResourcePref *p;
2040
2041 XrmInitialize();
2042 resm = XResourceManagerString(xw.dpy);
2043 if (!resm)
2044 return;
2045
2046 db = XrmGetStringDatabase(resm);
2047 for (p = resources; p < resources + LEN(resources); p++)
2048 resource_load(db, p->name, p->type, p->dst);
2049}
2050
1986void 2051void
1987usage(void) 2052usage(void)
1988{ 2053{
@@ -2001,7 +2066,6 @@ main(int argc, char *argv[])
2001{ 2066{
2002 xw.l = xw.t = 0; 2067 xw.l = xw.t = 0;
2003 xw.isfixed = False; 2068 xw.isfixed = False;
2004 win.cursor = cursorshape;
2005 2069
2006 ARGBEGIN { 2070 ARGBEGIN {
2007 case 'a': 2071 case 'a':
@@ -2056,6 +2120,12 @@ run:
2056 2120
2057 setlocale(LC_CTYPE, ""); 2121 setlocale(LC_CTYPE, "");
2058 XSetLocaleModifiers(""); 2122 XSetLocaleModifiers("");
2123
2124 if(!(xw.dpy = XOpenDisplay(NULL)))
2125 die("Can't open display\n");
2126
2127 config_init();
2128 win.cursor = cursorshape;
2059 cols = MAX(cols, 1); 2129 cols = MAX(cols, 1);
2060 rows = MAX(rows, 1); 2130 rows = MAX(rows, 1);
2061 tnew(cols, rows); 2131 tnew(cols, rows);