aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c207
1 files changed, 106 insertions, 101 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index f8f89f18..8addf26e 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <ctype.h> 1#include <ctype.h>
3#include <math.h> 2#include <math.h>
4#include <stdbool.h> 3#include <stdbool.h>
@@ -113,8 +112,8 @@ static void container_move_to_container_from_direction(
113 struct sway_container *container, struct sway_container *destination, 112 struct sway_container *container, struct sway_container *destination,
114 enum wlr_direction move_dir) { 113 enum wlr_direction move_dir) {
115 if (destination->view) { 114 if (destination->view) {
116 if (destination->parent == container->parent && 115 if (destination->pending.parent == container->pending.parent &&
117 destination->workspace == container->workspace) { 116 destination->pending.workspace == container->pending.workspace) {
118 sway_log(SWAY_DEBUG, "Swapping siblings"); 117 sway_log(SWAY_DEBUG, "Swapping siblings");
119 list_t *siblings = container_get_siblings(container); 118 list_t *siblings = container_get_siblings(container);
120 int container_index = list_find(siblings, container); 119 int container_index = list_find(siblings, container);
@@ -126,28 +125,28 @@ static void container_move_to_container_from_direction(
126 int offset = 125 int offset =
127 move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP; 126 move_dir == WLR_DIRECTION_LEFT || move_dir == WLR_DIRECTION_UP;
128 int index = container_sibling_index(destination) + offset; 127 int index = container_sibling_index(destination) + offset;
129 if (destination->parent) { 128 if (destination->pending.parent) {
130 container_insert_child(destination->parent, container, index); 129 container_insert_child(destination->pending.parent, container, index);
131 } else { 130 } else {
132 workspace_insert_tiling(destination->workspace, 131 workspace_insert_tiling(destination->pending.workspace,
133 container, index); 132 container, index);
134 } 133 }
135 container->width = container->height = 0; 134 container->pending.width = container->pending.height = 0;
136 container->width_fraction = container->height_fraction = 0; 135 container->width_fraction = container->height_fraction = 0;
137 workspace_squash(destination->workspace); 136 workspace_squash(destination->pending.workspace);
138 } 137 }
139 return; 138 return;
140 } 139 }
141 140
142 if (is_parallel(destination->layout, move_dir)) { 141 if (is_parallel(destination->pending.layout, move_dir)) {
143 sway_log(SWAY_DEBUG, "Reparenting container (parallel)"); 142 sway_log(SWAY_DEBUG, "Reparenting container (parallel)");
144 int index = 143 int index =
145 move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ? 144 move_dir == WLR_DIRECTION_RIGHT || move_dir == WLR_DIRECTION_DOWN ?
146 0 : destination->children->length; 145 0 : destination->pending.children->length;
147 container_insert_child(destination, container, index); 146 container_insert_child(destination, container, index);
148 container->width = container->height = 0; 147 container->pending.width = container->pending.height = 0;
149 container->width_fraction = container->height_fraction = 0; 148 container->width_fraction = container->height_fraction = 0;
150 workspace_squash(destination->workspace); 149 workspace_squash(destination->pending.workspace);
151 return; 150 return;
152 } 151 }
153 152
@@ -168,7 +167,7 @@ static void container_move_to_container_from_direction(
168static void container_move_to_workspace_from_direction( 167static void container_move_to_workspace_from_direction(
169 struct sway_container *container, struct sway_workspace *workspace, 168 struct sway_container *container, struct sway_workspace *workspace,
170 enum wlr_direction move_dir) { 169 enum wlr_direction move_dir) {
171 container->width = container->height = 0; 170 container->pending.width = container->pending.height = 0;
172 container->width_fraction = container->height_fraction = 0; 171 container->width_fraction = container->height_fraction = 0;
173 172
174 if (is_parallel(workspace->layout, move_dir)) { 173 if (is_parallel(workspace->layout, move_dir)) {
@@ -188,8 +187,8 @@ static void container_move_to_workspace_from_direction(
188 workspace_add_tiling(workspace, container); 187 workspace_add_tiling(workspace, container);
189 return; 188 return;
190 } 189 }
191 while (focus_inactive->parent) { 190 while (focus_inactive->pending.parent) {
192 focus_inactive = focus_inactive->parent; 191 focus_inactive = focus_inactive->pending.parent;
193 } 192 }
194 container_move_to_container_from_direction(container, focus_inactive, 193 container_move_to_container_from_direction(container, focus_inactive,
195 move_dir); 194 move_dir);
@@ -197,25 +196,33 @@ static void container_move_to_workspace_from_direction(
197 196
198static void container_move_to_workspace(struct sway_container *container, 197static void container_move_to_workspace(struct sway_container *container,
199 struct sway_workspace *workspace) { 198 struct sway_workspace *workspace) {
200 if (container->workspace == workspace) { 199 if (container->pending.workspace == workspace) {
201 return; 200 return;
202 } 201 }
203 struct sway_workspace *old_workspace = container->workspace; 202 struct sway_workspace *old_workspace = container->pending.workspace;
204 if (container_is_floating(container)) { 203 if (container_is_floating(container)) {
205 struct sway_output *old_output = container->workspace->output; 204 struct sway_output *old_output = container->pending.workspace->output;
206 container_detach(container); 205 container_detach(container);
207 workspace_add_floating(workspace, container); 206 workspace_add_floating(workspace, container);
208 container_handle_fullscreen_reparent(container); 207 container_handle_fullscreen_reparent(container);
209 // If changing output, center it within the workspace 208 // If changing output, adjust the coordinates of the window.
210 if (old_output != workspace->output && !container->fullscreen_mode) { 209 if (old_output != workspace->output && !container->pending.fullscreen_mode) {
211 container_floating_move_to_center(container); 210 struct wlr_box workspace_box, old_workspace_box;
211 workspace_get_box(workspace, &workspace_box);
212 workspace_get_box(old_workspace, &old_workspace_box);
213 floating_fix_coordinates(container, &old_workspace_box, &workspace_box);
214 if (container->scratchpad && workspace->output) {
215 struct wlr_box output_box;
216 output_get_box(workspace->output, &output_box);
217 container->transform = workspace_box;
218 }
212 } 219 }
213 } else { 220 } else {
214 container_detach(container); 221 container_detach(container);
215 if (workspace_is_empty(workspace) && container->children) { 222 if (workspace_is_empty(workspace) && container->pending.children) {
216 workspace_unwrap_children(workspace, container); 223 workspace_unwrap_children(workspace, container);
217 } else { 224 } else {
218 container->width = container->height = 0; 225 container->pending.width = container->pending.height = 0;
219 container->width_fraction = container->height_fraction = 0; 226 container->width_fraction = container->height_fraction = 0;
220 workspace_add_tiling(workspace, container); 227 workspace_add_tiling(workspace, container);
221 } 228 }
@@ -237,13 +244,13 @@ static void container_move_to_container(struct sway_container *container,
237 return; 244 return;
238 } 245 }
239 if (container_is_floating(container)) { 246 if (container_is_floating(container)) {
240 container_move_to_workspace(container, destination->workspace); 247 container_move_to_workspace(container, destination->pending.workspace);
241 return; 248 return;
242 } 249 }
243 struct sway_workspace *old_workspace = container->workspace; 250 struct sway_workspace *old_workspace = container->pending.workspace;
244 251
245 container_detach(container); 252 container_detach(container);
246 container->width = container->height = 0; 253 container->pending.width = container->pending.height = 0;
247 container->width_fraction = container->height_fraction = 0; 254 container->width_fraction = container->height_fraction = 0;
248 255
249 if (destination->view) { 256 if (destination->view) {
@@ -256,12 +263,12 @@ static void container_move_to_container(struct sway_container *container,
256 ipc_event_window(container, "move"); 263 ipc_event_window(container, "move");
257 } 264 }
258 265
259 if (destination->workspace) { 266 if (destination->pending.workspace) {
260 workspace_focus_fullscreen(destination->workspace); 267 workspace_focus_fullscreen(destination->pending.workspace);
261 workspace_detect_urgent(destination->workspace); 268 workspace_detect_urgent(destination->pending.workspace);
262 } 269 }
263 270
264 if (old_workspace && old_workspace != destination->workspace) { 271 if (old_workspace && old_workspace != destination->pending.workspace) {
265 workspace_detect_urgent(old_workspace); 272 workspace_detect_urgent(old_workspace);
266 } 273 }
267} 274}
@@ -275,7 +282,7 @@ static bool container_move_to_next_output(struct sway_container *container,
275 if (!sway_assert(ws, "Expected output to have a workspace")) { 282 if (!sway_assert(ws, "Expected output to have a workspace")) {
276 return false; 283 return false;
277 } 284 }
278 switch (container->fullscreen_mode) { 285 switch (container->pending.fullscreen_mode) {
279 case FULLSCREEN_NONE: 286 case FULLSCREEN_NONE:
280 container_move_to_workspace_from_direction(container, ws, move_dir); 287 container_move_to_workspace_from_direction(container, ws, move_dir);
281 return true; 288 return true;
@@ -293,12 +300,12 @@ static bool container_move_to_next_output(struct sway_container *container,
293static bool container_move_in_direction(struct sway_container *container, 300static bool container_move_in_direction(struct sway_container *container,
294 enum wlr_direction move_dir) { 301 enum wlr_direction move_dir) {
295 // If moving a fullscreen view, only consider outputs 302 // If moving a fullscreen view, only consider outputs
296 switch (container->fullscreen_mode) { 303 switch (container->pending.fullscreen_mode) {
297 case FULLSCREEN_NONE: 304 case FULLSCREEN_NONE:
298 break; 305 break;
299 case FULLSCREEN_WORKSPACE: 306 case FULLSCREEN_WORKSPACE:
300 return container_move_to_next_output(container, 307 return container_move_to_next_output(container,
301 container->workspace->output, move_dir); 308 container->pending.workspace->output, move_dir);
302 case FULLSCREEN_GLOBAL: 309 case FULLSCREEN_GLOBAL:
303 return false; 310 return false;
304 } 311 }
@@ -317,26 +324,26 @@ static bool container_move_in_direction(struct sway_container *container,
317 while (!ancestor) { 324 while (!ancestor) {
318 // Don't allow containers to move out of their 325 // Don't allow containers to move out of their
319 // fullscreen or floating parent 326 // fullscreen or floating parent
320 if (current->fullscreen_mode || container_is_floating(current)) { 327 if (current->pending.fullscreen_mode || container_is_floating(current)) {
321 return false; 328 return false;
322 } 329 }
323 330
324 enum sway_container_layout parent_layout = container_parent_layout(current); 331 enum sway_container_layout parent_layout = container_parent_layout(current);
325 if (!is_parallel(parent_layout, move_dir)) { 332 if (!is_parallel(parent_layout, move_dir)) {
326 if (!current->parent) { 333 if (!current->pending.parent) {
327 // No parallel parent, so we reorient the workspace 334 // No parallel parent, so we reorient the workspace
328 current = workspace_wrap_children(current->workspace); 335 current = workspace_wrap_children(current->pending.workspace);
329 current->workspace->layout = 336 current->pending.workspace->layout =
330 move_dir == WLR_DIRECTION_LEFT || 337 move_dir == WLR_DIRECTION_LEFT ||
331 move_dir == WLR_DIRECTION_RIGHT ? 338 move_dir == WLR_DIRECTION_RIGHT ?
332 L_HORIZ : L_VERT; 339 L_HORIZ : L_VERT;
333 container->height = container->width = 0; 340 container->pending.height = container->pending.width = 0;
334 container->height_fraction = container->width_fraction = 0; 341 container->height_fraction = container->width_fraction = 0;
335 workspace_update_representation(current->workspace); 342 workspace_update_representation(current->pending.workspace);
336 wrapped = true; 343 wrapped = true;
337 } else { 344 } else {
338 // Keep looking for a parallel parent 345 // Keep looking for a parallel parent
339 current = current->parent; 346 current = current->pending.parent;
340 } 347 }
341 continue; 348 continue;
342 } 349 }
@@ -356,14 +363,14 @@ static bool container_move_in_direction(struct sway_container *container,
356 container_move_to_container_from_direction(container, 363 container_move_to_container_from_direction(container,
357 target, move_dir); 364 target, move_dir);
358 return true; 365 return true;
359 } else if (!container->parent) { 366 } else if (!container->pending.parent) {
360 // Container is at workspace level so we move it to the 367 // Container is at workspace level so we move it to the
361 // next workspace if possible 368 // next workspace if possible
362 return container_move_to_next_output(container, 369 return container_move_to_next_output(container,
363 current->workspace->output, move_dir); 370 current->pending.workspace->output, move_dir);
364 } else { 371 } else {
365 // Container has escaped its immediate parallel parent 372 // Container has escaped its immediate parallel parent
366 current = current->parent; 373 current = current->pending.parent;
367 continue; 374 continue;
368 } 375 }
369 } 376 }
@@ -377,31 +384,31 @@ static bool container_move_in_direction(struct sway_container *container,
377 container_move_to_container_from_direction(container, 384 container_move_to_container_from_direction(container,
378 target, move_dir); 385 target, move_dir);
379 return true; 386 return true;
380 } else if (!wrapped && !container->parent->parent && 387 } else if (!wrapped && !container->pending.parent->pending.parent &&
381 container->parent->children->length == 1) { 388 container->pending.parent->pending.children->length == 1) {
382 // Treat singleton children as if they are at workspace level like i3 389 // Treat singleton children as if they are at workspace level like i3
383 // https://github.com/i3/i3/blob/1d9160f2d247dbaa83fb62f02fd7041dec767fc2/src/move.c#L367 390 // https://github.com/i3/i3/blob/1d9160f2d247dbaa83fb62f02fd7041dec767fc2/src/move.c#L367
384 return container_move_to_next_output(container, 391 return container_move_to_next_output(container,
385 ancestor->workspace->output, move_dir); 392 ancestor->pending.workspace->output, move_dir);
386 } else { 393 } else {
387 // Container will be promoted 394 // Container will be promoted
388 struct sway_container *old_parent = container->parent; 395 struct sway_container *old_parent = container->pending.parent;
389 if (ancestor->parent) { 396 if (ancestor->pending.parent) {
390 // Container will move in with its parent 397 // Container will move in with its parent
391 container_insert_child(ancestor->parent, container, 398 container_insert_child(ancestor->pending.parent, container,
392 index + (offs < 0 ? 0 : 1)); 399 index + (offs < 0 ? 0 : 1));
393 } else { 400 } else {
394 // Container will move to workspace level, 401 // Container will move to workspace level,
395 // may be re-split by workspace_layout 402 // may be re-split by workspace_layout
396 workspace_insert_tiling(ancestor->workspace, container, 403 workspace_insert_tiling(ancestor->pending.workspace, container,
397 index + (offs < 0 ? 0 : 1)); 404 index + (offs < 0 ? 0 : 1));
398 } 405 }
399 ancestor->height = ancestor->width = 0; 406 ancestor->pending.height = ancestor->pending.width = 0;
400 ancestor->height_fraction = ancestor->width_fraction = 0; 407 ancestor->height_fraction = ancestor->width_fraction = 0;
401 if (old_parent) { 408 if (old_parent) {
402 container_reap_empty(old_parent); 409 container_reap_empty(old_parent);
403 } 410 }
404 workspace_squash(container->workspace); 411 workspace_squash(container->pending.workspace);
405 return true; 412 return true;
406 } 413 }
407} 414}
@@ -427,14 +434,14 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
427 container = workspace_wrap_children(workspace); 434 container = workspace_wrap_children(workspace);
428 } 435 }
429 436
430 if (container->fullscreen_mode == FULLSCREEN_GLOBAL) { 437 if (container->pending.fullscreen_mode == FULLSCREEN_GLOBAL) {
431 return cmd_results_new(CMD_FAILURE, 438 return cmd_results_new(CMD_FAILURE,
432 "Can't move fullscreen global container"); 439 "Can't move fullscreen global container");
433 } 440 }
434 441
435 struct sway_seat *seat = config->handler_context.seat; 442 struct sway_seat *seat = config->handler_context.seat;
436 struct sway_container *old_parent = container->parent; 443 struct sway_container *old_parent = container->pending.parent;
437 struct sway_workspace *old_ws = container->workspace; 444 struct sway_workspace *old_ws = container->pending.workspace;
438 struct sway_output *old_output = old_ws ? old_ws->output : NULL; 445 struct sway_output *old_output = old_ws ? old_ws->output : NULL;
439 struct sway_node *destination = NULL; 446 struct sway_node *destination = NULL;
440 447
@@ -462,7 +469,7 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
462 if (strcasecmp(argv[1], "number") == 0) { 469 if (strcasecmp(argv[1], "number") == 0) {
463 // move [window|container] [to] "workspace number x" 470 // move [window|container] [to] "workspace number x"
464 if (argc < 3) { 471 if (argc < 3) {
465 return cmd_results_new(CMD_INVALID, expected_syntax); 472 return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
466 } 473 }
467 if (!isdigit(argv[2][0])) { 474 if (!isdigit(argv[2][0])) {
468 return cmd_results_new(CMD_INVALID, 475 return cmd_results_new(CMD_INVALID,
@@ -508,7 +515,7 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
508 destination = dst ? &dst->node : &ws->node; 515 destination = dst ? &dst->node : &ws->node;
509 } else if (strcasecmp(argv[0], "output") == 0) { 516 } else if (strcasecmp(argv[0], "output") == 0) {
510 struct sway_output *new_output = output_in_direction(argv[1], 517 struct sway_output *new_output = output_in_direction(argv[1],
511 old_output, container->x, container->y); 518 old_output, container->pending.x, container->pending.y);
512 if (!new_output) { 519 if (!new_output) {
513 return cmd_results_new(CMD_FAILURE, 520 return cmd_results_new(CMD_FAILURE,
514 "Can't find output with name/direction '%s'", argv[1]); 521 "Can't find output with name/direction '%s'", argv[1]);
@@ -522,7 +529,7 @@ static struct cmd_results *cmd_move_container(bool no_auto_back_and_forth,
522 } 529 }
523 destination = &dest_con->node; 530 destination = &dest_con->node;
524 } else { 531 } else {
525 return cmd_results_new(CMD_INVALID, expected_syntax); 532 return cmd_results_new(CMD_INVALID, "%s", expected_syntax);
526 } 533 }
527 534
528 if (destination->type == N_CONTAINER && 535 if (destination->type == N_CONTAINER &&
@@ -686,6 +693,9 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
686 arrange_output(old_output); 693 arrange_output(old_output);
687 arrange_output(new_output); 694 arrange_output(new_output);
688 695
696 struct sway_seat *seat = config->handler_context.seat;
697 seat_consider_warp_to_focus(seat);
698
689 return cmd_results_new(CMD_SUCCESS, NULL); 699 return cmd_results_new(CMD_SUCCESS, NULL);
690} 700}
691 701
@@ -706,12 +716,12 @@ static struct cmd_results *cmd_move_in_direction(
706 "Cannot move workspaces in a direction"); 716 "Cannot move workspaces in a direction");
707 } 717 }
708 if (container_is_floating(container)) { 718 if (container_is_floating(container)) {
709 if (container->fullscreen_mode) { 719 if (container->pending.fullscreen_mode) {
710 return cmd_results_new(CMD_FAILURE, 720 return cmd_results_new(CMD_FAILURE,
711 "Cannot move fullscreen floating container"); 721 "Cannot move fullscreen floating container");
712 } 722 }
713 double lx = container->x; 723 double lx = container->pending.x;
714 double ly = container->y; 724 double ly = container->pending.y;
715 switch (direction) { 725 switch (direction) {
716 case WLR_DIRECTION_LEFT: 726 case WLR_DIRECTION_LEFT:
717 lx -= move_amt; 727 lx -= move_amt;
@@ -729,8 +739,8 @@ static struct cmd_results *cmd_move_in_direction(
729 container_floating_move_to(container, lx, ly); 739 container_floating_move_to(container, lx, ly);
730 return cmd_results_new(CMD_SUCCESS, NULL); 740 return cmd_results_new(CMD_SUCCESS, NULL);
731 } 741 }
732 struct sway_workspace *old_ws = container->workspace; 742 struct sway_workspace *old_ws = container->pending.workspace;
733 struct sway_container *old_parent = container->parent; 743 struct sway_container *old_parent = container->pending.parent;
734 744
735 if (!container_move_in_direction(container, direction)) { 745 if (!container_move_in_direction(container, direction)) {
736 // Container didn't move 746 // Container didn't move
@@ -744,7 +754,7 @@ static struct cmd_results *cmd_move_in_direction(
744 workspace_consider_destroy(old_ws); 754 workspace_consider_destroy(old_ws);
745 } 755 }
746 756
747 struct sway_workspace *new_ws = container->workspace; 757 struct sway_workspace *new_ws = container->pending.workspace;
748 758
749 if (root->fullscreen_global) { 759 if (root->fullscreen_global) {
750 arrange_root(); 760 arrange_root();
@@ -759,15 +769,6 @@ static struct cmd_results *cmd_move_in_direction(
759 ipc_event_window(container, "move"); 769 ipc_event_window(container, "move");
760 } 770 }
761 771
762 // Hack to re-focus container
763 seat_set_raw_focus(config->handler_context.seat, &new_ws->node);
764 seat_set_focus_container(config->handler_context.seat, container);
765
766 if (old_ws != new_ws) {
767 ipc_event_workspace(old_ws, new_ws, "focus");
768 workspace_detect_urgent(old_ws);
769 workspace_detect_urgent(new_ws);
770 }
771 container_end_mouse_operation(container); 772 container_end_mouse_operation(container);
772 773
773 return cmd_results_new(CMD_SUCCESS, NULL); 774 return cmd_results_new(CMD_SUCCESS, NULL);
@@ -781,22 +782,22 @@ static struct cmd_results *cmd_move_to_position_pointer(
781 } 782 }
782 struct wlr_cursor *cursor = seat->cursor->cursor; 783 struct wlr_cursor *cursor = seat->cursor->cursor;
783 /* Determine where to put the window. */ 784 /* Determine where to put the window. */
784 double lx = cursor->x - container->width / 2; 785 double lx = cursor->x - container->pending.width / 2;
785 double ly = cursor->y - container->height / 2; 786 double ly = cursor->y - container->pending.height / 2;
786 787
787 /* Correct target coordinates to be in bounds (on screen). */ 788 /* Correct target coordinates to be in bounds (on screen). */
788 struct wlr_output *output = wlr_output_layout_output_at( 789 struct wlr_output *output = wlr_output_layout_output_at(
789 root->output_layout, cursor->x, cursor->y); 790 root->output_layout, cursor->x, cursor->y);
790 if (output) { 791 if (output) {
791 struct wlr_box *box = 792 struct wlr_box box;
792 wlr_output_layout_get_box(root->output_layout, output); 793 wlr_output_layout_get_box(root->output_layout, output, &box);
793 lx = fmax(lx, box->x); 794 lx = fmax(lx, box.x);
794 ly = fmax(ly, box->y); 795 ly = fmax(ly, box.y);
795 if (lx + container->width > box->x + box->width) { 796 if (lx + container->pending.width > box.x + box.width) {
796 lx = box->x + box->width - container->width; 797 lx = box.x + box.width - container->pending.width;
797 } 798 }
798 if (ly + container->height > box->y + box->height) { 799 if (ly + container->pending.height > box.y + box.height) {
799 ly = box->y + box->height - container->height; 800 ly = box.y + box.height - container->pending.height;
800 } 801 }
801 } 802 }
802 803
@@ -818,7 +819,7 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
818 } 819 }
819 820
820 if (!argc) { 821 if (!argc) {
821 return cmd_results_new(CMD_INVALID, expected_position_syntax); 822 return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
822 } 823 }
823 824
824 bool absolute = false; 825 bool absolute = false;
@@ -828,41 +829,41 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
828 ++argv; 829 ++argv;
829 } 830 }
830 if (!argc) { 831 if (!argc) {
831 return cmd_results_new(CMD_INVALID, expected_position_syntax); 832 return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
832 } 833 }
833 if (strcmp(argv[0], "position") == 0) { 834 if (strcmp(argv[0], "position") == 0) {
834 --argc; 835 --argc;
835 ++argv; 836 ++argv;
836 } 837 }
837 if (!argc) { 838 if (!argc) {
838 return cmd_results_new(CMD_INVALID, expected_position_syntax); 839 return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
839 } 840 }
840 if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 || 841 if (strcmp(argv[0], "cursor") == 0 || strcmp(argv[0], "mouse") == 0 ||
841 strcmp(argv[0], "pointer") == 0) { 842 strcmp(argv[0], "pointer") == 0) {
842 if (absolute) { 843 if (absolute) {
843 return cmd_results_new(CMD_INVALID, expected_position_syntax); 844 return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
844 } 845 }
845 return cmd_move_to_position_pointer(container); 846 return cmd_move_to_position_pointer(container);
846 } else if (strcmp(argv[0], "center") == 0) { 847 } else if (strcmp(argv[0], "center") == 0) {
847 double lx, ly; 848 double lx, ly;
848 if (absolute) { 849 if (absolute) {
849 lx = root->x + (root->width - container->width) / 2; 850 lx = root->x + (root->width - container->pending.width) / 2;
850 ly = root->y + (root->height - container->height) / 2; 851 ly = root->y + (root->height - container->pending.height) / 2;
851 } else { 852 } else {
852 struct sway_workspace *ws = container->workspace; 853 struct sway_workspace *ws = container->pending.workspace;
853 if (!ws) { 854 if (!ws) {
854 struct sway_seat *seat = config->handler_context.seat; 855 struct sway_seat *seat = config->handler_context.seat;
855 ws = seat_get_focused_workspace(seat); 856 ws = seat_get_focused_workspace(seat);
856 } 857 }
857 lx = ws->x + (ws->width - container->width) / 2; 858 lx = ws->x + (ws->width - container->pending.width) / 2;
858 ly = ws->y + (ws->height - container->height) / 2; 859 ly = ws->y + (ws->height - container->pending.height) / 2;
859 } 860 }
860 container_floating_move_to(container, lx, ly); 861 container_floating_move_to(container, lx, ly);
861 return cmd_results_new(CMD_SUCCESS, NULL); 862 return cmd_results_new(CMD_SUCCESS, NULL);
862 } 863 }
863 864
864 if (argc < 2) { 865 if (argc < 2) {
865 return cmd_results_new(CMD_FAILURE, expected_position_syntax); 866 return cmd_results_new(CMD_FAILURE, "%s", expected_position_syntax);
866 } 867 }
867 868
868 struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID }; 869 struct movement_amount lx = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
@@ -874,19 +875,23 @@ static struct cmd_results *cmd_move_to_position(int argc, char **argv) {
874 return cmd_results_new(CMD_INVALID, "Invalid x position specified"); 875 return cmd_results_new(CMD_INVALID, "Invalid x position specified");
875 } 876 }
876 877
878 if (argc < 1) {
879 return cmd_results_new(CMD_FAILURE, "%s", expected_position_syntax);
880 }
881
877 struct movement_amount ly = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID }; 882 struct movement_amount ly = { .amount = 0, .unit = MOVEMENT_UNIT_INVALID };
878 // Y direction 883 // Y direction
879 num_consumed_args = parse_movement_amount(argc, argv, &ly); 884 num_consumed_args = parse_movement_amount(argc, argv, &ly);
880 argc -= num_consumed_args; 885 argc -= num_consumed_args;
881 argv += num_consumed_args; 886 argv += num_consumed_args;
882 if (argc > 0) { 887 if (argc > 0) {
883 return cmd_results_new(CMD_INVALID, expected_position_syntax); 888 return cmd_results_new(CMD_INVALID, "%s", expected_position_syntax);
884 } 889 }
885 if (ly.unit == MOVEMENT_UNIT_INVALID) { 890 if (ly.unit == MOVEMENT_UNIT_INVALID) {
886 return cmd_results_new(CMD_INVALID, "Invalid y position specified"); 891 return cmd_results_new(CMD_INVALID, "Invalid y position specified");
887 } 892 }
888 893
889 struct sway_workspace *ws = container->workspace; 894 struct sway_workspace *ws = container->pending.workspace;
890 if (!ws) { 895 if (!ws) {
891 struct sway_seat *seat = config->handler_context.seat; 896 struct sway_seat *seat = config->handler_context.seat;
892 ws = seat_get_focused_workspace(seat); 897 ws = seat_get_focused_workspace(seat);
@@ -960,14 +965,14 @@ static struct cmd_results *cmd_move_to_scratchpad(void) {
960 // If the container is in a floating split container, 965 // If the container is in a floating split container,
961 // operate on the split container instead of the child. 966 // operate on the split container instead of the child.
962 if (container_is_floating_or_child(con)) { 967 if (container_is_floating_or_child(con)) {
963 while (con->parent) { 968 while (con->pending.parent) {
964 con = con->parent; 969 con = con->pending.parent;
965 } 970 }
966 } 971 }
967 972
968 if (!con->scratchpad) { 973 if (!con->scratchpad) {
969 root_scratchpad_add_container(con, NULL); 974 root_scratchpad_add_container(con, NULL);
970 } else if (con->workspace) { 975 } else if (con->pending.workspace) {
971 root_scratchpad_hide(con); 976 root_scratchpad_hide(con);
972 } 977 }
973 return cmd_results_new(CMD_SUCCESS, NULL); 978 return cmd_results_new(CMD_SUCCESS, NULL);
@@ -1026,13 +1031,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
1026 } 1031 }
1027 1032
1028 if (!argc) { 1033 if (!argc) {
1029 return cmd_results_new(CMD_INVALID, expected_full_syntax); 1034 return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
1030 } 1035 }
1031 1036
1032 // Only `move [window|container] [to] workspace` supports 1037 // Only `move [window|container] [to] workspace` supports
1033 // `--no-auto-back-and-forth` so treat others as invalid syntax 1038 // `--no-auto-back-and-forth` so treat others as invalid syntax
1034 if (no_auto_back_and_forth && strcasecmp(argv[0], "workspace") != 0) { 1039 if (no_auto_back_and_forth && strcasecmp(argv[0], "workspace") != 0) {
1035 return cmd_results_new(CMD_INVALID, expected_full_syntax); 1040 return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
1036 } 1041 }
1037 1042
1038 if (strcasecmp(argv[0], "workspace") == 0 || 1043 if (strcasecmp(argv[0], "workspace") == 0 ||
@@ -1046,5 +1051,5 @@ struct cmd_results *cmd_move(int argc, char **argv) {
1046 strcasecmp(argv[1], "position") == 0)) { 1051 strcasecmp(argv[1], "position") == 0)) {
1047 return cmd_move_to_position(argc, argv); 1052 return cmd_move_to_position(argc, argv);
1048 } 1053 }
1049 return cmd_results_new(CMD_INVALID, expected_full_syntax); 1054 return cmd_results_new(CMD_INVALID, "%s", expected_full_syntax);
1050} 1055}