| tabbed-xresources-signal-reloading-20220622-014eabf.diff - sites - public wiki … | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| tabbed-xresources-signal-reloading-20220622-014eabf.diff (3895B) | |
| --- | |
| 1 From 014eabf578fb7d4b37c368c6e110e99897b6013d Mon Sep 17 00:00:00 2001 | |
| 2 From: Mahdi Mirzadeh <[email protected]> | |
| 3 Date: Wed, 22 Jun 2022 04:26:22 +0430 | |
| 4 Subject: [PATCH] handle tabbed settings from Xresources + reload all tab… | |
| 5 instances by running 'pidof tabbed | xargs kill -s USR1' | |
| 6 | |
| 7 --- | |
| 8 config.def.h | 2 +- | |
| 9 tabbed.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
| 10 2 files changed, 68 insertions(+), 1 deletion(-) | |
| 11 | |
| 12 diff --git a/config.def.h b/config.def.h | |
| 13 index defa426..f6d59b2 100644 | |
| 14 --- a/config.def.h | |
| 15 +++ b/config.def.h | |
| 16 @@ -1,7 +1,7 @@ | |
| 17 /* See LICENSE file for copyright and license details. */ | |
| 18 | |
| 19 /* appearance */ | |
| 20 -static const char font[] = "monospace:size=9"; | |
| 21 +static const char* font = "monospace:size=9"; | |
| 22 static const char* normbgcolor = "#222222"; | |
| 23 static const char* normfgcolor = "#cccccc"; | |
| 24 static const char* selbgcolor = "#555555"; | |
| 25 diff --git a/tabbed.c b/tabbed.c | |
| 26 index eafe28a..829c58b 100644 | |
| 27 --- a/tabbed.c | |
| 28 +++ b/tabbed.c | |
| 29 @@ -16,6 +16,7 @@ | |
| 30 #include <X11/Xutil.h> | |
| 31 #include <X11/XKBlib.h> | |
| 32 #include <X11/Xft/Xft.h> | |
| 33 +#include <X11/Xresource.h> | |
| 34 | |
| 35 #include "arg.h" | |
| 36 | |
| 37 @@ -47,6 +48,16 @@ | |
| 38 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) | |
| 39 #define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height) | |
| 40 | |
| 41 +#define XRESOURCE_LOAD_META(NAME) … | |
| 42 + if(!XrmGetResource(xrdb, "tabbed." NAME, "tabbed." NAME, &type,… | |
| 43 + XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret)… | |
| 44 + if (ret.addr != NULL && !strncmp("String", type, 64)) | |
| 45 + | |
| 46 +#define XRESOURCE_LOAD_STRING(NAME, DST) \ | |
| 47 + XRESOURCE_LOAD_META(NAME) \ | |
| 48 + DST = ret.addr; | |
| 49 + | |
| 50 + | |
| 51 enum { ColFG, ColBG, ColLast }; /* color */ | |
| 52 enum { WMProtocols, WMDelete, WMName, WMState, WMFullscreen, | |
| 53 XEmbed, WMSelectTab, WMLast }; /* default atoms */ | |
| 54 @@ -135,6 +146,9 @@ static void updatenumlockmask(void); | |
| 55 static void updatetitle(int c); | |
| 56 static int xerror(Display *dpy, XErrorEvent *ee); | |
| 57 static void xsettitle(Window w, const char *str); | |
| 58 +static void xrdb_load(void); | |
| 59 +static void reload(int sig); | |
| 60 +static void writecolors(void); | |
| 61 | |
| 62 /* variables */ | |
| 63 static int screen; | |
| 64 @@ -172,6 +186,8 @@ static const char *geometry; | |
| 65 | |
| 66 char *argv0; | |
| 67 | |
| 68 +static int colors_changed = 0; | |
| 69 + | |
| 70 /* configuration, allows nested code to access above variables */ | |
| 71 #include "config.h" | |
| 72 | |
| 73 @@ -327,6 +343,8 @@ drawbar(void) | |
| 74 int c, cc, fc, width; | |
| 75 char *name = NULL; | |
| 76 | |
| 77 + if (colors_changed == 1) writecolors(); | |
| 78 + | |
| 79 if (nclients == 0) { | |
| 80 dc.x = 0; | |
| 81 dc.w = ww; | |
| 82 @@ -1273,6 +1291,53 @@ usage(void) | |
| 83 " [-u color] [-U color] command...\n", argv0); | |
| 84 } | |
| 85 | |
| 86 +void | |
| 87 +xrdb_load(void) | |
| 88 +{ | |
| 89 + char *xrm; | |
| 90 + char *type; | |
| 91 + XrmDatabase xrdb; | |
| 92 + XrmValue ret; | |
| 93 + Display *dpy; | |
| 94 + | |
| 95 + if(!(dpy = XOpenDisplay(NULL))) | |
| 96 + die("Can't open display\n"); | |
| 97 + | |
| 98 + XrmInitialize(); | |
| 99 + xrm = XResourceManagerString(dpy); | |
| 100 + | |
| 101 + if (xrm != NULL) { | |
| 102 + xrdb = XrmGetStringDatabase(xrm); | |
| 103 + XRESOURCE_LOAD_STRING("color0", normbgcolor); | |
| 104 + XRESOURCE_LOAD_STRING("color12", normfgcolor); | |
| 105 + XRESOURCE_LOAD_STRING("color12", selbgcolor); | |
| 106 + XRESOURCE_LOAD_STRING("color0", selfgcolor); | |
| 107 + XRESOURCE_LOAD_STRING("color0", urgbgcolor); | |
| 108 + XRESOURCE_LOAD_STRING("color1", urgfgcolor); | |
| 109 + XRESOURCE_LOAD_STRING("font", font); | |
| 110 + } | |
| 111 + XFlush(dpy); | |
| 112 +} | |
| 113 + | |
| 114 +void | |
| 115 +reload(int sig) { | |
| 116 + xrdb_load(); | |
| 117 + colors_changed=1; | |
| 118 + signal(SIGUSR1, reload); | |
| 119 +} | |
| 120 + | |
| 121 +void | |
| 122 +writecolors(void) { | |
| 123 + dc.norm[ColBG] = getcolor(normbgcolor); | |
| 124 + dc.norm[ColFG] = getcolor(normfgcolor); | |
| 125 + dc.sel[ColBG] = getcolor(selbgcolor); | |
| 126 + dc.sel[ColFG] = getcolor(selfgcolor); | |
| 127 + dc.urg[ColBG] = getcolor(urgbgcolor); | |
| 128 + dc.urg[ColFG] = getcolor(urgfgcolor); | |
| 129 + | |
| 130 + colors_changed = 0; | |
| 131 +} | |
| 132 + | |
| 133 int | |
| 134 main(int argc, char *argv[]) | |
| 135 { | |
| 136 @@ -1354,6 +1419,8 @@ main(int argc, char *argv[]) | |
| 137 if (!(dpy = XOpenDisplay(NULL))) | |
| 138 die("%s: cannot open display\n", argv0); | |
| 139 | |
| 140 + xrdb_load(); | |
| 141 + signal(SIGUSR1, reload); | |
| 142 setup(); | |
| 143 printf("0x%lx\n", win); | |
| 144 fflush(NULL); | |
| 145 -- | |
| 146 2.35.2 | |
| 147 |