bar/wayland: coalesce “refresh” commands

This reduces the number of repaints primarily during startup, but also
when e.g. switching workspace.
This commit is contained in:
Daniel Eklöf 2021-10-22 18:07:14 +02:00
parent 939b81a4ea
commit bd44e82eca
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -7,6 +7,7 @@
#include <unistd.h> #include <unistd.h>
#include <poll.h> #include <poll.h>
#include <pthread.h> #include <pthread.h>
#include <errno.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <fcntl.h> #include <fcntl.h>
@ -1139,16 +1140,30 @@ loop(struct bar *_bar,
} }
if (fds[2].revents & POLLIN) { if (fds[2].revents & POLLIN) {
uint8_t command; bool do_expose = false;
if (read(backend->pipe_fds[0], &command, sizeof(command))
!= sizeof(command)) /* Coalesce “refresh” commands */
{ size_t count = 0;
LOG_ERRNO("failed to read from command pipe"); while (true) {
break; 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); LOG_DBG("coalesced %zu expose commands", count);
expose(_bar); if (do_expose)
expose(_bar);
} }
if (fds[1].revents & POLLIN) { if (fds[1].revents & POLLIN) {