From fe803b89a7ecee7f737ad82bfe0bab441c163156 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 15 Oct 2018 19:40:40 +1000 Subject: [PATCH 1/4] Fix crash in swap command When swapping containers that are in the root of the workspace, parent will be NULL. --- sway/commands/swap.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sway/commands/swap.c b/sway/commands/swap.c index e7f9cbea..d8ffe78c 100644 --- a/sway/commands/swap.c +++ b/sway/commands/swap.c @@ -22,6 +22,7 @@ static void swap_places(struct sway_container *con1, temp->width = con1->width; temp->height = con1->height; temp->parent = con1->parent; + temp->workspace = con1->workspace; con1->x = con2->x; con1->y = con2->y; @@ -34,8 +35,18 @@ static void swap_places(struct sway_container *con1, con2->height = temp->height; int temp_index = container_sibling_index(con1); - container_insert_child(con2->parent, con1, container_sibling_index(con2)); - container_insert_child(temp->parent, con2, temp_index); + if (con2->parent) { + container_insert_child(con2->parent, con1, + container_sibling_index(con2)); + } else { + workspace_insert_tiling(con2->workspace, con1, + container_sibling_index(con2)); + } + if (temp->parent) { + container_insert_child(temp->parent, con2, temp_index); + } else { + workspace_insert_tiling(temp->workspace, con2, temp_index); + } free(temp); } From 32ba8154b8f5f15b2c778dd404f3acb5becc1719 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 15 Oct 2018 21:57:59 +1000 Subject: [PATCH 2/4] 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); From e64463219838b10bcae3a97998e5f7fe5b09298e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 16 Oct 2018 00:08:00 +1000 Subject: [PATCH 3/4] Fix swaylock version string The referenced constants were not defined so it always printed "version unknown". Also it would exit with code 1. It now exits with code 0. --- swaylock/main.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/swaylock/main.c b/swaylock/main.c index 04c0bb07..86dfd577 100644 --- a/swaylock/main.c +++ b/swaylock/main.c @@ -634,13 +634,9 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, } break; case 'v': -#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE - fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", - SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH); -#else - fprintf(stdout, "version unknown\n"); -#endif - return 1; + fprintf(stdout, "swaylock version " SWAY_VERSION "\n"); + exit(EXIT_SUCCESS); + break; case LO_BS_HL_COLOR: if (state) { state->args.colors.bs_highlight = parse_color(optarg); From a9a9df75ec9556df8a902cf7c63a51058e695369 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Mon, 15 Oct 2018 13:36:56 -0700 Subject: [PATCH 4/4] common/loop.c: add _POSIX_C_SOURCE for clock_gettime and CLOCK_MONOTONIC --- common/loop.c | 1 + 1 file changed, 1 insertion(+) diff --git a/common/loop.c b/common/loop.c index 1b174967..750bee75 100644 --- a/common/loop.c +++ b/common/loop.c @@ -1,3 +1,4 @@ +#define _POSIX_C_SOURCE 199309L #include #include #include