[dwm][patch][autodarkmode] Fix signal handler - sites - public wiki contents of… | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
commit 942b82cd1eff2988758ce1c0598b0128713a688f | |
parent 8fdbefda8d769b0b349d8eb70d664a24b0956bdd | |
Author: Spencer Williams <[email protected]> | |
Date: Mon, 24 Feb 2025 11:29:33 -0500 | |
[dwm][patch][autodarkmode] Fix signal handler | |
Diffstat: | |
D dwm.suckless.org/patches/autodarkm… | 175 ---------------------------… | |
A dwm.suckless.org/patches/autodarkm… | 208 +++++++++++++++++++++++++++… | |
M dwm.suckless.org/patches/autodarkm… | 2 +- | |
3 files changed, 209 insertions(+), 176 deletions(-) | |
--- | |
diff --git a/dwm.suckless.org/patches/autodarkmode/dwm-autodarkmode-20240602-6.… | |
@@ -1,175 +0,0 @@ | |
-diff --git a/config.def.h b/config.def.h | |
-index 9efa774..8a8d3be 100644 | |
---- a/config.def.h | |
-+++ b/config.def.h | |
-@@ -12,11 +12,16 @@ 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] = { | |
-+static const char *colorsdark[][3] = { | |
- /* fg bg border */ | |
- [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, | |
- [SchemeSel] = { col_gray4, col_cyan, col_cyan }, | |
- }; | |
-+static const char *colorslight[][3] = { | |
-+ /* fg bg border */ | |
-+ [SchemeNorm] = { col_gray1, col_gray3, col_gray2 }, | |
-+ [SchemeSel] = { col_cyan, col_gray4, col_cyan }, | |
-+}; | |
- | |
- /* tagging */ | |
- static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | |
-@@ -56,13 +61,14 @@ static const Layout layouts[] = { | |
- #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } | |
- | |
- /* commands */ | |
--static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn… | |
--static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufo… | |
-+static char dmenumon[2] = "0"; /* component of dmenu{dark,light}, manipulated… | |
-+static const char *dmenudark[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn",… | |
-+static const char *dmenulight[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn",… | |
- static const char *termcmd[] = { "st", NULL }; | |
- | |
- static const Key keys[] = { | |
- /* modifier key function argument */ | |
-- { MODKEY, XK_p, spawn, {.v = dmen… | |
-+ { MODKEY, XK_p, spawndmenu, {0} }, | |
- { MODKEY|ShiftMask, XK_Return, spawn, {.v = term… | |
- { MODKEY, XK_b, togglebar, {0} }, | |
- { MODKEY, XK_j, focusstack, {.i = +1 }… | |
-diff --git a/dwm.c b/dwm.c | |
-index f1d86b2..d4e3ddc 100644 | |
---- a/dwm.c | |
-+++ b/dwm.c | |
-@@ -198,6 +198,7 @@ static void scan(void); | |
- static int sendevent(Client *c, Atom proto); | |
- static void sendmon(Client *c, Monitor *m); | |
- static void setclientstate(Client *c, long state); | |
-+static void setcolormode(int sig); | |
- static void setfocus(Client *c); | |
- static void setfullscreen(Client *c, int fullscreen); | |
- static void setlayout(const Arg *arg); | |
-@@ -206,6 +207,7 @@ static void setup(void); | |
- static void seturgent(Client *c, int urg); | |
- static void showhide(Client *c); | |
- static void spawn(const Arg *arg); | |
-+static void spawndmenu(const Arg *arg); | |
- static void tag(const Arg *arg); | |
- static void tagmon(const Arg *arg); | |
- static void tile(Monitor *m); | |
-@@ -262,11 +264,12 @@ static void (*handler[LASTEvent]) (XEvent *) = { | |
- static Atom wmatom[WMLast], netatom[NetLast]; | |
- static int running = 1; | |
- static Cur *cursor[CurLast]; | |
--static Clr **scheme; | |
-+static Clr **scheme, **schemedark, **schemelight; | |
- static Display *dpy; | |
- static Drw *drw; | |
- static Monitor *mons, *selmon; | |
- static Window root, wmcheckwin; | |
-+static const char **dmenucmd; | |
- | |
- /* configuration, allows nested code to access above variables */ | |
- #include "config.h" | |
-@@ -486,9 +489,12 @@ cleanup(void) | |
- cleanupmon(mons); | |
- for (i = 0; i < CurLast; i++) | |
- drw_cur_free(drw, cursor[i]); | |
-- for (i = 0; i < LENGTH(colors); i++) | |
-- free(scheme[i]); | |
-- free(scheme); | |
-+ for (i = 0; i < LENGTH(colorsdark); i++) { | |
-+ free(schemedark[i]); | |
-+ free(schemelight[i]); | |
-+ } | |
-+ free(schemedark); | |
-+ free(schemelight); | |
- XDestroyWindow(dpy, wmcheckwin); | |
- drw_free(drw); | |
- XSync(dpy, False); | |
-@@ -1442,6 +1448,32 @@ setclientstate(Client *c, long state) | |
- PropModeReplace, (unsigned char *)data, 2); | |
- } | |
- | |
-+void | |
-+setcolormode(int sig) | |
-+{ | |
-+ static const char *file = ".lightmode"; | |
-+ static char *path = NULL; | |
-+ const char *home; | |
-+ size_t size; | |
-+ | |
-+ if (!path && (home = getenv("HOME"))) { | |
-+ size = strlen(home) + 1 + strlen(file) + 1; | |
-+ path = malloc(size); | |
-+ if (!path) | |
-+ die("dwm: malloc failed"); | |
-+ | |
-+ snprintf(path, size, "%s/%s", home, file); | |
-+ } | |
-+ | |
-+ if (access(path, F_OK) == 0) { | |
-+ scheme = schemelight; | |
-+ dmenucmd = dmenulight; | |
-+ } else { | |
-+ scheme = schemedark; | |
-+ dmenucmd = dmenudark; | |
-+ } | |
-+} | |
-+ | |
- int | |
- sendevent(Client *c, Atom proto) | |
- { | |
-@@ -1550,6 +1582,11 @@ setup(void) | |
- sa.sa_handler = SIG_IGN; | |
- sigaction(SIGCHLD, &sa, NULL); | |
- | |
-+ /* set color mode on SIGHUP */ | |
-+ sigemptyset(&sa.sa_mask); | |
-+ sa.sa_handler = setcolormode; | |
-+ sigaction(SIGHUP, &sa, NULL); | |
-+ | |
- /* clean up any zombies (inherited from .xinitrc etc) immediately */ | |
- while (waitpid(-1, NULL, WNOHANG) > 0); | |
- | |
-@@ -1584,9 +1621,13 @@ setup(void) | |
- cursor[CurResize] = drw_cur_create(drw, XC_sizing); | |
- cursor[CurMove] = drw_cur_create(drw, XC_fleur); | |
- /* init appearance */ | |
-- scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); | |
-- for (i = 0; i < LENGTH(colors); i++) | |
-- scheme[i] = drw_scm_create(drw, colors[i], 3); | |
-+ schemedark = ecalloc(LENGTH(colorsdark), sizeof(Clr *)); | |
-+ schemelight = ecalloc(LENGTH(colorslight), sizeof(Clr *)); | |
-+ for (i = 0; i < LENGTH(colorsdark); i++) { | |
-+ schemedark[i] = drw_scm_create(drw, colorsdark[i], 3); | |
-+ schemelight[i] = drw_scm_create(drw, colorslight[i], 3); | |
-+ } | |
-+ setcolormode(0); | |
- /* init bars */ | |
- updatebars(); | |
- updatestatus(); | |
-@@ -1649,8 +1690,6 @@ spawn(const Arg *arg) | |
- { | |
- struct sigaction sa; | |
- | |
-- if (arg->v == dmenucmd) | |
-- dmenumon[0] = '0' + selmon->num; | |
- if (fork() == 0) { | |
- if (dpy) | |
- close(ConnectionNumber(dpy)); | |
-@@ -1666,6 +1705,13 @@ spawn(const Arg *arg) | |
- } | |
- } | |
- | |
-+void | |
-+spawndmenu(const Arg *arg) | |
-+{ | |
-+ dmenumon[0] = '0' + selmon->num; | |
-+ spawn(&(const Arg){.v = dmenucmd}); | |
-+} | |
-+ | |
- void | |
- tag(const Arg *arg) | |
- { | |
diff --git a/dwm.suckless.org/patches/autodarkmode/dwm-autodarkmode-20250224-6.… | |
@@ -0,0 +1,208 @@ | |
+diff --git a/config.def.h b/config.def.h | |
+index 9efa774..8a8d3be 100644 | |
+--- a/config.def.h | |
++++ b/config.def.h | |
+@@ -12,11 +12,16 @@ 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] = { | |
++static const char *colorsdark[][3] = { | |
+ /* fg bg border */ | |
+ [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, | |
+ [SchemeSel] = { col_gray4, col_cyan, col_cyan }, | |
+ }; | |
++static const char *colorslight[][3] = { | |
++ /* fg bg border */ | |
++ [SchemeNorm] = { col_gray1, col_gray3, col_gray2 }, | |
++ [SchemeSel] = { col_cyan, col_gray4, col_cyan }, | |
++}; | |
+ | |
+ /* tagging */ | |
+ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; | |
+@@ -56,13 +61,14 @@ static const Layout layouts[] = { | |
+ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } | |
+ | |
+ /* commands */ | |
+-static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn… | |
+-static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufo… | |
++static char dmenumon[2] = "0"; /* component of dmenu{dark,light}, manipulated… | |
++static const char *dmenudark[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn",… | |
++static const char *dmenulight[] = { "dmenu_run", "-m", dmenumon, "-i", "-fn",… | |
+ static const char *termcmd[] = { "st", NULL }; | |
+ | |
+ static const Key keys[] = { | |
+ /* modifier key function argument */ | |
+- { MODKEY, XK_p, spawn, {.v = dmen… | |
++ { MODKEY, XK_p, spawndmenu, {0} }, | |
+ { MODKEY|ShiftMask, XK_Return, spawn, {.v = term… | |
+ { MODKEY, XK_b, togglebar, {0} }, | |
+ { MODKEY, XK_j, focusstack, {.i = +1 }… | |
+diff --git a/dwm.c b/dwm.c | |
+index f1d86b2..bd9cf3d 100644 | |
+--- a/dwm.c | |
++++ b/dwm.c | |
+@@ -153,6 +153,7 @@ static void checkotherwm(void); | |
+ static void cleanup(void); | |
+ static void cleanupmon(Monitor *mon); | |
+ static void clientmessage(XEvent *e); | |
++static void colormodehandler(int sig); | |
+ static void configure(Client *c); | |
+ static void configurenotify(XEvent *e); | |
+ static void configurerequest(XEvent *e); | |
+@@ -198,6 +199,7 @@ static void scan(void); | |
+ static int sendevent(Client *c, Atom proto); | |
+ static void sendmon(Client *c, Monitor *m); | |
+ static void setclientstate(Client *c, long state); | |
++static void setcolormode(void); | |
+ static void setfocus(Client *c); | |
+ static void setfullscreen(Client *c, int fullscreen); | |
+ static void setlayout(const Arg *arg); | |
+@@ -206,6 +208,7 @@ static void setup(void); | |
+ static void seturgent(Client *c, int urg); | |
+ static void showhide(Client *c); | |
+ static void spawn(const Arg *arg); | |
++static void spawndmenu(const Arg *arg); | |
+ static void tag(const Arg *arg); | |
+ static void tagmon(const Arg *arg); | |
+ static void tile(Monitor *m); | |
+@@ -262,11 +265,13 @@ static void (*handler[LASTEvent]) (XEvent *) = { | |
+ static Atom wmatom[WMLast], netatom[NetLast]; | |
+ static int running = 1; | |
+ static Cur *cursor[CurLast]; | |
+-static Clr **scheme; | |
++static Clr **scheme, **schemedark, **schemelight; | |
+ static Display *dpy; | |
+ static Drw *drw; | |
+ static Monitor *mons, *selmon; | |
+ static Window root, wmcheckwin; | |
++static const char **dmenucmd; | |
++static int colormodechanged; | |
+ | |
+ /* configuration, allows nested code to access above variables */ | |
+ #include "config.h" | |
+@@ -486,9 +491,12 @@ cleanup(void) | |
+ cleanupmon(mons); | |
+ for (i = 0; i < CurLast; i++) | |
+ drw_cur_free(drw, cursor[i]); | |
+- for (i = 0; i < LENGTH(colors); i++) | |
+- free(scheme[i]); | |
+- free(scheme); | |
++ for (i = 0; i < LENGTH(colorsdark); i++) { | |
++ free(schemedark[i]); | |
++ free(schemelight[i]); | |
++ } | |
++ free(schemedark); | |
++ free(schemelight); | |
+ XDestroyWindow(dpy, wmcheckwin); | |
+ drw_free(drw); | |
+ XSync(dpy, False); | |
+@@ -531,6 +539,12 @@ clientmessage(XEvent *e) | |
+ } | |
+ } | |
+ | |
++void | |
++colormodehandler(int sig) | |
++{ | |
++ colormodechanged = 1; | |
++} | |
++ | |
+ void | |
+ configure(Client *c) | |
+ { | |
+@@ -1225,6 +1239,10 @@ propertynotify(XEvent *e) | |
+ Window trans; | |
+ XPropertyEvent *ev = &e->xproperty; | |
+ | |
++ if (colormodechanged) { | |
++ setcolormode(); | |
++ colormodechanged = 0; | |
++ } | |
+ if ((ev->window == root) && (ev->atom == XA_WM_NAME)) | |
+ updatestatus(); | |
+ else if (ev->state == PropertyDelete) | |
+@@ -1442,6 +1460,32 @@ setclientstate(Client *c, long state) | |
+ PropModeReplace, (unsigned char *)data, 2); | |
+ } | |
+ | |
++void | |
++setcolormode(void) | |
++{ | |
++ static const char *file = ".lightmode"; | |
++ static char *path = NULL; | |
++ const char *home; | |
++ size_t size; | |
++ | |
++ if (!path && (home = getenv("HOME"))) { | |
++ size = strlen(home) + 1 + strlen(file) + 1; | |
++ path = malloc(size); | |
++ if (!path) | |
++ die("dwm: malloc failed"); | |
++ | |
++ snprintf(path, size, "%s/%s", home, file); | |
++ } | |
++ | |
++ if (access(path, F_OK) == 0) { | |
++ scheme = schemelight; | |
++ dmenucmd = dmenulight; | |
++ } else { | |
++ scheme = schemedark; | |
++ dmenucmd = dmenudark; | |
++ } | |
++} | |
++ | |
+ int | |
+ sendevent(Client *c, Atom proto) | |
+ { | |
+@@ -1550,6 +1594,11 @@ setup(void) | |
+ sa.sa_handler = SIG_IGN; | |
+ sigaction(SIGCHLD, &sa, NULL); | |
+ | |
++ /* set color mode on SIGHUP */ | |
++ sigemptyset(&sa.sa_mask); | |
++ sa.sa_handler = colormodehandler; | |
++ sigaction(SIGHUP, &sa, NULL); | |
++ | |
+ /* clean up any zombies (inherited from .xinitrc etc) immediately */ | |
+ while (waitpid(-1, NULL, WNOHANG) > 0); | |
+ | |
+@@ -1584,9 +1633,13 @@ setup(void) | |
+ cursor[CurResize] = drw_cur_create(drw, XC_sizing); | |
+ cursor[CurMove] = drw_cur_create(drw, XC_fleur); | |
+ /* init appearance */ | |
+- scheme = ecalloc(LENGTH(colors), sizeof(Clr *)); | |
+- for (i = 0; i < LENGTH(colors); i++) | |
+- scheme[i] = drw_scm_create(drw, colors[i], 3); | |
++ schemedark = ecalloc(LENGTH(colorsdark), sizeof(Clr *)); | |
++ schemelight = ecalloc(LENGTH(colorslight), sizeof(Clr *)); | |
++ for (i = 0; i < LENGTH(colorsdark); i++) { | |
++ schemedark[i] = drw_scm_create(drw, colorsdark[i], 3); | |
++ schemelight[i] = drw_scm_create(drw, colorslight[i], 3); | |
++ } | |
++ setcolormode(); | |
+ /* init bars */ | |
+ updatebars(); | |
+ updatestatus(); | |
+@@ -1649,8 +1702,6 @@ spawn(const Arg *arg) | |
+ { | |
+ struct sigaction sa; | |
+ | |
+- if (arg->v == dmenucmd) | |
+- dmenumon[0] = '0' + selmon->num; | |
+ if (fork() == 0) { | |
+ if (dpy) | |
+ close(ConnectionNumber(dpy)); | |
+@@ -1666,6 +1717,13 @@ spawn(const Arg *arg) | |
+ } | |
+ } | |
+ | |
++void | |
++spawndmenu(const Arg *arg) | |
++{ | |
++ dmenumon[0] = '0' + selmon->num; | |
++ spawn(&(const Arg){.v = dmenucmd}); | |
++} | |
++ | |
+ void | |
+ tag(const Arg *arg) | |
+ { | |
diff --git a/dwm.suckless.org/patches/autodarkmode/index.md b/dwm.suckless.org/… | |
@@ -39,7 +39,7 @@ Configuration | |
Download | |
-------- | |
-* [dwm-autodarkmode-20240602-6.5.diff](dwm-autodarkmode-20240602-6.5.diff) | |
+* [dwm-autodarkmode-20250224-6.5.diff](dwm-autodarkmode-20250224-6.5.diff) | |
Author | |
------ |