dwm-xrdb-6.3.diff (7448B)
1 From 164fed01ba802628b4349ddaec04ddf7fbb3eb81 Mon Sep 17 00:00:00 2001 2 From: NekoCWD <nekodevelopper@gmail.com> 3 Date: Sun, 15 Jan 2023 22:33:04 +0300 4 Subject: [PATCH] XRDB update for dwm6.3 5 6 --- 7 config.def.h | 22 ++++++++++--------- 8 drw.c | 2 +- 9 drw.h | 2 +- 10 dwm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 11 4 files changed, 76 insertions(+), 12 deletions(-) 12 13 diff --git a/config.def.h b/config.def.h 14 index a2ac963..0e83100 100644 15 --- a/config.def.h 16 +++ b/config.def.h 17 @@ -7,15 +7,16 @@ static const int showbar = 1; /* 0 means no bar */ 18 static const int topbar = 1; /* 0 means bottom bar */ 19 static const char *fonts[] = { "monospace:size=10" }; 20 static const char dmenufont[] = "monospace:size=10"; 21 -static const char col_gray1[] = "#222222"; 22 -static const char col_gray2[] = "#444444"; 23 -static const char col_gray3[] = "#bbbbbb"; 24 -static const char col_gray4[] = "#eeeeee"; 25 -static const char col_cyan[] = "#005577"; 26 -static const char *colors[][3] = { 27 - /* fg bg border */ 28 - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, 29 - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, 30 +static char normbgcolor[] = "#222222"; 31 +static char normbordercolor[] = "#444444"; 32 +static char normfgcolor[] = "#bbbbbb"; 33 +static char selfgcolor[] = "#eeeeee"; 34 +static char selbordercolor[] = "#005577"; 35 +static char selbgcolor[] = "#005577"; 36 +static char *colors[][3] = { 37 + /* fg bg border */ 38 + [SchemeNorm] = { normfgcolor, normbgcolor, normbordercolor }, 39 + [SchemeSel] = { selfgcolor, selbgcolor, selbordercolor }, 40 }; 41 42 /* tagging */ 43 @@ -57,7 +58,7 @@ static const Layout layouts[] = { 44 45 /* commands */ 46 static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ 47 -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; 48 +static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", normbgcolor, "-nf", normfgcolor, "-sb", selbordercolor, "-sf", selfgcolor, NULL }; 49 static const char *termcmd[] = { "st", NULL }; 50 51 static Key keys[] = { 52 @@ -85,6 +86,7 @@ static Key keys[] = { 53 { MODKEY, XK_period, focusmon, {.i = +1 } }, 54 { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, 55 { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, 56 + { MODKEY, XK_F5, xrdb, {.v = NULL } }, 57 TAGKEYS( XK_1, 0) 58 TAGKEYS( XK_2, 1) 59 TAGKEYS( XK_3, 2) 60 diff --git a/drw.c b/drw.c 61 index 4cdbcbe..8f1059e 100644 62 --- a/drw.c 63 +++ b/drw.c 64 @@ -208,7 +208,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) 65 /* Wrapper to create color schemes. The caller has to call free(3) on the 66 * returned color scheme when done using it. */ 67 Clr * 68 -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) 69 +drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount) 70 { 71 size_t i; 72 Clr *ret; 73 diff --git a/drw.h b/drw.h 74 index 4bcd5ad..42b04ce 100644 75 --- a/drw.h 76 +++ b/drw.h 77 @@ -39,7 +39,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in 78 79 /* Colorscheme abstraction */ 80 void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); 81 -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); 82 +Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount); 83 84 /* Cursor abstraction */ 85 Cur *drw_cur_create(Drw *drw, int shape); 86 diff --git a/dwm.c b/dwm.c 87 index a96f33c..0f58c6d 100644 88 --- a/dwm.c 89 +++ b/dwm.c 90 @@ -35,6 +35,7 @@ 91 #include <X11/Xatom.h> 92 #include <X11/Xlib.h> 93 #include <X11/Xproto.h> 94 +#include <X11/Xresource.h> 95 #include <X11/Xutil.h> 96 #ifdef XINERAMA 97 #include <X11/extensions/Xinerama.h> 98 @@ -56,6 +57,21 @@ 99 #define HEIGHT(X) ((X)->h + 2 * (X)->bw) 100 #define TAGMASK ((1 << LENGTH(tags)) - 1) 101 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) 102 +#define XRDB_LOAD_COLOR(R,V) if (XrmGetResource(xrdb, R, NULL, &type, &value) == True) { \ 103 + if (value.addr != NULL && strnlen(value.addr, 8) == 7 && value.addr[0] == '#') { \ 104 + int i = 1; \ 105 + for (; i <= 6; i++) { \ 106 + if (value.addr[i] < 48) break; \ 107 + if (value.addr[i] > 57 && value.addr[i] < 65) break; \ 108 + if (value.addr[i] > 70 && value.addr[i] < 97) break; \ 109 + if (value.addr[i] > 102) break; \ 110 + } \ 111 + if (i == 7) { \ 112 + strncpy(V, value.addr, 7); \ 113 + V[7] = '\0'; \ 114 + } \ 115 + } \ 116 + } 117 118 /* enums */ 119 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 120 @@ -178,6 +194,7 @@ static void grabkeys(void); 121 static void incnmaster(const Arg *arg); 122 static void keypress(XEvent *e); 123 static void killclient(const Arg *arg); 124 +static void loadxrdb(void); 125 static void manage(Window w, XWindowAttributes *wa); 126 static void mappingnotify(XEvent *e); 127 static void maprequest(XEvent *e); 128 @@ -233,6 +250,7 @@ static Monitor *wintomon(Window w); 129 static int xerror(Display *dpy, XErrorEvent *ee); 130 static int xerrordummy(Display *dpy, XErrorEvent *ee); 131 static int xerrorstart(Display *dpy, XErrorEvent *ee); 132 +static void xrdb(const Arg *arg); 133 static void zoom(const Arg *arg); 134 135 /* variables */ 136 @@ -1018,6 +1036,37 @@ killclient(const Arg *arg) 137 } 138 } 139 140 +void 141 +loadxrdb() 142 +{ 143 + Display *display; 144 + char * resm; 145 + XrmDatabase xrdb; 146 + char *type; 147 + XrmValue value; 148 + 149 + display = XOpenDisplay(NULL); 150 + 151 + if (display != NULL) { 152 + resm = XResourceManagerString(display); 153 + 154 + if (resm != NULL) { 155 + xrdb = XrmGetStringDatabase(resm); 156 + 157 + if (xrdb != NULL) { 158 + XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor); 159 + XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor); 160 + XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor); 161 + XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor); 162 + XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor); 163 + XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor); 164 + } 165 + } 166 + } 167 + 168 + XCloseDisplay(display); 169 +} 170 + 171 void 172 manage(Window w, XWindowAttributes *wa) 173 { 174 @@ -2116,6 +2165,17 @@ xerrorstart(Display *dpy, XErrorEvent *ee) 175 return -1; 176 } 177 178 +void 179 +xrdb(const Arg *arg) 180 +{ 181 + loadxrdb(); 182 + int i; 183 + for (i = 0; i < LENGTH(colors); i++) 184 + scheme[i] = drw_scm_create(drw, colors[i], 3); 185 + focus(NULL); 186 + arrange(NULL); 187 +} 188 + 189 void 190 zoom(const Arg *arg) 191 { 192 @@ -2142,6 +2202,8 @@ main(int argc, char *argv[]) 193 if (!(dpy = XOpenDisplay(NULL))) 194 die("dwm: cannot open display"); 195 checkotherwm(); 196 + XrmInitialize(); 197 + loadxrdb(); 198 setup(); 199 #ifdef __OpenBSD__ 200 if (pledge("stdio rpath proc exec", NULL) == -1) 201 -- 202 2.38.2 203