From bb66e6d578fdc68fb33d0fde921390d74f20bb31 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 6 Jun 2018 22:57:34 +1000 Subject: Refactor everything that needs to arrange windows * The arrange_foo functions are now replaced with arrange_and_commit, or with manually created transactions and arrange_windows x2. * The arrange functions are now only called from the highest level functions rather than from both high level and low level functions. * Due to the previous point, view_set_fullscreen_raw and view_set_fullscreen are both merged into one function again. * Floating and fullscreen are now working with transactions. --- sway/commands/move.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) (limited to 'sway/commands/move.c') diff --git a/sway/commands/move.c b/sway/commands/move.c index dc9a6f6f..2c9fb77a 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -5,8 +5,10 @@ #include #include #include "sway/commands.h" +#include "sway/desktop/transaction.h" #include "sway/input/seat.h" #include "sway/output.h" +#include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/tree/workspace.h" @@ -96,6 +98,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, seat_set_focus(config->handler_context.seat, focus); container_reap_empty(old_parent); container_reap_empty(destination->parent); + + struct sway_transaction *txn = transaction_create(); + arrange_windows(old_parent, txn); + arrange_windows(destination->parent, txn); + transaction_commit(txn); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "output") == 0) { @@ -125,6 +133,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, seat_set_focus(config->handler_context.seat, old_parent); container_reap_empty(old_parent); container_reap_empty(focus->parent); + + struct sway_transaction *txn = transaction_create(); + arrange_windows(old_parent, txn); + arrange_windows(focus->parent, txn); + transaction_commit(txn); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } return cmd_results_new(CMD_INVALID, "move", expected_syntax); @@ -152,9 +166,28 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, current = container_parent(current, C_WORKSPACE); } container_move_to(current, destination); + + struct sway_transaction *txn = transaction_create(); + arrange_windows(source, txn); + arrange_windows(destination, txn); + transaction_commit(txn); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } +static void move_in_direction(struct sway_container *container, + enum wlr_direction direction, int move_amt) { + struct sway_container *old_parent = container->parent; + container_move(container, direction, move_amt); + + struct sway_transaction *txn = transaction_create(); + arrange_windows(old_parent, txn); + if (container->parent != old_parent) { + arrange_windows(container->parent, txn); + } + transaction_commit(txn); +} + struct cmd_results *cmd_move(int argc, char **argv) { struct cmd_results *error = NULL; int move_amt = 10; @@ -173,13 +206,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { } if (strcasecmp(argv[0], "left") == 0) { - container_move(current, MOVE_LEFT, move_amt); + move_in_direction(current, MOVE_LEFT, move_amt); } else if (strcasecmp(argv[0], "right") == 0) { - container_move(current, MOVE_RIGHT, move_amt); + move_in_direction(current, MOVE_RIGHT, move_amt); } else if (strcasecmp(argv[0], "up") == 0) { - container_move(current, MOVE_UP, move_amt); + move_in_direction(current, MOVE_UP, move_amt); } else if (strcasecmp(argv[0], "down") == 0) { - container_move(current, MOVE_DOWN, move_amt); + move_in_direction(current, MOVE_DOWN, move_amt); } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { return cmd_move_container(current, argc, argv); -- cgit v1.2.3 From b864ac0149212adf753824366e20badfa971b29f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 24 Jun 2018 15:50:53 +1000 Subject: Fix crash when unmapping a view with reapable parents container_destroy was calling container_reap_empty, which calls container_destroy and so on. Eventually the original container_destroy would return a NULL pointer to the caller which caused a crash. This also fixes an arrange on the wrong container when moving views in and out of stacks. --- sway/commands/move.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'sway/commands/move.c') diff --git a/sway/commands/move.c b/sway/commands/move.c index 2c9fb77a..da0f89e9 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -177,13 +177,19 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, static void move_in_direction(struct sway_container *container, enum wlr_direction direction, int move_amt) { - struct sway_container *old_parent = container->parent; + // For simplicity, we'll arrange the entire workspace. The reason for this + // is moving the container might reap the old parent, and container_move + // does not return a surviving parent. + // TODO: Make container_move return the surviving parent so we can arrange + // just that. + struct sway_container *old_ws = container_parent(container, C_WORKSPACE); container_move(container, direction, move_amt); + struct sway_container *new_ws = container_parent(container, C_WORKSPACE); struct sway_transaction *txn = transaction_create(); - arrange_windows(old_parent, txn); - if (container->parent != old_parent) { - arrange_windows(container->parent, txn); + arrange_windows(old_ws, txn); + if (new_ws != old_ws) { + arrange_windows(new_ws, txn); } transaction_commit(txn); } -- cgit v1.2.3 From b6a238c7b70bfb6520c55c480bf6a7e60b4f7db4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 24 Jun 2018 16:03:24 +1000 Subject: Fix crash when running move in an empty workspace --- sway/commands/move.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'sway/commands/move.c') diff --git a/sway/commands/move.c b/sway/commands/move.c index da0f89e9..4ce8d089 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -175,8 +175,12 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, return cmd_results_new(CMD_SUCCESS, NULL, NULL); } -static void move_in_direction(struct sway_container *container, +static struct cmd_results *move_in_direction(struct sway_container *container, enum wlr_direction direction, int move_amt) { + if (container->type == C_WORKSPACE) { + return cmd_results_new(CMD_FAILURE, "move", + "Cannot move workspaces in a direction"); + } // For simplicity, we'll arrange the entire workspace. The reason for this // is moving the container might reap the old parent, and container_move // does not return a surviving parent. @@ -192,6 +196,8 @@ static void move_in_direction(struct sway_container *container, arrange_windows(new_ws, txn); } transaction_commit(txn); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } struct cmd_results *cmd_move(int argc, char **argv) { @@ -212,13 +218,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { } if (strcasecmp(argv[0], "left") == 0) { - move_in_direction(current, MOVE_LEFT, move_amt); + return move_in_direction(current, MOVE_LEFT, move_amt); } else if (strcasecmp(argv[0], "right") == 0) { - move_in_direction(current, MOVE_RIGHT, move_amt); + return move_in_direction(current, MOVE_RIGHT, move_amt); } else if (strcasecmp(argv[0], "up") == 0) { - move_in_direction(current, MOVE_UP, move_amt); + return move_in_direction(current, MOVE_UP, move_amt); } else if (strcasecmp(argv[0], "down") == 0) { - move_in_direction(current, MOVE_DOWN, move_amt); + return move_in_direction(current, MOVE_DOWN, move_amt); } else if (strcasecmp(argv[0], "container") == 0 || strcasecmp(argv[0], "window") == 0) { return cmd_move_container(current, argc, argv); -- cgit v1.2.3 From e8fb6b3325ee545312c092f0b103eea2424fce9f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 29 Jun 2018 19:36:22 +1000 Subject: Fix crash when moving last child of a container to workspace or output We were arranging a parent which may have been deleted by the reaper, which meant the `current` children list of the surviving parent had a dangling pointer. Instead, we now reap the workspace. --- sway/commands/move.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sway/commands/move.c') diff --git a/sway/commands/move.c b/sway/commands/move.c index 4ce8d089..4061df3a 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -90,6 +90,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, } free(ws_name); struct sway_container *old_parent = current->parent; + struct sway_container *old_ws = container_parent(current, C_WORKSPACE); struct sway_container *destination = seat_get_focus_inactive( config->handler_context.seat, ws); container_move_to(current, destination); @@ -99,8 +100,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, container_reap_empty(old_parent); container_reap_empty(destination->parent); + // TODO: Ideally we would arrange the surviving parent after reaping, + // but container_reap_empty does not return it, so we arrange the + // workspace instead. struct sway_transaction *txn = transaction_create(); - arrange_windows(old_parent, txn); + arrange_windows(old_ws, txn); arrange_windows(destination->parent, txn); transaction_commit(txn); @@ -129,13 +133,17 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, focus = destination->children->items[0]; } struct sway_container *old_parent = current->parent; + struct sway_container *old_ws = container_parent(current, C_WORKSPACE); container_move_to(current, focus); seat_set_focus(config->handler_context.seat, old_parent); container_reap_empty(old_parent); container_reap_empty(focus->parent); + // TODO: Ideally we would arrange the surviving parent after reaping, + // but container_reap_empty does not return it, so we arrange the + // workspace instead. struct sway_transaction *txn = transaction_create(); - arrange_windows(old_parent, txn); + arrange_windows(old_ws, txn); arrange_windows(focus->parent, txn); transaction_commit(txn); -- cgit v1.2.3 From fc6fde7d90ee031539252cb8832e11c38cfed686 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 30 Jun 2018 21:07:54 +1000 Subject: Fix compile error --- sway/commands/move.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/commands/move.c') diff --git a/sway/commands/move.c b/sway/commands/move.c index 4061df3a..a4fae388 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -184,7 +184,7 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current, } static struct cmd_results *move_in_direction(struct sway_container *container, - enum wlr_direction direction, int move_amt) { + enum movement_direction direction, int move_amt) { if (container->type == C_WORKSPACE) { return cmd_results_new(CMD_FAILURE, "move", "Cannot move workspaces in a direction"); -- cgit v1.2.3