dwm-xrdb-6.1.diff (5594B)
1 diff --git a/config.def.h b/config.def.h 2 index 7054c06..436e16f 100644 3 --- a/config.def.h 4 +++ b/config.def.h 5 @@ -5,12 +5,12 @@ static const char *fonts[] = { 6 "monospace:size=10" 7 }; 8 static const char dmenufont[] = "monospace:size=10"; 9 -static const char normbordercolor[] = "#444444"; 10 -static const char normbgcolor[] = "#222222"; 11 -static const char normfgcolor[] = "#bbbbbb"; 12 -static const char selbordercolor[] = "#005577"; 13 -static const char selbgcolor[] = "#005577"; 14 -static const char selfgcolor[] = "#eeeeee"; 15 +static char normbordercolor[] = "#444444"; 16 +static char normbgcolor[] = "#222222"; 17 +static char normfgcolor[] = "#bbbbbb"; 18 +static char selbordercolor[] = "#005577"; 19 +static char selbgcolor[] = "#005577"; 20 +static char selfgcolor[] = "#eeeeee"; 21 static const unsigned int borderpx = 1; /* border pixel of windows */ 22 static const unsigned int snap = 32; /* snap pixel */ 23 static const int showbar = 1; /* 0 means no bar */ 24 @@ -82,6 +82,7 @@ static Key keys[] = { 25 { MODKEY, XK_period, focusmon, {.i = +1 } }, 26 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 27 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 28 + { MODKEY, XK_F5, xrdb, {.v = NULL } }, 29 TAGKEYS( XK_1, 0) 30 TAGKEYS( XK_2, 1) 31 TAGKEYS( XK_3, 2) 32 @@ -110,4 +111,3 @@ static Button buttons[] = { 33 { ClkTagBar, MODKEY, Button1, tag, {0} }, 34 { ClkTagBar, MODKEY, Button3, toggletag, {0} }, 35 }; 36 - 37 diff --git a/dwm.c b/dwm.c 38 index 0362114..bb1238c 100644 39 --- a/dwm.c 40 +++ b/dwm.c 41 @@ -35,6 +35,7 @@ 42 #include <X11/Xatom.h> 43 #include <X11/Xlib.h> 44 #include <X11/Xproto.h> 45 +#include <X11/Xresource.h> 46 #include <X11/Xutil.h> 47 #ifdef XINERAMA 48 #include <X11/extensions/Xinerama.h> 49 @@ -56,6 +57,21 @@ 50 #define HEIGHT(X) ((X)->h + 2 * (X)->bw) 51 #define TAGMASK ((1 << LENGTH(tags)) - 1) 52 #define TEXTW(X) (drw_text(drw, 0, 0, 0, 0, (X), 0) + drw->fonts[0]->h) 53 +#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \ 54 + if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \ 55 + int i = 1; \ 56 + for (; i <= 6; i++) { \ 57 + if (value.addr[i] < 48) break; \ 58 + if (value.addr[i] > 57 && value.addr[i] < 65) break; \ 59 + if (value.addr[i] > 70 && value.addr[i] < 97) break; \ 60 + if (value.addr[i] > 102) break; \ 61 + } \ 62 + if (i == 7) { \ 63 + strncpy(V, value.addr, 7); \ 64 + V[7] = '\0'; \ 65 + } \ 66 + } \ 67 + } 68 69 /* enums */ 70 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 71 @@ -178,6 +194,7 @@ static void grabkeys(void); 72 static void incnmaster(const Arg *arg); 73 static void keypress(XEvent *e); 74 static void killclient(const Arg *arg); 75 +static void loadxrdb(void); 76 static void manage(Window w, XWindowAttributes *wa); 77 static void mappingnotify(XEvent *e); 78 static void maprequest(XEvent *e); 79 @@ -232,6 +249,7 @@ static Monitor *wintomon(Window w); 80 static int xerror(Display *dpy, XErrorEvent *ee); 81 static int xerrordummy(Display *dpy, XErrorEvent *ee); 82 static int xerrorstart(Display *dpy, XErrorEvent *ee); 83 +static void xrdb(const Arg *arg); 84 static void zoom(const Arg *arg); 85 86 /* variables */ 87 @@ -1029,6 +1047,37 @@ killclient(const Arg *arg) 88 } 89 } 90 91 +void 92 +loadxrdb() 93 +{ 94 + Display *display; 95 + char *resm; 96 + XrmDatabase xrdb; 97 + char *type; 98 + XrmValue value; 99 + 100 + display = XOpenDisplay(NULL); 101 + 102 + if (display != NULL) { 103 + resm = XResourceManagerString(display); 104 + 105 + if (resm != NULL) { 106 + xrdb = XrmGetStringDatabase(resm); 107 + 108 + if (xrdb != NULL) { 109 + XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor); 110 + XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor); 111 + XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor); 112 + XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor); 113 + XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor); 114 + XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor); 115 + } 116 + } 117 + } 118 + 119 + XCloseDisplay(display); 120 +} 121 + 122 void 123 manage(Window w, XWindowAttributes *wa) 124 { 125 @@ -2106,6 +2155,22 @@ xerrorstart(Display *dpy, XErrorEvent *ee) 126 return -1; 127 } 128 129 +void 130 +xrdb(const Arg *arg) 131 +{ 132 + loadxrdb(); 133 + 134 + scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor); 135 + scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor); 136 + scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor); 137 + scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor); 138 + scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor); 139 + scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor); 140 + 141 + focus(NULL); 142 + arrange(NULL); 143 +} 144 + 145 void 146 zoom(const Arg *arg) 147 { 148 @@ -2132,6 +2197,8 @@ main(int argc, char *argv[]) 149 if (!(dpy = XOpenDisplay(NULL))) 150 die("dwm: cannot open display\n"); 151 checkotherwm(); 152 + XrmInitialize(); 153 + loadxrdb(); 154 setup(); 155 scan(); 156 run();