summary refs log tree commit diff
path: root/calmwm.c
diff options
context:
space:
mode:
authorokan <okan>2017-12-27 17:04:35 +0000
committerokan <okan>2017-12-27 17:04:35 +0000
commit3d7c82936e6cbc49c92cdd985f8c3a8588028da5 (patch)
treeacfa1f6a5fd8115fb0c833effc922040a9535914 /calmwm.c
parent03e5d869522e7fcc9243e6877bdc05cef2856c79 (diff)
downloadcwm-3d7c82936e6cbc49c92cdd985f8c3a8588028da5.tar.gz
cwm-3d7c82936e6cbc49c92cdd985f8c3a8588028da5.tar.xz
cwm-3d7c82936e6cbc49c92cdd985f8c3a8588028da5.zip
Use poll and XNextEvent to replace XNextEvent blocking inside the x11 event
handler.
Diffstat (limited to 'calmwm.c')
-rw-r--r--calmwm.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/calmwm.c b/calmwm.c
index fdfc9e5..521d1f9 100644
--- a/calmwm.c
+++ b/calmwm.c
@@ -27,6 +27,7 @@
 #include <getopt.h>
 #include <limits.h>
 #include <locale.h>
+#include <poll.h>
 #include <pwd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -56,6 +57,7 @@ main(int argc, char **argv)
 	const char	*conf_file = NULL;
 	char		*conf_path, *display_name = NULL;
 	int		 ch, xfd;
+	struct pollfd	 pfd[1];
 	struct passwd	*pw;
 
 	if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
@@ -114,8 +116,16 @@ main(int argc, char **argv)
 	if (pledge("stdio rpath proc exec", NULL) == -1)
 		err(1, "pledge");
 
-	while (cwm_status == CWM_RUNNING)
+	memset(&pfd, 0, sizeof(pfd));
+	pfd[0].fd = xfd;
+	pfd[0].events = POLLIN;
+	while (cwm_status == CWM_RUNNING) {
 		xev_process();
+		if (poll(pfd, 1, INFTIM) == -1) {
+			if (errno != EINTR)
+				warn("poll");
+		}
+	}
 	x_teardown();
 	if (cwm_status == CWM_EXEC_WM)
 		u_exec(Conf.wm_argv);