dwm-noxz

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

commit: 3262c9eb81635868bc7fd325f23d36944eac85e6
parent: eb5c5a2ff99198d02af8d8b2441a1c6e520aac19
author: Chris Noxz <chris@noxz.tech>
date:   Tue, 25 Jul 2023 21:36:54 +0200
Update fifo feature to use poll.h
Mdwm.c35++++++++------------
1 file changed, 14 insertions(+), 21 deletions(-)
diff --git a/dwm.c b/dwm.c
@@ -30,6 +30,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <poll.h>
 #include <sys/select.h>
 #include <sys/types.h>
 #include <sys/wait.h>
@@ -1720,29 +1721,21 @@ void
 run(void)
 {
 	XEvent ev;
-	fd_set rfds;
-	int n;
-	int dpyfd, maxfd;
+	struct pollfd fds[2] = {
+		{ .events = POLLIN },
+		{ .fd = fifofd, .events = POLLIN }
+	};
 	/* main event loop */
 	XSync(dpy, False);
-	dpyfd = ConnectionNumber(dpy);
-	maxfd = fifofd;
-	if (dpyfd > maxfd)
-		maxfd = dpyfd;
-	maxfd++;
+	fds[0].fd = ConnectionNumber(dpy);
 	while (running) {
-		FD_ZERO(&rfds);
-		FD_SET(fifofd, &rfds);
-		FD_SET(dpyfd, &rfds);
-		n = select(maxfd, &rfds, NULL, NULL, NULL);
-		if (n > 0) {
-			if (FD_ISSET(fifofd, &rfds))
-				dispatchcmd();
-			if (FD_ISSET(dpyfd, &rfds))
-				while (XCheckIfEvent(dpy, &ev, evpredicate, NULL))
-					if (handler[ev.type])
-						handler[ev.type](&ev); /* call handler */
-		}
+		(void)poll(fds, 1[&fds] - fds, -1);
+		if (fds[1].revents & POLLIN)
+			 dispatchcmd();
+		if (fds[0].revents & POLLIN)
+			while (XCheckIfEvent(dpy, &ev, evpredicate, NULL))
+				if (handler[ev.type])
+					handler[ev.type](&ev); /* call handler */
 	}
 }
 
@@ -2008,7 +2001,7 @@ setup(void)
 
 	/* fifo */
 	mkfifo(dwmfifo, 0600);
-	fifofd = open(dwmfifo, O_RDWR | O_NONBLOCK);
+	fifofd = open(dwmfifo, O_RDWR | O_CLOEXEC | O_NONBLOCK);
 	if (fifofd < 0)
 		die("Failed to open() DWM fifo %s:", dwmfifo);
 }