From: Michael D. Lowis Date: Thu, 27 Apr 2017 16:10:13 +0000 (-0400) Subject: reworked event loop for x11 to have a 100ms timeout. This allows us to refresh period... X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e40da415d5b4de3ff6a004452822501bbea35efb;p=projs%2Ftide.git reworked event loop for x11 to have a 100ms timeout. This allows us to refresh periodically even when no X events have occurred --- 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);