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) {