diff options
Diffstat (limited to 'x.c')
-rw-r--r-- | x.c | 80 |
1 files changed, 75 insertions, 5 deletions
@@ -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 | ||
18 | char *argv0; | 19 | char *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 */ | ||
50 | enum resource_type { | ||
51 | STRING = 0, | ||
52 | INTEGER = 1, | ||
53 | FLOAT = 2 | ||
54 | }; | ||
55 | |||
56 | typedef 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) | |||
834 | void | 848 | void |
835 | xhints(void) | 849 | xhints(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 | ||
1998 | int | ||
1999 | resource_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 | |||
2034 | void | ||
2035 | config_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 | |||
1986 | void | 2051 | void |
1987 | usage(void) | 2052 | usage(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); |