@@ 442,48 442,6 @@ static int draw(struct context *ctx) {
return 0;
}
-static int display_dispatch(struct pollfd *pfd, int polln, struct wl_display *display, int timeout) {
- assert(polln > 0);
- if (wl_display_prepare_read(display) == -1) {
- return wl_display_dispatch_pending(display);
- }
-
- pfd[EVENT_LOOP_WAYLAND].events = POLLOUT;
- while (wl_display_flush(display) == -1) {
- if (errno != EAGAIN && errno != EPIPE) {
- wl_display_cancel_read(display);
- return -1;
- }
-
- // We only poll the wayland fd here
- while (poll(pfd, 1, -1) == -1) {
- if (errno != EINTR) {
- wl_display_cancel_read(display);
- return -1;
- }
- }
- }
-
- pfd[EVENT_LOOP_WAYLAND].events = POLLIN;
- while (poll(pfd, polln, timeout) == -1) {
- if (errno != EINTR) {
- wl_display_cancel_read(display);
- return -1;
- }
- }
-
- if ((pfd[0].revents & POLLIN) == 0) {
- wl_display_cancel_read(display);
- return 0;
- }
-
- if (wl_display_read_events(display) == -1) {
- return -1;
- }
-
- return wl_display_dispatch_pending(display);
-}
-
static bool equal_within(double a, double b, double hysteresis) {
return a > b - hysteresis && a < b + hysteresis;
}
@@ 662,6 620,48 @@ static int setup_wayland(struct context *ctx, bool layer_shell, bool vertical, i
return 0;
}
+static int display_dispatch(struct pollfd *pfd, int polln, struct wl_display *display) {
+ assert(polln > 0);
+ if (wl_display_prepare_read(display) == -1) {
+ return wl_display_dispatch_pending(display);
+ }
+
+ pfd[EVENT_LOOP_WAYLAND].events = POLLOUT;
+ while (wl_display_flush(display) == -1) {
+ if (errno != EAGAIN && errno != EPIPE) {
+ wl_display_cancel_read(display);
+ return -1;
+ }
+
+ // We only poll the wayland fd here
+ while (poll(pfd, 1, -1) == -1) {
+ if (errno != EINTR) {
+ wl_display_cancel_read(display);
+ return -1;
+ }
+ }
+ }
+
+ pfd[EVENT_LOOP_WAYLAND].events = POLLIN;
+ while (poll(pfd, polln, -1) == -1) {
+ if (errno != EINTR) {
+ wl_display_cancel_read(display);
+ return -1;
+ }
+ }
+
+ if ((pfd[0].revents & POLLIN) == 0) {
+ wl_display_cancel_read(display);
+ return 0;
+ }
+
+ if (wl_display_read_events(display) == -1) {
+ return -1;
+ }
+
+ return wl_display_dispatch_pending(display);
+}
+
static const char usage[] = ""
"usage: %s [options]\n"
" -h show this help message\n"
@@ 762,7 762,7 @@ int main(int argc, char **argv) {
draw(&ctx);
- while (display_dispatch(pollfds, 2, ctx.display, -1) != -1 && ctx.running) {
+ while (display_dispatch(pollfds, 2, ctx.display) != -1 && ctx.running) {
if (pollfds[EVENT_LOOP_PIPEWIRE].revents & POLLIN) {
int ret = pw_loop_iterate(ctx.pw_loop, 0);
if (ret < 0) {