Add: Reload colors without relaunching the session

This commit is contained in:
pixel2175 2025-08-13 09:22:04 +01:00
parent be0f7b5674
commit 561ff342dd
3 changed files with 78 additions and 0 deletions

8
patches/recolr/README.md Normal file
View File

@ -0,0 +1,8 @@
# Reload Colors
this patch lets you change DWL colors without relaunch it
## how to use
after patching dwl with this add the colors file path in config.def.h
the colors file structure you will find it in the example file
when you edit the colors file press MOD+n to reload

4
patches/recolr/example Normal file
View File

@ -0,0 +1,4 @@
e5c9b8ff 131312ff 554e38ff
e5c9b8ff 954816ff 954816ff
131312ff 131312ff 131312ff

View File

@ -0,0 +1,66 @@
diff --git a/config.def.h b/config.def.h
index 95c2afa..73422ee 100644
--- a/config.def.h
+++ b/config.def.h
@@ -4,9 +4,12 @@
((hex >> 8) & 0xFF) / 255.0f, \
(hex & 0xFF) / 255.0f }
/* appearance */
+
static const int sloppyfocus = 1; /* focus follows mouse */
static const int bypass_surface_visibility = 0; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible */
static const unsigned int borderpx = 1; /* border pixel of windows */
+// Replace colors_dir with your own path, e.g /home/yourname/.cache/dwl-colors
+static const char *colors_dir = "/home/pixel/.cache/wal/dwl-colors";
static const float rootcolor[] = COLOR(0x222222ff);
static const float bordercolor[] = COLOR(0x444444ff);
static const float focuscolor[] = COLOR(0x005577ff);
@@ -128,6 +131,7 @@ static const Key keys[] = {
{ MODKEY, XKB_KEY_p, spawn, {.v = menucmd} },
{ MODKEY|WLR_MODIFIER_SHIFT, XKB_KEY_Return, spawn, {.v = termcmd} },
{ MODKEY, XKB_KEY_j, focusstack, {.i = +1} },
+ { MODKEY, XKB_KEY_n, reload_colors, {0} },
{ MODKEY, XKB_KEY_k, focusstack, {.i = -1} },
{ MODKEY, XKB_KEY_i, incnmaster, {.i = +1} },
{ MODKEY, XKB_KEY_d, incnmaster, {.i = -1} },
diff --git a/dwl.c b/dwl.c
index 12f441e..0801673 100644
--- a/dwl.c
+++ b/dwl.c
@@ -313,6 +313,7 @@ static void pointerfocus(Client *c, struct wlr_surface *surface,
static void printstatus(void);
static void powermgrsetmode(struct wl_listener *listener, void *data);
static void quit(const Arg *arg);
+static void reload_colors(const Arg *arg);
static void rendermon(struct wl_listener *listener, void *data);
static void requestdecorationmode(struct wl_listener *listener, void *data);
static void requeststartdrag(struct wl_listener *listener, void *data);
@@ -2146,6 +2147,28 @@ quit(const Arg *arg)
wl_display_terminate(dpy);
}
+void
+reload_colors(const Arg *arg)
+{
+ FILE *f = fopen(colors_dir, "r");
+ if (!f) {
+ return;
+ }
+
+ for (int i = 0; i < (int)LENGTH(colors); i++) {
+ unsigned int fg, bg, border;
+ if (fscanf(f, "%x %x %x", &fg, &bg, &border) != 3) {
+ break;
+ }
+ colors[i][ColFg] = fg;
+ colors[i][ColBg] = bg;
+ colors[i][ColBorder] = border;
+ }
+
+ fclose(f);
+ drawbars();
+}
+
void
rendermon(struct wl_listener *listener, void *data)
{