]> git.mdlowis.com Git - projs/tide.git/commitdiff
optimize event handling and redrwa logic so we don't monopolize the server
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 20 Dec 2018 16:55:26 +0000 (11:55 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 20 Dec 2018 16:55:26 +0000 (11:55 -0500)
config.h
foo.md [new file with mode: 0644]
src/lib/x11.c

index 169cfb2616ca09e29b5da5b5d3a7f6f16878f286..58bff13a7e46899277c245a42422de9f7d5902b0 100644 (file)
--- a/config.h
+++ b/config.h
@@ -47,7 +47,7 @@ static char* Fonts[2] = {
 int WinWidth = 640;
 int WinHeight = 480;
 int ScrollWidth = 5;
-int Timeout = 50;
+int Timeout = 100;
 int TabWidth = 4;
 int ScrollBy = 1;
 int ClickTime = 500;
diff --git a/foo.md b/foo.md
new file mode 100644 (file)
index 0000000..06c59fc
--- /dev/null
+++ b/foo.md
@@ -0,0 +1,10 @@
+# Ctrl+D
+
+1) Tag: "Get", Edit: nil
+2) Tag: "Get", Edit: "Makefile"
+3) Tag: "Get Makefile", Edit: nil
+4) Tag: nil, Edit: "Get"
+5) Tag: "Makefile", Edit: "Get"
+6) Tag: nil, Edit: "Get Makefile"
+
+# Tag Execution
\ No newline at end of file
index 8bb63baf3d5cda48a8638cfb60245e6247630d48..bccc0b0f969f4ac73e20c0fd59c3add54a92b2db 100644 (file)
@@ -428,9 +428,9 @@ static void xresize(XConf* x, XEvent* e) {
 
 static void xupdate(Job* job) {
     (void)job;
-    int nevents;
+    int nevents, nqueued;
     /* process events from the queue */
-    XEventsQueued(X.display, QueuedAfterFlush);
+    nqueued = XEventsQueued(X.display, QueuedAfterFlush);
     XGetMotionEvents(X.display, X.self, CurrentTime, CurrentTime, &nevents);
     for (XEvent e; XPending(X.display);) {
         XNextEvent(X.display, &e);
@@ -438,22 +438,24 @@ static void xupdate(Job* job) {
             (X.eventfns[e.type])(&X, &e);
         for (int status; waitpid(-1, &status, WNOHANG) > 0;);
     }
-    /* force update the title */
-    win_title(NULL);
-    /* determine the size of the regions */
-    size_t maxtagrows = ((X.height/4) / X.tagfont->height);
-    size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
-    size_t tagregsz = (tagrows * X.tagfont->height) + 7;
-    size_t editrows = (X.height - tagregsz) / X.font->height ;
-    /* draw the regions to the window */
-    drawcsr csr = { .w = X.width, .h = X.height };
-    csr.x += ScrollWidth + 1;
-    draw_statbox();
-    draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel);
-    draw_hrule(&csr);
-    draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel);
-    draw_scroll(&csr);
-    XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+    if (nqueued || !job) {
+            /* force update the title */
+        win_title(NULL);
+        /* determine the size of the regions */
+        size_t maxtagrows = ((X.height/4) / X.tagfont->height);
+        size_t tagrows = view_limitrows(win_view(TAGS), maxtagrows);
+        size_t tagregsz = (tagrows * X.tagfont->height) + 7;
+        size_t editrows = (X.height - tagregsz) / X.font->height ;
+        /* draw the regions to the window */
+        drawcsr csr = { .w = X.width, .h = X.height };
+        csr.x += ScrollWidth + 1;
+        draw_statbox();
+        draw_view(&Regions[TAGS], X.tagfont, tagrows, &csr, TagsBg, TagsFg, TagsSel);
+        draw_hrule(&csr);
+        draw_view(&Regions[EDIT], X.font, editrows, &csr, EditBg, EditFg, EditSel);
+        draw_scroll(&csr);
+        XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+    }
     XFlush(X.display);
 }
 
@@ -516,6 +518,7 @@ void win_init(KeyBinding* bindings) {
 }
 
 void win_title(char* path) {
+    static char prevtitle[4096] = {0};
     char title[4096] = {0};
     if (!path) path = win_view(EDIT)->buffer.path;
     if (!path) path = "*scratch*";
@@ -523,15 +526,13 @@ void win_title(char* path) {
         (DosLineFeed ? 'C' : 'N'),
         (ExpandTabs ? 'S' : 'T'),
         path);
-    XStoreName(X.display, X.self, title);
+    if (strcmp(prevtitle, title))
+        XStoreName(X.display, X.self, title);
+    memcpy(prevtitle, title, sizeof(title));
 }
 
 void win_font(char* font) {
-    if (font) {
-        font_load(font);
-    } else {
-        font_load(Fonts[++FontSel % nelem(Fonts)]);
-    }
+    font_load(font ? font : Fonts[++FontSel % nelem(Fonts)]);
 }
 
 void win_prop_set(char* xname, char* ename, char* value) {
@@ -543,7 +544,8 @@ void win_prop_set(char* xname, char* ename, char* value) {
 }
 
 void win_update(int ms) {
-    job_poll(ms);
+    if (job_poll(ms))
+        xupdate(NULL);
 }
 
 void win_loop(void) {