]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed event loop. turns out X11 is finnicky
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Jul 2017 01:44:42 +0000 (21:44 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 10 Jul 2017 01:44:42 +0000 (21:44 -0400)
lib/event.c
lib/win.c

index 6c2bf3d660a00a8fedd3f8b48dd9e16d7cd20af5..964c3e9b13b7d1a6a775039756fc402b4a01b381 100644 (file)
@@ -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) {
index 22a587a5fcd14ad162860539be2d2fb17c2a1cad..e103f3f469ec8d725debf4ecd8103f0fdd68d21a 100644 (file)
--- 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) {