From bd44e82ecaefbd2056eeb58bba48209b94b28c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Fri, 22 Oct 2021 18:07:14 +0200 Subject: [PATCH] =?UTF-8?q?bar/wayland:=20coalesce=20=E2=80=9Crefresh?= =?UTF-8?q?=E2=80=9D=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reduces the number of repaints primarily during startup, but also when e.g. switching workspace. --- bar/wayland.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/bar/wayland.c b/bar/wayland.c index 02e9ad6..90d1103 100644 --- a/bar/wayland.c +++ b/bar/wayland.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -1139,16 +1140,30 @@ loop(struct bar *_bar, } if (fds[2].revents & POLLIN) { - uint8_t command; - if (read(backend->pipe_fds[0], &command, sizeof(command)) - != sizeof(command)) - { - LOG_ERRNO("failed to read from command pipe"); - break; + bool do_expose = false; + + /* Coalesce “refresh” commands */ + size_t count = 0; + while (true) { + uint8_t command; + ssize_t r = read(backend->pipe_fds[0], &command, sizeof(command)); + if (r < 0 && errno == EAGAIN) + break; + if (r != sizeof(command)) { + LOG_ERRNO("failed to read from command pipe"); + break; + } + + assert(command == 1); + if (command == 1) { + count++; + do_expose = true; + } } - assert(command == 1); - expose(_bar); + LOG_DBG("coalesced %zu expose commands", count); + if (do_expose) + expose(_bar); } if (fds[1].revents & POLLIN) {