Add Xresources capability

master
noamcore 2018-10-23 14:26:26 -03:00 committed by Bert Münnich
parent b83d4fa1bf
commit 4853e17b83
2 changed files with 41 additions and 6 deletions

View File

@ -14,11 +14,11 @@ static const char * const BAR_FONT = "monospace:size=8";
/* colors:
* (see X(7) section "COLOR NAMES" for valid values)
*/
static const char * const WIN_BG_COLOR = "#555555";
static const char * const WIN_FS_COLOR = "#000000";
static const char * const SEL_COLOR = "#EEEEEE";
static const char * const BAR_BG_COLOR = "#222222";
static const char * const BAR_FG_COLOR = "#EEEEEE";
static char const * WIN_BG_COLOR = "#555555";
static char const * WIN_FS_COLOR = "#000000";
static char const * SEL_COLOR = "#EEEEEE";
static char const * BAR_BG_COLOR = "#222222";
static char const * BAR_FG_COLOR = "#EEEEEE";
#endif
#ifdef _IMAGE_CONFIG

View File

@ -27,6 +27,7 @@
#include <locale.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Xresource.h>
enum {
H_TEXT_PAD = 5,
@ -99,6 +100,35 @@ void win_check_wm_support(Display *dpy, Window root)
}
}
void get_xresource(Display *dpy, const char* rsc, const void* dst)
{
char *type;
XrmValue ret;
XrmDatabase db;
char fullname[256];
char *resource_manager;
XrmInitialize();
resource_manager = XResourceManagerString(dpy);
if (resource_manager == NULL)
return;
db = XrmGetStringDatabase(resource_manager);
if (db == NULL)
return;
snprintf(fullname, sizeof(fullname), ".%s", rsc);
fullname[sizeof(fullname) - 1] = '\0';
XrmGetResource(db, fullname, "String", &type, &ret);
if (ret.addr != NULL || !strncmp("String", type, 64)) {
*( (char **) dst ) = ret.addr;
}
}
#define INIT_ATOM_(atom) \
atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
@ -122,6 +152,11 @@ void win_init(win_t *win)
if (setlocale(LC_CTYPE, "") == NULL || XSupportsLocale() == 0)
error(0, 0, "No locale support");
get_xresource(e->dpy, "background", &WIN_BG_COLOR);
get_xresource(e->dpy, "background", &BAR_FG_COLOR);
get_xresource(e->dpy, "foreground", &BAR_BG_COLOR);
get_xresource(e->dpy, "foreground", &SEL_COLOR);
win_init_font(e, BAR_FONT);
win_alloc_color(e, WIN_BG_COLOR, &win->bgcol);
@ -210,7 +245,7 @@ void win_open(win_t *win)
e->depth, InputOutput, e->vis, 0, NULL);
if (win->xwin == None)
error(EXIT_FAILURE, 0, "Error creating X window");
XSelectInput(e->dpy, win->xwin,
ButtonReleaseMask | ButtonPressMask | KeyPressMask |
PointerMotionMask | StructureNotifyMask);