dwm-noxz

[fork] suckless dwm - personal fork
git clone https://noxz.tech/git/dwm-noxz.git
dwm-noxz

commit: 765b660c8501f4e197ee90848537ce0debf7636b
parent: 4553dc31a28b2c655dff3e5c999d9b0af45ec471
author: Chris Noxz <chris@noxz.tech>
date:   Thu, 11 May 2023 14:33:14 +0200
Set status using fifo/cmd
Mconfig.def.h1+
Mdwm.c75+++++++++++---------
2 files changed, 42 insertions(+), 34 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -170,6 +170,7 @@ static Command commands[] = {
 	{ "inc nmaster -",      incnmaster,     {.i = -1} },
 	{ "zoom",               zoom,           {0} },
 	{ "kill client",        killclient,     {0} },
+	{ "set status ...",     setstatus,      {.i = DispCmdLine} },
 
 	{ "set layout grid",    setlayout,      {.v = &layouts[LayoutGrid]} },
 	{ "set layout tiled",   setlayout,      {.v = &layouts[LayoutTiled]} },
diff --git a/dwm.c b/dwm.c
@@ -234,6 +234,7 @@ static void setclienttagprop(Client *c);
 static void setfocus(Client *c);
 static void setfullscreen(Client *c, int fullscreen);
 static void setlayout(const Arg *arg);
+static void setstatus(const Arg *arg);
 static void settagstate(void);
 static void togglelayout(const Arg *arg);
 static void rotatelayout(const Arg *arg);
@@ -261,7 +262,6 @@ static void updateclientlist(void);
 static int updategeom(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
-static void updatestatus(void);
 static void updatetitle(Client *c);
 static void updatewindowtype(Client *c);
 static void updatewmhints(Client *c);
@@ -275,7 +275,7 @@ static void zoom(const Arg *arg);
 
 /* variables */
 static const char broken[] = "broken";
-static char stext[256];
+static char stext[256] = "";
 static int screen;
 static int sw, sh;           /* X display screen geometry width, height */
 static int bh, blw = 0;      /* bar geometry */
@@ -781,11 +781,11 @@ dirtomon(int dir)
 void
 strsplit(char *str, char ***arr, const char *toks)
 {
-	char *p = strtok((char *)str, toks);
+	char *p = strtok(str, toks);
 	int len = 0;
 
 	while (p) {
-		if ((*arr = realloc(*arr, sizeof (char*) * len++)) == NULL)
+		if ((*arr = realloc(*arr, sizeof (char*) * ++len)) == NULL)
 			die("realloc: failed\n");
 		(*arr)[len - 1] = p;
 		p = strtok(NULL, toks);
@@ -799,34 +799,31 @@ strsplit(char *str, char ***arr, const char *toks)
 void
 dispatchline(const char *c, int n, void (*func)(const Arg *), const Arg *arg)
 {
-	char *cmd = NULL;
 	char *line = NULL;
 	char **arr = NULL;
+	int len = strlen(c) - n;
 	Arg a;
 
-	if (strlen(c) < n)
+	if (len < 0)
 		return;
 
-	cmd = malloc(n + 1);
-	line = malloc(strlen(c) + 1);
+	line = malloc(len + 1);
 
-	strncpy(cmd, c, n);
 	strcpy(line, c + n);
 	strsplit(line, &arr, " ");
 
 	switch (arg->i) {
-		case DispUi: {
-			if (sscanf(arr[0], "%d", &a.i))
+	case DispUi:
+		if (sscanf(arr[0], "%d", &a.i))
 			a.ui = 1 << a.i;
-		} break;
-		case DispCmdLine:
-			a.v = (const char **)arr;
-		break;
+	break;
+	case DispCmdLine:
+		a.v = (const char **)arr;
+	break;
 	}
 
 	func(&a);
 
-	free(cmd);
 	free(line);
 	free(arr);
 }
@@ -858,11 +855,7 @@ dispatchcmd(void)
 			);
 			if (strncmp(commands[i].name, line, n) == 0) {
 				if (n != m)
-					dispatchline(
-						line, n,
-						commands[i].func,
-						&commands[i].arg
-					);
+					dispatchline(line, n, commands[i].func, &commands[i].arg);
 				else
 					commands[i].func(&commands[i].arg);
 				break;
@@ -906,7 +899,6 @@ drawbar(Monitor *m)
 			*ts = ctmp;
 			tp = ++ts;
 		}
-		tw += 2; /* 2px right padding */
 		tx = -i_basewidth;
 		ts = stext;
 		tp = stext;
@@ -1486,9 +1478,7 @@ propertynotify(XEvent *e)
 	Window trans;
 	XPropertyEvent *ev = &e->xproperty;
 
-	if ((ev->window == root) && (ev->atom == XA_WM_NAME))
-		updatestatus();
-	else if (ev->state == PropertyDelete)
+	if (ev->state == PropertyDelete)
 		return; /* ignore */
 	else if ((c = wintoclient(ev->window))) {
 		switch(ev->atom) {
@@ -1998,7 +1988,6 @@ setup(void)
 		scheme[i] = drw_scm_create(drw, colors[i], 4);
 	/* init bars */
 	updatebars();
-	updatestatus();
 	/* supporting window for NetWMCheck */
 	wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0);
 	XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
@@ -2084,6 +2073,32 @@ spawn(const Arg *arg)
 	}
 }
 
+void
+setstatus(const Arg *arg)
+{
+	char *buff = NULL;
+	int len = 0;
+	int i, c = 0;
+
+	for (i = 0; ((char **)arg->v)[i]; i++, c++)
+		len += 1 + strlen(((char **)arg->v)[i]);
+
+	if (len == 0)
+		return;
+
+	buff = calloc(len + 1, sizeof(char));
+
+	for (i = 0; ((char **)arg->v)[i]; i++) {
+		strcat(buff, ((char **)arg->v)[i]);
+		strcat(buff, " "); /* also add space to end for padding */
+	}
+
+	strcpy(stext, buff);
+	drawbar(selmon);
+
+	free(buff);
+}
+
 void
 tag(const Arg *arg)
 {
@@ -2548,14 +2563,6 @@ updatesizehints(Client *c)
 	c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh);
 }
 
-void
-updatestatus(void)
-{
-	if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
-		strcpy(stext, "dwm-"VERSION);
-	drawbar(selmon);
-}
-
 void
 updatetitle(Client *c)
 {