From ba8a6eb8882a2c27192ebd9b58d63e6f269d8bcc Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 5 Jun 2019 20:26:17 -0400 Subject: [PATCH] improve idle performance by halting redraws after a second of now pipe activity --- src/lib/x11.c | 37 +++++++++++++++++++++---------------- src/lib/x11_gc.c | 3 ++- src/tframe.c | 4 ++-- src/tide.c | 12 +++++------- 4 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/lib/x11.c b/src/lib/x11.c index b36cb53..052d08e 100644 --- a/src/lib/x11.c +++ b/src/lib/x11.c @@ -4,6 +4,7 @@ #include #include #include +#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)) { diff --git a/src/lib/x11_gc.c b/src/lib/x11_gc.c index bf2fc12..fb9be9d 100644 --- a/src/lib/x11_gc.c +++ b/src/lib/x11_gc.c @@ -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); } diff --git a/src/tframe.c b/src/tframe.c index 2755f27..7979304 100644 --- a/src/tframe.c +++ b/src/tframe.c @@ -221,8 +221,8 @@ void win_init(void) { | ButtonMotionMask | SubstructureRedirectMask | SubstructureNotifyMask - | StructureNotifyMask - | ExposureMask +// | StructureNotifyMask +// | ExposureMask // | FocusChangeMask // | PropertyChangeMask // | VisibilityChangeMask diff --git a/src/tide.c b/src/tide.c index e590bac..3201cec 100644 --- a/src/tide.c +++ b/src/tide.c @@ -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); } } -- 2.51.0