summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/layout.h1
-rw-r--r--sway.5.txt6
-rw-r--r--sway/commands.c21
-rw-r--r--sway/layout.c24
4 files changed, 48 insertions, 4 deletions
diff --git a/include/layout.h b/include/layout.h
index cb38a7b1..a3cf006a 100644
--- a/include/layout.h
+++ b/include/layout.h
@@ -47,6 +47,7 @@ void swap_geometry(swayc_t *a, swayc_t *b);
47 47
48void move_container(swayc_t* container, enum movement_direction direction); 48void move_container(swayc_t* container, enum movement_direction direction);
49void move_container_to(swayc_t* container, swayc_t* destination); 49void move_container_to(swayc_t* container, swayc_t* destination);
50void move_workspace_to(swayc_t* workspace, swayc_t* destination);
50 51
51// Layout 52// Layout
52void update_geometry(swayc_t *view); 53void update_geometry(swayc_t *view);
diff --git a/sway.5.txt b/sway.5.txt
index 87bd0c05..30b57d4a 100644
--- a/sway.5.txt
+++ b/sway.5.txt
@@ -102,9 +102,9 @@ Commands
102 Moves the focused container to the workspace identified by _name_. 102 Moves the focused container to the workspace identified by _name_.
103 _name_ may be a special workspace name. See **workspace**. 103 _name_ may be a special workspace name. See **workspace**.
104 104
105**move** <container|window> to output <name|direction>:: 105**move** <container|window|workspace> to output <name|direction>::
106 Moves the focused container to the output identified by _name_ or _direction_. 106 Moves the focused container or workspace to the output identified by _name_ or
107 _direction_ may be one of _up_, _down_, _left_, _right_. 107 _direction_. _direction_ may be one of _up_, _down_, _left_, _right_.
108 108
109**mouse_warping** <output|none>:: 109**mouse_warping** <output|none>::
110 When _output_: place mouse at center of newly focused window when changing 110 When _output_: place mouse at center of newly focused window when changing
diff --git a/sway/commands.c b/sway/commands.c
index 7f4fef09..43166a1c 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -556,7 +556,7 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
556 } 556 }
557 const char* expected_syntax = "Expected 'move <left|right|up|down>' or " 557 const char* expected_syntax = "Expected 'move <left|right|up|down>' or "
558 "'move <container|window> to workspace <name>' or " 558 "'move <container|window> to workspace <name>' or "
559 "'move <container|window> to output <name|direction>'"; 559 "'move <container|window|workspace> to output <name|direction>'";
560 swayc_t *view = get_focused_container(&root_container); 560 swayc_t *view = get_focused_container(&root_container);
561 561
562 if (strcasecmp(argv[0], "left") == 0) { 562 if (strcasecmp(argv[0], "left") == 0) {
@@ -607,6 +607,25 @@ static struct cmd_results *cmd_move(int argc, char **argv) {
607 } else { 607 } else {
608 return cmd_results_new(CMD_INVALID, "move", expected_syntax); 608 return cmd_results_new(CMD_INVALID, "move", expected_syntax);
609 } 609 }
610 } else if (strcasecmp(argv[0], "workspace") == 0) {
611 // move workspace (to output x)
612 swayc_t *output = NULL;
613 if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) {
614 return error;
615 } else if (strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "output") != 0) {
616 return cmd_results_new(CMD_INVALID, "move", expected_syntax);
617 } else if (!(output = output_by_name(argv[3]))) {
618 return cmd_results_new(CMD_FAILURE, "move workspace",
619 "Can't find output with name/at direction '%s'", argv[3]);
620 }
621 if (view->type == C_WORKSPACE) {
622 // This probably means we're moving an empty workspace, but
623 // that's fine.
624 move_workspace_to(view, output);
625 } else {
626 swayc_t *workspace = swayc_parent_by_type(view, C_WORKSPACE);
627 move_workspace_to(workspace, output);
628 }
610 } else if (strcasecmp(argv[0], "scratchpad") == 0) { 629 } else if (strcasecmp(argv[0], "scratchpad") == 0) {
611 // move scratchpad ... 630 // move scratchpad ...
612 if (view->type != C_CONTAINER && view->type != C_VIEW) { 631 if (view->type != C_CONTAINER && view->type != C_VIEW) {
diff --git a/sway/layout.c b/sway/layout.c
index cb4d6937..c6a05107 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -317,6 +317,30 @@ void move_container_to(swayc_t* container, swayc_t* destination) {
317 } 317 }
318} 318}
319 319
320void move_workspace_to(swayc_t* workspace, swayc_t* destination) {
321 if (workspace == destination || swayc_is_parent_of(workspace, destination)) {
322 return;
323 }
324 swayc_t *src_op = remove_child(workspace);
325 // reset container geometry
326 workspace->width = workspace->height = 0;
327 add_child(destination, workspace);
328 // Refocus destination (change to new workspace)
329 set_focused_container(get_focused_view(workspace));
330 arrange_windows(destination, -1, -1);
331 update_visibility(destination);
332
333 // make sure source output has a workspace
334 if (src_op->children->length == 0) {
335 char *ws_name = workspace_next_name();
336 swayc_t *ws = new_workspace(src_op, ws_name);
337 ws->is_focused = true;
338 free(ws_name);
339 }
340 set_focused_container(get_focused_view(src_op));
341 update_visibility(src_op);
342}
343
320void update_geometry(swayc_t *container) { 344void update_geometry(swayc_t *container) {
321 if (container->type != C_VIEW) { 345 if (container->type != C_VIEW) {
322 return; 346 return;