From 32ba8154b8f5f15b2c778dd404f3acb5becc1719 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 15 Oct 2018 21:57:59 +1000 Subject: [PATCH] Sway clients: Exit gracefully when compositor is unavailable --- swaybar/bar.c | 6 +++++- swaybg/main.c | 7 ++++++- swayidle/main.c | 4 +++- swaylock/main.c | 6 +++++- swaynag/swaynag.c | 6 +++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/swaybar/bar.c b/swaybar/bar.c index be290c18..0deba72d 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -586,7 +586,11 @@ bool bar_setup(struct swaybar *bar, const char *socket_path) { } bar->display = wl_display_connect(NULL); - assert(bar->display); + if (!bar->display) { + sway_abort("Unable to connect to the compositor. " + "If your compositor is running, check or set the " + "WAYLAND_DISPLAY environment variable."); + } struct wl_registry *registry = wl_display_get_registry(bar->display); wl_registry_add_listener(registry, ®istry_listener, bar); diff --git a/swaybg/main.c b/swaybg/main.c index 742669ef..45b7a913 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -222,7 +222,12 @@ int main(int argc, const char **argv) { } state.display = wl_display_connect(NULL); - assert(state.display); + if (!state.display) { + wlr_log(WLR_ERROR, "Unable to connect to the compositor. " + "If your compositor is running, check or set the " + "WAYLAND_DISPLAY environment variable."); + return 1; + } struct wl_registry *registry = wl_display_get_registry(state.display); wl_registry_add_listener(registry, ®istry_listener, &state); diff --git a/swayidle/main.c b/swayidle/main.c index 5b6c95a7..93f4c94b 100644 --- a/swayidle/main.c +++ b/swayidle/main.c @@ -388,7 +388,9 @@ int main(int argc, char *argv[]) { state.display = wl_display_connect(NULL); if (state.display == NULL) { - wlr_log(WLR_ERROR, "Failed to create display"); + wlr_log(WLR_ERROR, "Unable to connect to the compositor. " + "If your compositor is running, check or set the " + "WAYLAND_DISPLAY environment variable."); return -3; } diff --git a/swaylock/main.c b/swaylock/main.c index 27bcfe32..04c0bb07 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -908,7 +908,11 @@ int main(int argc, char **argv) { wl_list_init(&state.surfaces); state.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); state.display = wl_display_connect(NULL); - assert(state.display); + if (!state.display) { + sway_abort("Unable to connect to the compositor. " + "If your compositor is running, check or set the " + "WAYLAND_DISPLAY environment variable."); + } struct wl_registry *registry = wl_display_get_registry(state.display); wl_registry_add_listener(registry, ®istry_listener, &state); diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index 69da851e..fa6bbe05 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c @@ -342,7 +342,11 @@ static const struct wl_registry_listener registry_listener = { void swaynag_setup(struct swaynag *swaynag) { swaynag->display = wl_display_connect(NULL); - assert(swaynag->display); + if (!swaynag->display) { + sway_abort("Unable to connect to the compositor. " + "If your compositor is running, check or set the " + "WAYLAND_DISPLAY environment variable."); + } swaynag->scale = 1; wl_list_init(&swaynag->outputs);