aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-06 22:57:34 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-09 10:11:25 +1000
commitbb66e6d578fdc68fb33d0fde921390d74f20bb31 (patch)
tree99d3763eee97acb870c16a762c0ee40af787c295 /sway/commands/move.c
parentMake main properties be the pending state (diff)
downloadsway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.tar.gz
sway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.tar.zst
sway-bb66e6d578fdc68fb33d0fde921390d74f20bb31.zip
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.
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c41
1 files changed, 37 insertions, 4 deletions
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 @@
5#include <wlr/types/wlr_output_layout.h> 5#include <wlr/types/wlr_output_layout.h>
6#include <wlr/util/log.h> 6#include <wlr/util/log.h>
7#include "sway/commands.h" 7#include "sway/commands.h"
8#include "sway/desktop/transaction.h"
8#include "sway/input/seat.h" 9#include "sway/input/seat.h"
9#include "sway/output.h" 10#include "sway/output.h"
11#include "sway/tree/arrange.h"
10#include "sway/tree/container.h" 12#include "sway/tree/container.h"
11#include "sway/tree/layout.h" 13#include "sway/tree/layout.h"
12#include "sway/tree/workspace.h" 14#include "sway/tree/workspace.h"
@@ -96,6 +98,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
96 seat_set_focus(config->handler_context.seat, focus); 98 seat_set_focus(config->handler_context.seat, focus);
97 container_reap_empty(old_parent); 99 container_reap_empty(old_parent);
98 container_reap_empty(destination->parent); 100 container_reap_empty(destination->parent);
101
102 struct sway_transaction *txn = transaction_create();
103 arrange_windows(old_parent, txn);
104 arrange_windows(destination->parent, txn);
105 transaction_commit(txn);
106
99 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 107 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
100 } else if (strcasecmp(argv[1], "to") == 0 108 } else if (strcasecmp(argv[1], "to") == 0
101 && strcasecmp(argv[2], "output") == 0) { 109 && strcasecmp(argv[2], "output") == 0) {
@@ -125,6 +133,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
125 seat_set_focus(config->handler_context.seat, old_parent); 133 seat_set_focus(config->handler_context.seat, old_parent);
126 container_reap_empty(old_parent); 134 container_reap_empty(old_parent);
127 container_reap_empty(focus->parent); 135 container_reap_empty(focus->parent);
136
137 struct sway_transaction *txn = transaction_create();
138 arrange_windows(old_parent, txn);
139 arrange_windows(focus->parent, txn);
140 transaction_commit(txn);
141
128 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 142 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
129 } 143 }
130 return cmd_results_new(CMD_INVALID, "move", expected_syntax); 144 return cmd_results_new(CMD_INVALID, "move", expected_syntax);
@@ -152,9 +166,28 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current,
152 current = container_parent(current, C_WORKSPACE); 166 current = container_parent(current, C_WORKSPACE);
153 } 167 }
154 container_move_to(current, destination); 168 container_move_to(current, destination);
169
170 struct sway_transaction *txn = transaction_create();
171 arrange_windows(source, txn);
172 arrange_windows(destination, txn);
173 transaction_commit(txn);
174
155 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 175 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
156} 176}
157 177
178static void move_in_direction(struct sway_container *container,
179 enum wlr_direction direction, int move_amt) {
180 struct sway_container *old_parent = container->parent;
181 container_move(container, direction, move_amt);
182
183 struct sway_transaction *txn = transaction_create();
184 arrange_windows(old_parent, txn);
185 if (container->parent != old_parent) {
186 arrange_windows(container->parent, txn);
187 }
188 transaction_commit(txn);
189}
190
158struct cmd_results *cmd_move(int argc, char **argv) { 191struct cmd_results *cmd_move(int argc, char **argv) {
159 struct cmd_results *error = NULL; 192 struct cmd_results *error = NULL;
160 int move_amt = 10; 193 int move_amt = 10;
@@ -173,13 +206,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
173 } 206 }
174 207
175 if (strcasecmp(argv[0], "left") == 0) { 208 if (strcasecmp(argv[0], "left") == 0) {
176 container_move(current, MOVE_LEFT, move_amt); 209 move_in_direction(current, MOVE_LEFT, move_amt);
177 } else if (strcasecmp(argv[0], "right") == 0) { 210 } else if (strcasecmp(argv[0], "right") == 0) {
178 container_move(current, MOVE_RIGHT, move_amt); 211 move_in_direction(current, MOVE_RIGHT, move_amt);
179 } else if (strcasecmp(argv[0], "up") == 0) { 212 } else if (strcasecmp(argv[0], "up") == 0) {
180 container_move(current, MOVE_UP, move_amt); 213 move_in_direction(current, MOVE_UP, move_amt);
181 } else if (strcasecmp(argv[0], "down") == 0) { 214 } else if (strcasecmp(argv[0], "down") == 0) {
182 container_move(current, MOVE_DOWN, move_amt); 215 move_in_direction(current, MOVE_DOWN, move_amt);
183 } else if (strcasecmp(argv[0], "container") == 0 216 } else if (strcasecmp(argv[0], "container") == 0
184 || strcasecmp(argv[0], "window") == 0) { 217 || strcasecmp(argv[0], "window") == 0) {
185 return cmd_move_container(current, argc, argv); 218 return cmd_move_container(current, argc, argv);