DWM need help finishing my new dwm patch

i have been wanting and trying to create a patch that checks my charger status and if its plugged in the color-theme of dwm will be blue but if it is unplugged then it will turn the theme of dwm to red, heres the "patch" i made

------------------- config.def.h
Code:
--- original.h    2025-03-27 15:14:53.097312042 +0500
+++ config.def.h    2025-06-15 14:51:21.240599830 +0500
@@ -1,100 +1,150 @@
 /* See LICENSE file for copyright and license details. */
 
 /* appearance */
-static const unsigned int borderpx  = 1;        /* border pixel of windows */
-static const unsigned int snap      = 32;       /* snap pixel */
-static const int showbar            = 1;        /* 0 means no bar */
-static const int topbar             = 1;        /* 0 means bottom bar */
-static const char *fonts[]          = { "monospace:size=10" };
-static const char dmenufont[]       = "monospace:size=10";
-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 *colors[][3]      = {
-    /*               fg         bg         border   */
-    [SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
-    [SchemeSel]  = { col_gray4, col_cyan,  col_cyan  },
+static const unsigned int borderpx    = 6;  /* border pixel of windows */
+static const unsigned int snap        = 32; /* snap pixel */
+static const int showbar        = 1;  /* 0 means no bar */
+static const int topbar        = 1;  /* 0 means bottom bar */
+static const char *fonts[]        = { "Liberation Mono:bold:size=14" };
+static const char dmenufont[]        = "Liberation Mono:bold:size=14";
+
+static const char *blue[] = {
+//     text        dark        light
+    "#FFFFFF",     "#0E1C4A",     "#3E54BD"
 };
 
+static const char *red[] = {
+//     text        dark        light
+    "#FFFFFF",     "#430B07",     "#73493D"
+};
+
+static const char **current_theme = blue;
+/*
+static const char *green[] = {
+    "#1A2C12", "#020C02", "#193A0D", "#385C17", "#1B331D"
+};
+*/

------------------- dwm.c
Code:
--- original.c    2025-06-15 15:17:35.492684035 +0500
+++ dwm.c    2025-05-25 10:10:31.564985125 +0500
@@ -271,6 +272,49 @@
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
+extern const char **current_theme;
+const char *colors[2][3];
+
+
+void
+update_colors(void) {
+    colors[SchemeNorm][0] = (char *)current_theme[0];
+    colors[SchemeNorm][1] = (char *)current_theme[1];
+    colors[SchemeNorm][2] = (char *)current_theme[2];
+
+    colors[SchemeSel][0] = (char *)current_theme[0];
+    colors[SchemeSel][1] = (char *)current_theme[2];
+    colors[SchemeSel][2] = (char *)current_theme[2];
+}
+
+void
+check_theme(Display *dpy) {
+    char *name = NULL;
+    Window root = DefaultRootWindow(dpy);
+
+    if (XFetchName(dpy, root, &name)) {
+    if (name && strstr(name, "change")) {
+        current_theme = red;
+        update_colors();
+    }
+    XFree(name);
+    }
+}
+
+void *
+theme_checker(void *arg) {
+    Display *dpy_thread = XOpenDisplay(NULL);
+    if (!dpy_thread) return NULL;
+
+    for (;;) {
+    check_theme(dpy_thread);
+    usleep(100000);
+    }
+
+    XCloseDisplay(dpy_thread);
+    return NULL;
+}
+
 /* compile-time check if all tags fit into an unsigned int bit array. */
 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
@@ -1851,7 +1895,7 @@
 }
 
 void
-updateclientlist()
+updateclientlist(void)
 {
     Client *c;
     Monitor *m;
@@ -2152,12 +2198,15 @@
     if (!(dpy = XOpenDisplay(NULL)))
         die("dwm: cannot open display");
     checkotherwm();
+    update_colors();
     setup();
 #ifdef __OpenBSD__
     if (pledge("stdio rpath proc exec", NULL) == -1)
         die("pledge");
 #endif /* __OpenBSD__ */
     scan();
+    pthread_t theme_thread;
+    pthread_create(&theme_thread, NULL, theme_checker, NULL);
     run();
     cleanup();
     XCloseDisplay(dpy);

In the code I have set the default theme to be blue and that works just fine and dwm gets colored correctly on build, even if I change the theme manually, but the theme doesn't change on status change.

This is a very specific purpose and I'm pretty sure that there isn't a patch for this, but if there's someone who knows of a patch that does this or can help me out with this I would really appreciate it. I tried doing this myself but I just can't figure it out.

I'm pretty new to C and don't have any experience working with linux or xorg utils, this is just how far I could get with some AI help.
 
I think it would be an easier alternative to just use a statusbar which shows battery plugged/unplugged status.
it would definitely be easier, which is why im already doing that with sltatus. but at this point you have to ask yourself,

is that good enough or could i do something that is stupidly cool?
 
For what it's worth, the dwm people are usually pretty helpful, if you ask them. (At least in my experience--my own question was an issue they couldn't reproduce, but they were pretty nice about it.)
yes i had the same thought but for the life of me i couldnt find any dwm-forums if those exist, all i could find was the suckless subreddit and the suckless mailing list,

i tried to post on the subreddit but reddit kept blocking my posts for some reason and they never gave a reason
please tell me i dont have to use mail to communicate with the team about this and there is just a normal forum or something somewhere
 
Yes in my case (and this was long ago), I think I just emailed one of the developers, though that was probably after looking at the page and getting email addresses--or maybe from the mailing list. I'm sorry, it was so long ago that I've forgotten. Though one could say that it is in keeping with the suckless philosophy to just have mailing lists. (Hrrm, there's probably an irc channel--let me check...hold on...) Yup, there's an irc #dwm on libera chat, seems to be 7 nicks on the channel though I have no idea how active it is.
 
Back
Top