Krolyxon
Commit 4853e17

Branches

Refs →

nsxiv4853e17

Add Xresources capability

Author
noamcore
Date
2018-10-23 14:26 -0300
Committer
Bert Münnich · 2019-01-23 19:53 +0100
Parent
b83d4fa
Commit
4853e17b831c4ce7021fb314eaa4dafded024d90

+41 −6

2 files changed

  1. M config.def.h +5 −5
  2. M window.c +36 −1
M config.def.h View
@@ -14,11 +14,11 @@ static const char * const BAR_FONT = "monospace:size=8";
1414 /* colors:
1515 * (see X(7) section "COLOR NAMES" for valid values)
1616 */
17−static const char * const WIN_BG_COLOR = "#555555";
18−static const char * const WIN_FS_COLOR = "#000000";
19−static const char * const SEL_COLOR = "#EEEEEE";
20−static const char * const BAR_BG_COLOR = "#222222";
21−static const char * const BAR_FG_COLOR = "#EEEEEE";
17+static char const * WIN_BG_COLOR = "#555555";
18+static char const * WIN_FS_COLOR = "#000000";
19+static char const * SEL_COLOR = "#EEEEEE";
20+static char const * BAR_BG_COLOR = "#222222";
21+static char const * BAR_FG_COLOR = "#EEEEEE";
2222
2323 #endif
2424 #ifdef _IMAGE_CONFIG
M window.c View
@@ -27,6 +27,7 @@
2727 #include <locale.h>
2828 #include <X11/cursorfont.h>
2929 #include <X11/Xatom.h>
30+#include <X11/Xresource.h>
3031
3132 enum {
3233 H_TEXT_PAD = 5,
@@ -99,6 +100,35 @@ void win_check_wm_support(Display *dpy, Window root)
99100 }
100101 }
101102
103+void get_xresource(Display *dpy, const char* rsc, const void* dst)
104+{
105+ char *type;
106+ XrmValue ret;
107+ XrmDatabase db;
108+ char fullname[256];
109+ char *resource_manager;
110+
111+ XrmInitialize();
112+ resource_manager = XResourceManagerString(dpy);
113+
114+ if (resource_manager == NULL)
115+ return;
116+
117+ db = XrmGetStringDatabase(resource_manager);
118+
119+ if (db == NULL)
120+ return;
121+
122+ snprintf(fullname, sizeof(fullname), ".%s", rsc);
123+ fullname[sizeof(fullname) - 1] = '\0';
124+
125+ XrmGetResource(db, fullname, "String", &type, &ret);
126+
127+ if (ret.addr != NULL || !strncmp("String", type, 64)) {
128+ *( (char **) dst ) = ret.addr;
129+ }
130+}
131+
102132 #define INIT_ATOM_(atom) \
103133 atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
104134
@@ -122,6 +152,11 @@ void win_init(win_t *win)
122152 if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
123153 error(0, 0, "No locale support");
124154
155+ get_xresource(e->dpy, "background", &WIN_BG_COLOR);
156+ get_xresource(e->dpy, "background", &BAR_FG_COLOR);
157+ get_xresource(e->dpy, "foreground", &BAR_BG_COLOR);
158+ get_xresource(e->dpy, "foreground", &SEL_COLOR);
159+
125160 win_init_font(e, BAR_FONT);
126161
127162 win_alloc_color(e, WIN_BG_COLOR, &win->bgcol);
@@ -210,7 +245,7 @@ void win_open(win_t *win)
210245 e->depth, InputOutput, e->vis, 0, NULL);
211246 if (win->xwin == None)
212247 error(EXIT_FAILURE, 0, "Error creating X window");
213−
248+
214249 XSelectInput(e->dpy, win->xwin,
215250 ButtonReleaseMask | ButtonPressMask | KeyPressMask |
216251 PointerMotionMask | StructureNotifyMask);