From 9c8394022edff666f670279f6a14e86fb8321733 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Sun, 25 Oct 2015 00:38:33 +0200 Subject: [PATCH 1/2] commands: Learn 'move to output '. --- sway.5.txt | 4 ++++ sway/commands.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/sway.5.txt b/sway.5.txt index 27735db6..87bd0c05 100644 --- a/sway.5.txt +++ b/sway.5.txt @@ -102,6 +102,10 @@ Commands Moves the focused container to the workspace identified by _name_. _name_ may be a special workspace name. See **workspace**. +**move** to output :: + Moves the focused container to the output identified by _name_ or _direction_. + _direction_ may be one of _up_, _down_, _left_, _right_. + **mouse_warping** :: When _output_: place mouse at center of newly focused window when changing output. When _none_: don't move mouse. diff --git a/sway/commands.c b/sway/commands.c index 00a4d1b0..7f4fef09 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -555,7 +555,8 @@ static struct cmd_results *cmd_move(int argc, char **argv) { return error; } const char* expected_syntax = "Expected 'move ' or " - "'move to workspace '"; + "'move to workspace ' or " + "'move to output '"; swayc_t *view = get_focused_container(&root_container); if (strcasecmp(argv[0], "left") == 0) { @@ -587,6 +588,22 @@ static struct cmd_results *cmd_move(int argc, char **argv) { ws = workspace_create(ws_name); } move_container_to(view, get_focused_container(ws)); + } else if (strcasecmp(argv[1], "to") == 0 && strcasecmp(argv[2], "output") == 0) { + // move container to output x + swayc_t *output = NULL; + if (view->type != C_CONTAINER && view->type != C_VIEW) { + return cmd_results_new(CMD_FAILURE, "move", "Can only move containers and views."); + } else if (!(output = output_by_name(argv[3]))) { + return cmd_results_new(CMD_FAILURE, "move", + "Can't find output with name/direction '%s'", argv[3]); + } else { + swayc_t *container = get_focused_container(output); + if (container->is_floating) { + move_container_to(view, container->parent); + } else { + move_container_to(view, container); + } + } } else { return cmd_results_new(CMD_INVALID, "move", expected_syntax); } From af31a3f04a808a526cbf210bc7762daef66a2f40 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Sun, 25 Oct 2015 00:38:33 +0200 Subject: [PATCH 2/2] commands: Learn 'move workspace to output '. --- include/layout.h | 1 + sway.5.txt | 6 +++--- sway/commands.c | 21 ++++++++++++++++++++- sway/layout.c | 24 ++++++++++++++++++++++++ 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); void move_container(swayc_t* container, enum movement_direction direction); void move_container_to(swayc_t* container, swayc_t* destination); +void move_workspace_to(swayc_t* workspace, swayc_t* destination); // Layout void 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 Moves the focused container to the workspace identified by _name_. _name_ may be a special workspace name. See **workspace**. -**move** to output :: - Moves the focused container to the output identified by _name_ or _direction_. - _direction_ may be one of _up_, _down_, _left_, _right_. +**move** to output :: + Moves the focused container or workspace to the output identified by _name_ or + _direction_. _direction_ may be one of _up_, _down_, _left_, _right_. **mouse_warping** :: 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) { } const char* expected_syntax = "Expected 'move ' or " "'move to workspace ' or " - "'move to output '"; + "'move to output '"; swayc_t *view = get_focused_container(&root_container); if (strcasecmp(argv[0], "left") == 0) { @@ -607,6 +607,25 @@ static struct cmd_results *cmd_move(int argc, char **argv) { } else { return cmd_results_new(CMD_INVALID, "move", expected_syntax); } + } else if (strcasecmp(argv[0], "workspace") == 0) { + // move workspace (to output x) + swayc_t *output = NULL; + if ((error = checkarg(argc, "move workspace", EXPECTED_EQUAL_TO, 4))) { + return error; + } else if (strcasecmp(argv[1], "to") != 0 || strcasecmp(argv[2], "output") != 0) { + return cmd_results_new(CMD_INVALID, "move", expected_syntax); + } else if (!(output = output_by_name(argv[3]))) { + return cmd_results_new(CMD_FAILURE, "move workspace", + "Can't find output with name/at direction '%s'", argv[3]); + } + if (view->type == C_WORKSPACE) { + // This probably means we're moving an empty workspace, but + // that's fine. + move_workspace_to(view, output); + } else { + swayc_t *workspace = swayc_parent_by_type(view, C_WORKSPACE); + move_workspace_to(workspace, output); + } } else if (strcasecmp(argv[0], "scratchpad") == 0) { // move scratchpad ... 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) { } } +void move_workspace_to(swayc_t* workspace, swayc_t* destination) { + if (workspace == destination || swayc_is_parent_of(workspace, destination)) { + return; + } + swayc_t *src_op = remove_child(workspace); + // reset container geometry + workspace->width = workspace->height = 0; + add_child(destination, workspace); + // Refocus destination (change to new workspace) + set_focused_container(get_focused_view(workspace)); + arrange_windows(destination, -1, -1); + update_visibility(destination); + + // make sure source output has a workspace + if (src_op->children->length == 0) { + char *ws_name = workspace_next_name(); + swayc_t *ws = new_workspace(src_op, ws_name); + ws->is_focused = true; + free(ws_name); + } + set_focused_container(get_focused_view(src_op)); + update_visibility(src_op); +} + void update_geometry(swayc_t *container) { if (container->type != C_VIEW) { return;