From 42fdf156979222975dc9614ce1f246ff8b6e48b7 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Sun, 9 Jul 2017 21:44:42 -0400 Subject: [PATCH] fixed event loop. turns out X11 is finnicky --- lib/event.c | 3 ++- lib/win.c | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/event.c b/lib/event.c index 6c2bf3d..964c3e9 100644 --- a/lib/event.c +++ b/lib/event.c @@ -19,6 +19,7 @@ bool event_poll(int ms) { /* poll for new events */ long n = poll(Descriptors, NumDescriptors, ms); if (n < 0) die("poll() :"); + if (n == 0) return false; /* Handle any events that occurred */ for (int i = 0; i < NumDescriptors; i++) { @@ -42,7 +43,7 @@ bool event_poll(int ms) { } } - return (n > 0); + return true; } void event_watchfd(int fd, int iodir, event_cbfn_t fn, void* data) { diff --git a/lib/win.c b/lib/win.c index 22a587a..e103f3f 100644 --- a/lib/win.c +++ b/lib/win.c @@ -72,8 +72,14 @@ void win_loop(void) { int ms = config_get_int(EventTimeout); event_watchfd(x11_connfd(), INPUT, win_update, NULL); while (x11_running()) { - if (event_poll(ms) || update_focus() || x11_running()) - x11_flip(); + bool pending = event_poll(ms); + int nevents = x11_events_queued(); + if (update_focus() || pending || nevents) { + x11_events_take(); + if (x11_running()) + x11_flip(); + } + x11_flush(); } x11_finish(); } @@ -204,11 +210,10 @@ static void layout(int width, int height) { static void onredraw(int width, int height) { static uint64_t maxtime = 0; + uint64_t start = getmillis(); size_t fheight = x11_font_height(Font); size_t fwidth = x11_font_width(Font); - uint64_t start = getmillis(); - layout(width, height); onupdate(); // Let the user program update the status and other content view_update(win_view(STATUS), Regions[STATUS].clrnor, Regions[STATUS].clrsel, &(Regions[STATUS].csrx), &(Regions[STATUS].csry)); @@ -282,10 +287,7 @@ static void onredraw(int width, int height) { uint64_t stop = getmillis(); uint64_t elapsed = stop-start; - //if (elapsed > maxtime) { - //printf("%llu\n", elapsed); - maxtime = elapsed; - //} + //printf("%llu\n", elapsed); } static void oninput(int mods, Rune key) { -- 2.49.0