aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/move.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-05 17:59:31 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-05 18:01:43 +1000
commitdbf4aa3e33bdee53876c6893b15ac3f224818e7c (patch)
treeba4ded7f1c63a9ec620122482cadcf0ad68661fa /sway/commands/move.c
parentFix inversed condition in criteria (diff)
downloadsway-dbf4aa3e33bdee53876c6893b15ac3f224818e7c.tar.gz
sway-dbf4aa3e33bdee53876c6893b15ac3f224818e7c.tar.zst
sway-dbf4aa3e33bdee53876c6893b15ac3f224818e7c.zip
Allow marked containers to be moved out of the scratchpad via move command
Diffstat (limited to 'sway/commands/move.c')
-rw-r--r--sway/commands/move.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index d562b5f1..7b503624 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -41,7 +41,7 @@ enum wlr_direction opposite_direction(enum wlr_direction d) {
41} 41}
42 42
43static struct sway_output *output_in_direction(const char *direction_string, 43static struct sway_output *output_in_direction(const char *direction_string,
44 struct wlr_output *reference, int ref_lx, int ref_ly) { 44 struct sway_output *reference, int ref_lx, int ref_ly) {
45 struct { 45 struct {
46 char *name; 46 char *name;
47 enum wlr_direction direction; 47 enum wlr_direction direction;
@@ -61,14 +61,15 @@ static struct sway_output *output_in_direction(const char *direction_string,
61 } 61 }
62 } 62 }
63 63
64 if (direction) { 64 if (reference && direction) {
65 struct wlr_output *target = wlr_output_layout_adjacent_output( 65 struct wlr_output *target = wlr_output_layout_adjacent_output(
66 root->output_layout, direction, reference, ref_lx, ref_ly); 66 root->output_layout, direction, reference->wlr_output,
67 ref_lx, ref_ly);
67 68
68 if (!target) { 69 if (!target) {
69 target = wlr_output_layout_farthest_output( 70 target = wlr_output_layout_farthest_output(
70 root->output_layout, opposite_direction(direction), 71 root->output_layout, opposite_direction(direction),
71 reference, ref_lx, ref_ly); 72 reference->wlr_output, ref_lx, ref_ly);
72 } 73 }
73 74
74 if (target) { 75 if (target) {
@@ -246,7 +247,7 @@ static void container_move_to_container(struct sway_container *container,
246 247
247 // Update workspace urgent state 248 // Update workspace urgent state
248 workspace_detect_urgent(destination->workspace); 249 workspace_detect_urgent(destination->workspace);
249 if (old_workspace != destination->workspace) { 250 if (old_workspace && old_workspace != destination->workspace) {
250 workspace_detect_urgent(old_workspace); 251 workspace_detect_urgent(old_workspace);
251 } 252 }
252} 253}
@@ -452,7 +453,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
452 struct sway_seat *seat = config->handler_context.seat; 453 struct sway_seat *seat = config->handler_context.seat;
453 struct sway_container *old_parent = container->parent; 454 struct sway_container *old_parent = container->parent;
454 struct sway_workspace *old_ws = container->workspace; 455 struct sway_workspace *old_ws = container->workspace;
455 struct sway_output *old_output = old_ws->output; 456 struct sway_output *old_output = old_ws ? old_ws->output : NULL;
456 struct sway_node *destination = NULL; 457 struct sway_node *destination = NULL;
457 458
458 // determine destination 459 // determine destination
@@ -496,7 +497,8 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
496 if (!no_auto_back_and_forth && config->auto_back_and_forth && 497 if (!no_auto_back_and_forth && config->auto_back_and_forth &&
497 prev_workspace_name) { 498 prev_workspace_name) {
498 // auto back and forth move 499 // auto back and forth move
499 if (old_ws->name && strcmp(old_ws->name, ws_name) == 0) { 500 if (old_ws && old_ws->name &&
501 strcmp(old_ws->name, ws_name) == 0) {
500 // if target workspace is the current one 502 // if target workspace is the current one
501 free(ws_name); 503 free(ws_name);
502 ws_name = strdup(prev_workspace_name); 504 ws_name = strdup(prev_workspace_name);
@@ -524,7 +526,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
524 destination = seat_get_focus_inactive(seat, &ws->node); 526 destination = seat_get_focus_inactive(seat, &ws->node);
525 } else if (strcasecmp(argv[1], "output") == 0) { 527 } else if (strcasecmp(argv[1], "output") == 0) {
526 struct sway_output *new_output = output_in_direction(argv[2], 528 struct sway_output *new_output = output_in_direction(argv[2],
527 old_output->wlr_output, container->x, container->y); 529 old_output, container->x, container->y);
528 if (!new_output) { 530 if (!new_output) {
529 return cmd_results_new(CMD_FAILURE, "move workspace", 531 return cmd_results_new(CMD_FAILURE, "move workspace",
530 "Can't find output with name/direction '%s'", argv[2]); 532 "Can't find output with name/direction '%s'", argv[2]);
@@ -541,7 +543,7 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
541 return cmd_results_new(CMD_INVALID, "move", expected_syntax); 543 return cmd_results_new(CMD_INVALID, "move", expected_syntax);
542 } 544 }
543 545
544 if (container->is_sticky && 546 if (container->is_sticky && old_output &&
545 node_has_ancestor(destination, &old_output->node)) { 547 node_has_ancestor(destination, &old_output->node)) {
546 return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky " 548 return cmd_results_new(CMD_FAILURE, "move", "Can't move sticky "
547 "container to another workspace on the same output"); 549 "container to another workspace on the same output");
@@ -552,6 +554,9 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
552 NULL : output_get_active_workspace(new_output); 554 NULL : output_get_active_workspace(new_output);
553 555
554 // move container, arrange windows and return focus 556 // move container, arrange windows and return focus
557 if (container->scratchpad) {
558 root_scratchpad_remove_container(container);
559 }
555 switch (destination->type) { 560 switch (destination->type) {
556 case N_WORKSPACE: 561 case N_WORKSPACE:
557 container_move_to_workspace(container, destination->sway_workspace); 562 container_move_to_workspace(container, destination->sway_workspace);
@@ -580,18 +585,20 @@ static struct cmd_results *cmd_move_container(int argc, char **argv) {
580 struct sway_node *focus = NULL; 585 struct sway_node *focus = NULL;
581 if (old_parent) { 586 if (old_parent) {
582 focus = seat_get_focus_inactive(seat, &old_parent->node); 587 focus = seat_get_focus_inactive(seat, &old_parent->node);
583 } else { 588 } else if (old_ws) {
584 focus = seat_get_focus_inactive(seat, &old_ws->node); 589 focus = seat_get_focus_inactive(seat, &old_ws->node);
585 } 590 }
586 seat_set_focus_warp(seat, focus, true, false); 591 seat_set_focus_warp(seat, focus, true, false);
587 592
588 if (old_parent) { 593 if (old_parent) {
589 container_reap_empty(old_parent); 594 container_reap_empty(old_parent);
590 } else { 595 } else if (old_ws) {
591 workspace_consider_destroy(old_ws); 596 workspace_consider_destroy(old_ws);
592 } 597 }
593 598
594 arrange_workspace(old_ws); 599 if (old_ws) {
600 arrange_workspace(old_ws);
601 }
595 arrange_node(node_get_parent(destination)); 602 arrange_node(node_get_parent(destination));
596 603
597 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 604 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
@@ -650,7 +657,7 @@ static struct cmd_results *cmd_move_workspace(int argc, char **argv) {
650 int center_x = workspace->width / 2 + workspace->x, 657 int center_x = workspace->width / 2 + workspace->x,
651 center_y = workspace->height / 2 + workspace->y; 658 center_y = workspace->height / 2 + workspace->y;
652 struct sway_output *new_output = output_in_direction(argv[2], 659 struct sway_output *new_output = output_in_direction(argv[2],
653 old_output->wlr_output, center_x, center_y); 660 old_output, center_x, center_y);
654 if (!new_output) { 661 if (!new_output) {
655 return cmd_results_new(CMD_FAILURE, "move workspace", 662 return cmd_results_new(CMD_FAILURE, "move workspace",
656 "Can't find output with name/direction '%s'", argv[2]); 663 "Can't find output with name/direction '%s'", argv[2]);