diff options
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r-- | sway/commands/move.c | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index dc9a6f6f..a4fae388 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -5,8 +5,10 @@ #include <wlr/types/wlr_output_layout.h> #include <wlr/util/log.h> #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" @@ -88,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); @@ -96,6 +99,15 @@ 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); + + // 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_ws, 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) { @@ -121,10 +133,20 @@ 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_ws, 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,6 +174,37 @@ 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 struct cmd_results *move_in_direction(struct sway_container *container, + 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"); + } + // 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_ws, txn); + if (new_ws != old_ws) { + arrange_windows(new_ws, txn); + } + transaction_commit(txn); + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -173,13 +226,13 @@ struct cmd_results *cmd_move(int argc, char **argv) { } if (strcasecmp(argv[0], "left") == 0) { - container_move(current, MOVE_LEFT, move_amt); + return move_in_direction(current, MOVE_LEFT, move_amt); } else if (strcasecmp(argv[0], "right") == 0) { - container_move(current, MOVE_RIGHT, move_amt); + return move_in_direction(current, MOVE_RIGHT, move_amt); } else if (strcasecmp(argv[0], "up") == 0) { - container_move(current, MOVE_UP, move_amt); + return move_in_direction(current, MOVE_UP, move_amt); } else if (strcasecmp(argv[0], "down") == 0) { - container_move(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); |