1 diff --git a/config.def.h b/config.def.h
2 index 91ab8cab2c..d3f9f00cbc 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -170,6 +170,42 @@ static unsigned int defaultattr = 11;
6 */
7 static uint forcemousemod = ShiftMask;
8
9 +/*
10 + * Xresources preferences to load at startup
11 + */
12 +ResourcePref resources[] = {
13 + { "font", STRING, &font },
14 + { "color0", STRING, &colorname[0] },
15 + { "color1", STRING, &colorname[1] },
16 + { "color2", STRING, &colorname[2] },
17 + { "color3", STRING, &colorname[3] },
18 + { "color4", STRING, &colorname[4] },
19 + { "color5", STRING, &colorname[5] },
20 + { "color6", STRING, &colorname[6] },
21 + { "color7", STRING, &colorname[7] },
22 + { "color8", STRING, &colorname[8] },
23 + { "color9", STRING, &colorname[9] },
24 + { "color10", STRING, &colorname[10] },
25 + { "color11", STRING, &colorname[11] },
26 + { "color12", STRING, &colorname[12] },
27 + { "color13", STRING, &colorname[13] },
28 + { "color14", STRING, &colorname[14] },
29 + { "color15", STRING, &colorname[15] },
30 + { "background", STRING, &colorname[259] },
31 + { "foreground", STRING, &colorname[258] },
32 + { "cursorColor", STRING, &colorname[256] },
33 + { "termname", STRING, &termname },
34 + { "shell", STRING, &shell },
35 + { "minlatency", INTEGER, &minlatency },
36 + { "maxlatency", INTEGER, &maxlatency },
37 + { "blinktimeout", INTEGER, &blinktimeout },
38 + { "bellvolume", INTEGER, &bellvolume },
39 + { "tabspaces", INTEGER, &tabspaces },
40 + { "borderpx", INTEGER, &borderpx },
41 + { "cwscale", FLOAT, &cwscale },
42 + { "chscale", FLOAT, &chscale },
43 +};
44 +
45 /*
46 * Internal mouse shortcuts.
47 * Beware that overloading Button1 will disable the selection.
48 @@ -177,10 +213,12 @@ static uint forcemousemod = ShiftMask;
49 static MouseShortcut mshortcuts[] = {
50 /* mask button function argument release */
51 { XK_ANY_MOD, Button2, selpaste, {.i = 0}, 1 },
52 + /*
53 { ShiftMask, Button4, ttysend, {.s = "\033[5;2~"} },
54 { XK_ANY_MOD, Button4, ttysend, {.s = "\031"} },
55 { ShiftMask, Button5, ttysend, {.s = "\033[6;2~"} },
56 { XK_ANY_MOD, Button5, ttysend, {.s = "\005"} },
57 + */
58 };
59
60 /* Internal keyboard shortcuts. */
61 diff --git a/x.c b/x.c
62 index 8a16faaad0..2cce27d1c9 100644
63 --- a/x.c
64 +++ b/x.c
65 @@ -14,6 +14,7 @@
66 #include <X11/keysym.h>
67 #include <X11/Xft/Xft.h>
68 #include <X11/XKBlib.h>
69 +#include <X11/Xresource.h>
70
71 char *argv0;
72 #include "arg.h"
73 @@ -45,6 +46,19 @@ typedef struct {
74 signed char appcursor; /* application cursor */
75 } Key;
76
77 +/* Xresources preferences */
78 +enum resource_type {
79 + STRING = 0,
80 + INTEGER = 1,
81 + FLOAT = 2
82 +};
83 +
84 +typedef struct {
85 + char *name;
86 + enum resource_type type;
87 + void *dst;
88 +} ResourcePref;
89 +
90 /* X modifiers */
91 #define XK_ANY_MOD UINT_MAX
92 #define XK_NO_MOD 0
93 @@ -843,8 +857,8 @@ xclear(int x1, int y1, int x2, int y2)
94 void
95 xhints(void)
96 {
97 - XClassHint class = {opt_name ? opt_name : termname,
98 - opt_class ? opt_class : termname};
99 + XClassHint class = {opt_name ? opt_name : "st",
100 + opt_class ? opt_class : "St"};
101 XWMHints wm = {.flags = InputHint, .input = 1};
102 XSizeHints *sizeh;
103
104 @@ -1119,8 +1133,6 @@ xinit(int cols, int rows)
105 pid_t thispid = getpid();
106 XColor xmousefg, xmousebg;
107
108 - if (!(xw.dpy = XOpenDisplay(NULL)))
109 - die("can't open display\n");
110 xw.scr = XDefaultScreen(xw.dpy);
111 xw.vis = XDefaultVisual(xw.dpy, xw.scr);
112
113 @@ -1995,6 +2007,59 @@ run(void)
114 }
115 }
116
117 +int
118 +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
119 +{
120 + char **sdst = dst;
121 + int *idst = dst;
122 + float *fdst = dst;
123 +
124 + char fullname[256];
125 + char fullclass[256];
126 + char *type;
127 + XrmValue ret;
128 +
129 + snprintf(fullname, sizeof(fullname), "%s.%s",
130 + opt_name ? opt_name : "st", name);
131 + snprintf(fullclass, sizeof(fullclass), "%s.%s",
132 + opt_class ? opt_class : "St", name);
133 + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0';
134 +
135 + XrmGetResource(db, fullname, fullclass, &type, &ret);
136 + if (ret.addr == NULL || strncmp("String", type, 64))
137 + return 1;
138 +
139 + switch (rtype) {
140 + case STRING:
141 + *sdst = ret.addr;
142 + break;
143 + case INTEGER:
144 + *idst = strtoul(ret.addr, NULL, 10);
145 + break;
146 + case FLOAT:
147 + *fdst = strtof(ret.addr, NULL);
148 + break;
149 + }
150 + return 0;
151 +}
152 +
153 +void
154 +config_init(void)
155 +{
156 + char *resm;
157 + XrmDatabase db;
158 + ResourcePref *p;
159 +
160 + XrmInitialize();
161 + resm = XResourceManagerString(xw.dpy);
162 + if (!resm)
163 + return;
164 +
165 + db = XrmGetStringDatabase(resm);
166 + for (p = resources; p < resources + LEN(resources); p++)
167 + resource_load(db, p->name, p->type, p->dst);
168 +}
169 +
170 void
171 usage(void)
172 {
173 @@ -2068,6 +2133,11 @@ run:
174
175 setlocale(LC_CTYPE, "");
176 XSetLocaleModifiers("");
177 +
178 + if(!(xw.dpy = XOpenDisplay(NULL)))
179 + die("Can't open display\n");
180 +
181 + config_init();
182 cols = MAX(cols, 1);
183 rows = MAX(rows, 1);
184 tnew(cols, rows);
|