From e40da415d5b4de3ff6a004452822501bbea35efb Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Thu, 27 Apr 2017 12:10:13 -0400 Subject: [PATCH] reworked event loop for x11 to have a 100ms timeout. This allows us to refresh periodically even when no X events have occurred --- lib/x11.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/x11.c b/lib/x11.c index 27104fc..cdf49e2 100644 --- a/lib/x11.c +++ b/lib/x11.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include static struct XSel* selfetch(Atom atom); static void selclear(XEvent* evnt); @@ -324,9 +326,19 @@ void x11_handle_events(void) { } void x11_loop(void) { + fd_set fds; + int xfd = ConnectionNumber(X.display); for (XEvent e; Running;) { - XPeekEvent(X.display,&e); - x11_handle_events(); + struct timeval tv = { .tv_usec = 100000 }; + FD_ZERO(&fds); + FD_SET(xfd, &fds); + + int ready = select(xfd+1, &fds, NULL, NULL, &tv); + if (ready > 0) + x11_handle_events(); + //else + // timer expired + if (Running) { /* redraw the window */ Config->redraw(X.width, X.height); -- 2.52.0