From: Michael D. Lowis Date: Thu, 20 Dec 2018 16:55:26 +0000 (-0500) Subject: optimize event handling and redrwa logic so we don't monopolize the server X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=e58c194ca0a259bbc49bde7925b27ecaf8261c01;p=projs%2Ftide.git optimize event handling and redrwa logic so we don't monopolize the server --- diff --git a/config.h b/config.h index 169cfb2..58bff13 100644 --- 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 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 diff --git a/src/lib/x11.c b/src/lib/x11.c index 8bb63ba..bccc0b0 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -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) {