ztatus

[discontinued] Status bar for dwm, and simple notification daemon.
git clone https://noxz.tech/git/ztatus.git
Log | Files | LICENSE

commit: 397aa2f918a16b6fd373469feee831366c4740e1
parent: d56f3124f7ae9b77e51417310d7dd04d64a6bd44
author: Chris Noxz <chris@noxz.tech>
date:   Wed, 8 Feb 2023 10:28:17 +0100
don't count seconds and only send updates
Mconfig.def.h2+-
Mztatus.c32++++++++++++--------
2 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -1,5 +1,5 @@
 /* format of the clock normally displayed */
-#define FORMAT_TIME     "\x08%04u-%02u-%02u %02u:%02u:%02u \x09 \ue029\ue02a "
+#define FORMAT_TIME     "\x0a%04u-%02u-%02u %02u:%02u "
 
 /* format of notifications */
 #define FORMAT_NOTIFY   "\x0b %s "
diff --git a/ztatus.c b/ztatus.c
@@ -30,6 +30,7 @@ static void sigint_handler(int);
 
 /* global variables */
 static Display *dpy;
+static char *last_line;
 static int delay_time = 0;
 static int running = 0;
 static int self_pid = 0;
@@ -77,6 +78,8 @@ run(void)
 		return die("error: cannot open display\n", FIFO_PATH);
 	if ((status_line = malloc(STATUS_LENGTH)) == NULL)
 		return die("error: failed to allocate memory\n", FIFO_PATH);
+	if ((last_line = calloc(STATUS_LENGTH, sizeof(char))) == NULL)
+		return die("error: failed to allocate memory\n", FIFO_PATH);
 
 	/* handle interrupts and terminations */
 	signal(SIGINT, sigint_handler);
@@ -99,16 +102,16 @@ run(void)
 			break;
 
 		/* dispatch on fifo read */
-	if (FD_ISSET(fifofd, &rfds))
-		dispatch();
-
-	/* prevent data printing if it's delayed.
-	 * this is so an external signal can borrow the status line
-	 * for a short time, determined by the delay_time */
-	if (delay_time > 0) {
-		delay_time--;
-		continue;
-	}
+		if (FD_ISSET(fifofd, &rfds))
+			dispatch();
+
+		/* prevent data printing if it's delayed.
+		 * this is so an external signal can borrow the status line
+		 * for a short time, determined by the delay_time */
+		if (delay_time > 0) {
+			delay_time--;
+			continue;
+		}
 
 		render_time(status_line);
 		set_status(status_line);
@@ -116,6 +119,7 @@ run(void)
 
 	/* free up resources when done */
 	free(status_line);
+	free(last_line);
 	XCloseDisplay(dpy);
 	if (fifofd >= 0)
 		unlink(FIFO_PATH);
@@ -262,7 +266,6 @@ render_time(char *str)
 		,y ,m ,d
 		,(time_val / 3600) % 24
 		,(time_val / 60) % 60
-		,time_val % 60
 	);
 	strcpy(str, tmp);
 	free(tmp);
@@ -270,8 +273,11 @@ render_time(char *str)
 
 void
 set_status(const char *line) {
-	XStoreName(dpy, DefaultRootWindow(dpy), line);
-	XSync(dpy, False);
+	if (strcmp(line, last_line)) {
+		XStoreName(dpy, DefaultRootWindow(dpy), line);
+		XSync(dpy, False);
+	}
+	strcpy(last_line, line);
 }
 
 void