aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorBrian Ashworth <RedSoxFan@users.noreply.github.com>2018-08-06 11:55:08 -0400
committerGitHub <noreply@github.com>2018-08-06 11:55:08 -0400
commit17f557298e3578323a7eeb1685ca923f7d638abc (patch)
tree67dfb7bc19eb3dd27252d8b0f493436250b4fdea /sway
parentd8b65193c493e5826383a08593395a598ce4b503 (diff)
parent639f3368e101b697aaf3715b1213ea30766ff4ed (diff)
Merge pull request #2428 from RyanDwyer/workspace-move-to-output
Move workspace moving code out of container_move_to
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/move.c44
-rw-r--r--sway/tree/layout.c28
2 files changed, 49 insertions, 23 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index af3dc538..bb4a7124 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -9,6 +9,7 @@
#include "sway/commands.h"
#include "sway/input/cursor.h"
#include "sway/input/seat.h"
+#include "sway/ipc-server.h"
#include "sway/output.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
@@ -16,6 +17,7 @@
#include "sway/tree/workspace.h"
#include "stringop.h"
#include "list.h"
+#include "log.h"
static const char *expected_syntax =
"Expected 'move <left|right|up|down> <[px] px>' or "
@@ -189,6 +191,46 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
+static void workspace_move_to_output(struct sway_container *workspace,
+ struct sway_container *output) {
+ if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
+ return;
+ }
+ if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
+ return;
+ }
+ if (workspace->parent == output) {
+ return;
+ }
+ struct sway_container *old_output = container_remove_child(workspace);
+ struct sway_seat *seat = input_manager_get_default_seat(input_manager);
+ struct sway_container *new_output_focus =
+ seat_get_focus_inactive(seat, output);
+
+ container_add_child(output, workspace);
+ wl_signal_emit(&workspace->events.reparent, old_output);
+
+ // If moving the last workspace from the old output, create a new workspace
+ // on the old output
+ if (old_output->children->length == 0) {
+ char *ws_name = workspace_next_name(old_output->name);
+ struct sway_container *ws = workspace_create(old_output, ws_name);
+ free(ws_name);
+ seat_set_focus(seat, ws);
+ }
+
+ // Try to remove an empty workspace from the destination output.
+ container_reap_empty_recursive(new_output_focus);
+
+ container_sort_workspaces(output);
+ seat_set_focus(seat, output);
+ workspace_output_raise_priority(workspace, old_output, output);
+ ipc_event_workspace(NULL, workspace, "move");
+
+ container_notify_subtree_changed(old_output);
+ container_notify_subtree_changed(output);
+}
+
static struct cmd_results *cmd_move_workspace(struct sway_container *current,
int argc, char **argv) {
struct cmd_results *error = NULL;
@@ -219,7 +261,7 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current,
if (current->type != C_WORKSPACE) {
current = container_parent(current, C_WORKSPACE);
}
- container_move_to(current, destination);
+ workspace_move_to_output(current, destination);
arrange_windows(source);
arrange_windows(destination);
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 28cdc71e..20815654 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -142,6 +142,10 @@ struct sway_container *container_remove_child(struct sway_container *child) {
void container_move_to(struct sway_container *container,
struct sway_container *destination) {
+ if (!sway_assert(container->type == C_CONTAINER ||
+ container->type == C_VIEW, "Expected a container or view")) {
+ return;
+ }
if (container == destination
|| container_has_ancestor(container, destination)) {
return;
@@ -154,11 +158,8 @@ void container_move_to(struct sway_container *container,
container->width = container->height = 0;
container->saved_width = container->saved_height = 0;
- struct sway_container *new_parent, *new_parent_focus;
- struct sway_seat *seat = input_manager_get_default_seat(input_manager);
+ struct sway_container *new_parent;
- // Get the focus of the destination before we change it.
- new_parent_focus = seat_get_focus_inactive(seat, destination);
if (destination->type == C_VIEW) {
new_parent = container_add_sibling(destination, container);
} else {
@@ -167,24 +168,7 @@ void container_move_to(struct sway_container *container,
}
wl_signal_emit(&container->events.reparent, old_parent);
- if (container->type == C_WORKSPACE) {
- // If moving a workspace to a new output, maybe create a new workspace
- // on the previous output
- if (old_parent->children->length == 0) {
- char *ws_name = workspace_next_name(old_parent->name);
- struct sway_container *ws = workspace_create(old_parent, ws_name);
- free(ws_name);
- seat_set_focus(seat, ws);
- }
-
- // Try to remove an empty workspace from the destination output.
- container_reap_empty_recursive(new_parent_focus);
-
- container_sort_workspaces(new_parent);
- seat_set_focus(seat, new_parent);
- workspace_output_raise_priority(container, old_parent, new_parent);
- ipc_event_workspace(NULL, container, "move");
- } else if (container->type == C_VIEW) {
+ if (container->type == C_VIEW) {
ipc_event_window(container, "move");
}
container_notify_subtree_changed(old_parent);