aboutsummaryrefslogtreecommitdiff
path: root/x.c
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-12-22 15:58:48 -0800
committerMike Crute <mike@crute.us>2023-04-25 20:45:27 -0700
commitba77c544805651604b722f2dafca867843868dd1 (patch)
tree7263b6bc32e36acd0d4ce219f039c6dde369338b /x.c
parenta9e2518e51378e844344eaf4c7f40cffea000b7a (diff)
downloadst-patched-ba77c544805651604b722f2dafca867843868dd1.tar.bz2
st-patched-ba77c544805651604b722f2dafca867843868dd1.tar.xz
st-patched-ba77c544805651604b722f2dafca867843868dd1.zip
Apply st-xresources-20200604-9ba7ecf
Diffstat (limited to 'x.c')
-rw-r--r--x.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/x.c b/x.c
index d000dcc..c9083db 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
@@ -865,8 +879,8 @@ xclear(int x1, int y1, int x2, int y2)
865void 879void
866xhints(void) 880xhints(void)
867{ 881{
868 XClassHint class = {opt_name ? opt_name : termname, 882 XClassHint class = {opt_name ? opt_name : "st",
869 opt_class ? opt_class : termname}; 883 opt_class ? opt_class : "St"};
870 XWMHints wm = {.flags = InputHint, .input = 1}; 884 XWMHints wm = {.flags = InputHint, .input = 1};
871 XSizeHints *sizeh; 885 XSizeHints *sizeh;
872 886
@@ -1142,8 +1156,6 @@ xinit(int cols, int rows)
1142 pid_t thispid = getpid(); 1156 pid_t thispid = getpid();
1143 XColor xmousefg, xmousebg; 1157 XColor xmousefg, xmousebg;
1144 1158
1145 if (!(xw.dpy = XOpenDisplay(NULL)))
1146 die("can't open display\n");
1147 xw.scr = XDefaultScreen(xw.dpy); 1159 xw.scr = XDefaultScreen(xw.dpy);
1148 xw.vis = XDefaultVisual(xw.dpy, xw.scr); 1160 xw.vis = XDefaultVisual(xw.dpy, xw.scr);
1149 1161
@@ -2021,6 +2033,59 @@ run(void)
2021 } 2033 }
2022} 2034}
2023 2035
2036int
2037resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
2038{
2039 char **sdst = dst;
2040 int *idst = dst;
2041 float *fdst = dst;
2042
2043 char fullname[256];
2044 char fullclass[256];
2045 char *type;
2046 XrmValue ret;
2047
2048 snprintf(fullname, sizeof(fullname), "%s.%s",
2049 opt_name ? opt_name : "st", name);
2050 snprintf(fullclass, sizeof(fullclass), "%s.%s",
2051 opt_class ? opt_class : "St", name);
2052 fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
2053
2054 XrmGetResource(db, fullname, fullclass, &type, &ret);
2055 if (ret.addr == NULL || strncmp("String", type, 64))
2056 return 1;
2057
2058 switch (rtype) {
2059 case STRING:
2060 *sdst = ret.addr;
2061 break;
2062 case INTEGER:
2063 *idst = strtoul(ret.addr, NULL, 10);
2064 break;
2065 case FLOAT:
2066 *fdst = strtof(ret.addr, NULL);
2067 break;
2068 }
2069 return 0;
2070}
2071
2072void
2073config_init(void)
2074{
2075 char *resm;
2076 XrmDatabase db;
2077 ResourcePref *p;
2078
2079 XrmInitialize();
2080 resm = XResourceManagerString(xw.dpy);
2081 if (!resm)
2082 return;
2083
2084 db = XrmGetStringDatabase(resm);
2085 for (p = resources; p < resources + LEN(resources); p++)
2086 resource_load(db, p->name, p->type, p->dst);
2087}
2088
2024void 2089void
2025usage(void) 2090usage(void)
2026{ 2091{
@@ -2094,6 +2159,11 @@ run:
2094 2159
2095 setlocale(LC_CTYPE, ""); 2160 setlocale(LC_CTYPE, "");
2096 XSetLocaleModifiers(""); 2161 XSetLocaleModifiers("");
2162
2163 if(!(xw.dpy = XOpenDisplay(NULL)))
2164 die("Can't open display\n");
2165
2166 config_init();
2097 cols = MAX(cols, 1); 2167 cols = MAX(cols, 1);
2098 rows = MAX(rows, 1); 2168 rows = MAX(rows, 1);
2099 tnew(cols, rows); 2169 tnew(cols, rows);