From a12ce12ba6d0f6c371190824f4812c4947661ad9 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 22 Mar 2020 20:29:13 +0000 Subject: [PATCH] Exit when compositor goes away --- src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 0f8b971..09f3539 100644 --- a/src/main.c +++ b/src/main.c @@ -316,9 +316,18 @@ failure: void on_wayland_event(void* obj) { struct wayvnc* self = aml_get_userdata(obj); - // TODO: Check if the compositor has gone away - wl_display_dispatch(self->display); + if (wl_display_prepare_read(self->display) < 0) { + wl_display_cancel_read(self->display); + return; + } + + if (wl_display_read_events(self->display) < 0 && errno == EPIPE) { + log_error("Compositor has gone away. Exiting...\n"); + wayvnc_exit(self); + } + + wl_display_dispatch_pending(self->display); } void wayvnc_exit(struct wayvnc* self)