]> git.mdlowis.com Git - projs/tide.git/commitdiff
improve idle performance by halting redraws after a second of now pipe activity
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 6 Jun 2019 00:26:17 +0000 (20:26 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 6 Jun 2019 00:26:17 +0000 (20:26 -0400)
src/lib/x11.c
src/lib/x11_gc.c
src/tframe.c
src/tide.c

index b36cb53bda2d5c575cf04a5e1e4739aa37a67120..052d08e7116490ae59b4106d73922df8618a47dc 100644 (file)
@@ -4,6 +4,7 @@
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include "config.h"
 
 struct XConf X;
 static Bool Has_Error = False;
@@ -46,20 +47,24 @@ XErrorEvent* x11_error_get(void) {
 void x11_mkwin(XConf* x, int width, int height, int evmask) {
     /* create the main window */
     x->width = width, x->height = height;
-    x->self = XCreateSimpleWindow(
-        x->display, x->root, 0, 0, x->width, x->height, 0, x->depth, -1);
+    XSetWindowAttributes attr;
+    attr.background_pixel = Palette[EditBg];
+    attr.bit_gravity = NorthWestGravity;
+    attr.backing_store = WhenMapped;
+    attr.event_mask = evmask
+        | FocusChangeMask
+        | ExposureMask
+        | VisibilityChangeMask
+        | StructureNotifyMask
+    ;
+    x->self = XCreateWindow(
+        x->display, x->root, 0, 0, x->width, x->height, 0, x->depth, InputOutput, x->visual,
+        CWBackPixel | CWBitGravity | CWBackingStore | CWEventMask,
+        &attr);
 
     /* register interest in the delete window message */
     Atom wmDeleteMessage = XInternAtom(x->display, "WM_DELETE_WINDOW", False);
     XSetWMProtocols(x->display, x->self, &wmDeleteMessage, 1);
-    /* setup window attributes and events */
-    XSetWindowAttributes swa;
-    swa.bit_gravity = NorthWestGravity;
-    swa.do_not_propagate_mask = 0; /* do not hide any events from child windows */
-    XChangeWindowAttributes(x->display, x->self,
-        CWBackPixel|CWBorderPixel|CWBitGravity|CWEventMask|CWColormap,
-        &swa);
-    XSelectInput(x->display, x->self, evmask);
 }
 
 void x11_mkdialog(XConf* x, int width, int height, int evmask) {
@@ -80,12 +85,13 @@ static void update_state(XConf* x, XEvent* e) {
 }
 
 void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) {
-    int nqueued, nevents;
+    int nevents;
     /* reap zombie background processes */
     for (int status; waitpid(-1, &status, WNOHANG) > 0;);
     /* process the entire event queue */
-    do {
-        nqueued = XEventsQueued(x->display, QueuedAfterFlush);
+
+    while (XEventsQueued(x->display, QueuedAfterFlush))
+    {
         XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
         for (XEvent e; XPending(x->display);) {
             XNextEvent(x->display, &e);
@@ -93,9 +99,8 @@ void x11_process_events(XConf* x, void (*redrawfn)(XConf*)) {
             if (!XFilterEvent(&e, None) && x->eventfns[e.type])
                 (x->eventfns[e.type])(x, &e);
         }
-        if (nqueued) redrawfn(x);
-        XFlush(x->display);
-    } while ((nqueued = XEventsQueued(x->display, QueuedAfterFlush)) > 0);
+    }
+    (void)redrawfn;
 }
 
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {
index bf2fc12b1ba3970f0e67762940553bed2c0e9630..fb9be9dfcb4b23415bed312f1096ce59308e06b5 100644 (file)
@@ -69,7 +69,8 @@ void x11_show(XConf* x) {
         XNextEvent(x->display, &ev);
         if (XFilterEvent(&ev, None))
             continue;
-        x11_resize(x, &ev);
+        if (ev.type == ConfigureNotify)
+            x11_resize(x, &ev);
     } while (ev.type != MapNotify);
     XWarpPointer(x->display, None, x->self, 0, 0, x->width, x->height, x->width/2, x->height/2);
 }
index 2755f2795ed03a051314fbe10f3d1f82ce6ebbe5..7979304c395534b3af7c1d4584089199d8342d25 100644 (file)
@@ -221,8 +221,8 @@ void win_init(void) {
         | ButtonMotionMask
         | SubstructureRedirectMask
         | SubstructureNotifyMask
-        | StructureNotifyMask
-        | ExposureMask
+//        | StructureNotifyMask
+//        | ExposureMask
 //        | FocusChangeMask
 //        | PropertyChangeMask
 //        | VisibilityChangeMask
index e590bacdf63221e4222423264b9f0d9d30fdd04a..3201cec9ea10cfa609aa76461f98b17ee94ded13 100644 (file)
@@ -200,8 +200,6 @@ static void xredraw(XConf* x) {
     Divider = draw_hrule(x, &csr);
     draw_view(x, &Regions[EDIT], x->font, editrows, &csr, EditBg, EditFg, EditSel, SyncMouse);
     draw_scroll(x, &csr, win_view(EDIT), Divider);
-    draw_rect(x, WinBdr, 0, x->height-1,  x->width, 1);
-    draw_rect(x, WinBdr, x->width-1, 0,  1, x->height);
     XCopyArea(x->display, x->pixmap, x->self, x->gc, 0, 0, x->width, x->height, 0, 0);
     SyncMouse = false;
     if (Divider < olddiv && Focused == TAGS) {
@@ -232,15 +230,11 @@ void win_init(void) {
         exit(EXIT_FAILURE);
     }
     x11_mkwin(&X, 640, 480, 0
-        | FocusChangeMask
         | KeyPressMask
         | ButtonPressMask
         | ButtonReleaseMask
         | ButtonMotionMask
         | PropertyChangeMask
-        | ExposureMask
-        | VisibilityChangeMask
-        | StructureNotifyMask
     );
     x11_init_gc(&X);
     x11_sel_init(&X);
@@ -283,8 +277,12 @@ void win_loop(void) {
     tide_send("ADD");
     job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
     XSync(X.display, False);
+    int maxcount = 1000 / Timeout;
+    int count = 0;
     while (X.running) {
-        if (!job_poll(Timeout))
+        bool ready = job_poll(Timeout);
+        count += (ready ? -count : 1);
+        if (count < maxcount)
             xupdate(NULL);
     }
 }