diff --git a/colors.h b/colors.h new file mode 100644 index 0000000..4d12d0a --- /dev/null +++ b/colors.h @@ -0,0 +1,27 @@ +/* ---------- styling guidlines ----------- */ +/* norm_fg : text color of unselected tags & status bar : (color15) light color same as urg_fg */ +/* norm_bg : bg color of unselected tags & status bar : (color0) dark color same as sel_fg */ +/* norm_border : border color of unselected clients : (color8) medium color */ +/* sel_fg : text color of selected tags : (color0) dark color same as norm_bg */ +/* sel_bg : bg color of selected tags : (color4) main color same as sel_border */ +/* sel_border : border color of selected tags : (color4) main color same as sel_bg */ +/* urg_fg : text color of urgent tags : (color15) light color same as norm_fg */ +/* urg_bg : bg color of urgent tags : (color1) urgent color same as urg_border */ +/* urg_border : border color of urgent clients : (color1) urgent color same as urg_bg */ + +/* ------------ gruvbox theme ------------- */ +static char norm_fg[] = "#ebdbb2"; +static char norm_bg[] = "#282828"; +static char norm_border[] = "#928374"; +static char sel_fg[] = "#282828"; +static char sel_bg[] = "#458588"; +static char sel_border[] = "#458588"; +static char urg_fg[] = "#ebdbb2"; +static char urg_bg[] = "#cc241d"; +static char urg_border[] = "#cc241d"; +static char *colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { norm_fg, norm_bg, norm_border }, + [SchemeSel] = { sel_fg, sel_bg, sel_border }, + [SchemeUrg] = { urg_fg, urg_bg, urg_border }, +}; diff --git a/config.h b/config.h index e09241a..38b010b 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* -------------- appearance ------------- */ +#include "colors.h" static const char *fonts[] = { "monospace:size=10" }; static const unsigned int borderpx = 2; /* border pixel of windows */ static const unsigned int snap = 10; /* snap pixel */ @@ -11,24 +12,11 @@ static const unsigned int gappiv = 10; /* vert inner gap between window static const unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ static const unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ -static const int barheight = 25; /* 0 means dwm will calculate bar height wrt font */ +static int barheight = 25; /* 0 means dwm will calculate bar height wrt font */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ #define VIEWONTAG 1 /* switch view on tag switch */ -static const char col_gray1[] = "#222222"; -static const char col_gray2[] = "#444444"; -static const char col_gray3[] = "#bbbbbb"; -static const char col_gray4[] = "#eeeeee"; -static const char col_cyan[] = "#005577"; -static const char col_urgborder[] = "#ff0000"; -static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, - [SchemeUrg] = { col_gray4, col_cyan, col_urgborder }, -}; - /* ----------------- sticky -------------- */ static const XPoint stickyicon[] = { {0,0}, {4,0}, {4,8}, {2,6}, {0,8}, {0,0} }; /* represents the icon as an array of vertices */ static const XPoint stickyiconbb = {4,8}; /* defines the bottom right corner of the polygon's bounding box (speeds up scaling) */ @@ -80,6 +68,20 @@ static const Layout layouts[] = { { NULL, NULL }, }; +/* --------------- Xresources ------------ */ +ResourcePref resources[] = { + { "color15", STRING, &norm_fg }, + { "color0", STRING, &norm_bg }, + { "color8", STRING, &norm_border }, + { "color0", STRING, &sel_fg }, + { "color4", STRING, &sel_bg }, + { "color4", STRING, &sel_border }, + { "color15", STRING, &urg_fg }, + { "color1", STRING, &urg_bg }, + { "color1", STRING, &urg_border }, + { "barheight", INTEGER, &barheight }, +}; + /* ----------- key definitions ----------- */ #define MODKEY Mod4Mask #define TAGKEYS(KEY,TAG) \ @@ -114,8 +116,9 @@ static Key keys[] = { { MODKEY, XK_Return, spawn, {.v = termcmd } }, { MODKEY, XK_space, spawn, {.v = termcmd } }, /* one handed mode */ { MODKEY, XK_d, spawn, {.v = menucmd } }, - { MODKEY|ShiftMask, XK_q, quit, {0} }, + { MODKEY|ShiftMask, XK_q, xrdb, {.v = NULL } }, { MODKEY, XK_q, quit, {1} }, + { MODKEY|ControlMask, XK_q, quit, {0} }, /* ---------- layouts ---------- */ { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, /* tile */ diff --git a/drw.c b/drw.c index 0585e5d..5c31b62 100644 --- a/drw.c +++ b/drw.c @@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) /* Wrapper to create color schemes. The caller has to call free(3) on the * returned color scheme when done using it. */ Clr * -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) +drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount) { size_t i; Clr *ret; diff --git a/drw.h b/drw.h index cb1f24b..9b0c6e9 100644 --- a/drw.h +++ b/drw.h @@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in /* Colorscheme abstraction */ void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); +Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount); /* Cursor abstraction */ Cur *drw_cur_create(Drw *drw, int shape); diff --git a/dwm.c b/dwm.c index fce8eb3..ca57bb9 100644 --- a/dwm.c +++ b/dwm.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #ifdef XINERAMA #include @@ -157,6 +158,19 @@ typedef struct { const char scratchkey; } Rule; +/* Xresources preferences */ +enum resource_type { + STRING = 0, + INTEGER = 1, + FLOAT = 2 +}; + +typedef struct { + char *name; + enum resource_type type; + void *dst; +} ResourcePref; + /* function declarations */ static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); @@ -201,6 +215,7 @@ static void grabkeys(void); static void incnmaster(const Arg *arg); static void keypress(XEvent *e); static void killclient(const Arg *arg); +static void loadxresources(void); static void losefullscreen(Client *next); static void manage(Window w, XWindowAttributes *wa); static void mappingnotify(XEvent *e); @@ -221,6 +236,7 @@ static void reorganizetags(const Arg *arg); static void resize(Client *c, int x, int y, int w, int h, int interact); static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); +static void resourceload(XrmDatabase db, char *name, enum resource_type rtype, void *dst); static void restack(Monitor *m); static void rotatestack(const Arg *arg); static void run(void); @@ -273,6 +289,7 @@ static Monitor *wintomon(Window w); static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); +static void xrdb(const Arg *arg); static void zoom(const Arg *arg); /* variables */ @@ -1464,6 +1481,25 @@ killclient(const Arg *arg) } } +void +loadxresources(void) +{ + Display *display; + char *resm; + XrmDatabase db; + ResourcePref *p; + + display = XOpenDisplay(NULL); + resm = XResourceManagerString(display); + if (!resm) + return; + + db = XrmGetStringDatabase(resm); + for (p = resources; p < resources + LENGTH(resources); p++) + resourceload(db, p->name, p->type, p->dst); + XCloseDisplay(display); +} + void losefullscreen(Client *next) { @@ -2019,6 +2055,41 @@ resizemouse(const Arg *arg) } } +void +resourceload(XrmDatabase db, char *name, enum resource_type rtype, void *dst) +{ + char *sdst = NULL; + int *idst = NULL; + float *fdst = NULL; + + sdst = dst; + idst = dst; + fdst = dst; + + char fullname[256]; + char *type; + XrmValue ret; + + snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name); + fullname[sizeof(fullname) - 1] = '\0'; + + XrmGetResource(db, fullname, "*", &type, &ret); + if (!(ret.addr == NULL || strncmp("String", type, 64))) + { + switch (rtype) { + case STRING: + strcpy(sdst, ret.addr); + break; + case INTEGER: + *idst = strtoul(ret.addr, NULL, 10); + break; + case FLOAT: + *fdst = strtof(ret.addr, NULL); + break; + } + } +} + void restack(Monitor *m) { @@ -3265,6 +3336,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee) return -1; } +void +xrdb(const Arg *arg) +{ + loadxresources(); + int i; + for (i = 0; i < LENGTH(colors); i++) + scheme[i] = drw_scm_create(drw, colors[i], 3); + focus(NULL); + arrange(NULL); +} + void zoom(const Arg *arg) { @@ -3291,6 +3373,8 @@ main(int argc, char *argv[]) if (!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display"); checkotherwm(); + XrmInitialize(); + loadxresources(); setup(); #ifdef __OpenBSD__ if (pledge("stdio rpath proc exec", NULL) == -1)