summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2022-08-29 21:37:03 +0200
committerbakkeby <[email protected]>2022-08-29 21:37:03 +0200
commit0f36ba5408ab04586dc71ccb082fb28633df14bc (patch)
tree63aa68533086c17d2f8a9100dcbf8ae448fbe18d
parent90f9b2d9820b8da03d54a64e523aa1f104b4ff2b (diff)
downloaddwm-flexipatch-0f36ba5408ab04586dc71ccb082fb28633df14bc.tar.gz
dwm-flexipatch-0f36ba5408ab04586dc71ccb082fb28633df14bc.zip
restartsig: call XNextEvent only when there is data to be read ref. #295
-rw-r--r--dwm.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/dwm.c b/dwm.c
index 8beafff..1756a6b 100644
--- a/dwm.c
+++ b/dwm.c
@@ -55,6 +55,10 @@
#include <pango/pango.h>
#endif // BAR_PANGO_PATCH
+#if RESTARTSIG_PATCH
+#include <poll.h>
+#endif // RESTARTSIG_PATCH
+
#if XKB_PATCH
#include <X11/XKBlib.h>
#endif // XKB_PATCH
@@ -819,7 +823,11 @@ static Atom clientatom[ClientLast];
#if ON_EMPTY_KEYS_PATCH
static int isempty = 0;
#endif // ON_EMPTY_KEYS_PATCH
+#if RESTARTSIG_PATCH
+static volatile sig_atomic_t running = 1;
+#else
static int running = 1;
+#endif // RESTARTSIG_PATCH
static Cur *cursor[CurLast];
static Clr **scheme;
static Display *dpy;
@@ -3186,6 +3194,30 @@ run(void)
}
}
}
+#elif RESTARTSIG_PATCH
+void
+run(void)
+{
+ XEvent ev;
+ XSync(dpy, False);
+ /* main event loop */
+ while (running) {
+ struct pollfd pfd = {
+ .fd = ConnectionNumber(dpy),
+ .events = POLLIN,
+ };
+ int pending = XPending(dpy) > 0 || poll(&pfd, 1, -1) > 0;
+
+ if (!running)
+ break;
+ if (!pending)
+ continue;
+
+ XNextEvent(dpy, &ev);
+ if (handler[ev.type])
+ handler[ev.type](&ev); /* call handler */
+ }
+}
#else
void
run(void)
@@ -3208,7 +3240,7 @@ run(void)
handler[ev.type](&ev); /* call handler */
}
}
-#endif // IPC_PATCH
+#endif // IPC_PATCH | RESTARTSIG_PATCH
void
scan(void)