From 356063b6c084a7c2d4e3e654fe48ec79a102294b Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Wed, 1 Aug 2018 16:03:37 +0100 Subject: commands: fix layout implementation (also better name for previous split layout) --- sway/tree/layout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 07de9664..28cdc71e 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -859,7 +859,7 @@ struct sway_container *container_split(struct sway_container *child, } if (child->type == C_WORKSPACE && child->children->length == 0) { // Special case: this just behaves like splitt - child->prev_layout = child->layout; + child->prev_split_layout = child->layout; child->layout = layout; return child; } @@ -870,7 +870,7 @@ struct sway_container *container_split(struct sway_container *child, remove_gaps(child); - cont->prev_layout = L_NONE; + cont->prev_split_layout = L_NONE; cont->width = child->width; cont->height = child->height; cont->x = child->x; -- cgit v1.2.3 From f57a3919cf5ad7c3edbf9e2e19051971a5f2d42f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Aug 2018 00:03:01 +1000 Subject: Move workspace moving code out of container_move_to container_move_to handled moving containers to new parents, as well as moving workspaces to new outputs. This commit removes the workspace-moving code from this function and introduces workspace_move_to_output. Moving workspaces using container_move_to only happened from the move command, so it's been implemented as a static function in that file. Simplifying container_move_to makes it easier for me to fix some issues in #2420. --- sway/tree/layout.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 07de9664..9485e675 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); -- cgit v1.2.3 From 36281609ea882d4c0a2a10fc9e604eb1ec2e8951 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 4 Aug 2018 14:46:27 +1000 Subject: Implement move to workspace on a floating container Also adjusts container_floating_translate to not change the current properties directly. --- sway/tree/layout.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 20815654..bdcd1a9b 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -151,7 +151,7 @@ void container_move_to(struct sway_container *container, return; } if (container_is_floating(container)) { - // TODO + container_floating_move_to_container(container, destination); return; } struct sway_container *old_parent = container_remove_child(container); -- cgit v1.2.3 From a0649190deaaf093112e99881c25ff550f07e96b Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 7 Aug 2018 09:30:27 +1000 Subject: Fix edge cases when moving floating container to new workspace * Removes container_floating_move_to_container, instead opting to put that logic in container_move_to * In the seat code, focusing a floating view now updates the pending state only and lets the next transaction carry it over to the current state. This is required, otherwise it would crash. * When unfullscreening a floating container, an output check is now done to see if it should center it. --- sway/tree/layout.c | 48 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) (limited to 'sway/tree/layout.c') diff --git a/sway/tree/layout.c b/sway/tree/layout.c index bdcd1a9b..38e14d00 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -150,22 +150,44 @@ void container_move_to(struct sway_container *container, || container_has_ancestor(container, destination)) { return; } + struct sway_container *old_parent = NULL; + struct sway_container *new_parent = NULL; if (container_is_floating(container)) { - container_floating_move_to_container(container, destination); - return; - } - struct sway_container *old_parent = container_remove_child(container); - container->width = container->height = 0; - container->saved_width = container->saved_height = 0; - - struct sway_container *new_parent; - - if (destination->type == C_VIEW) { - new_parent = container_add_sibling(destination, container); + // Resolve destination into a workspace + struct sway_container *new_ws = NULL; + if (destination->type == C_OUTPUT) { + new_ws = output_get_active_workspace(destination->sway_output); + } else if (destination->type == C_WORKSPACE) { + new_ws = destination; + } else { + new_ws = container_parent(destination, C_WORKSPACE); + } + if (!new_ws) { + // This can happen if the user has run "move container to mark foo", + // where mark foo is on a hidden scratchpad container. + return; + } + struct sway_container *old_output = + container_parent(container, C_OUTPUT); + old_parent = container_remove_child(container); + container_add_child(new_ws->sway_workspace->floating, container); + // If changing output, center it within the workspace + if (old_output != new_ws->parent && !container->is_fullscreen) { + container_floating_move_to_center(container); + } } else { - new_parent = destination; - container_add_child(destination, container); + old_parent = container_remove_child(container); + container->width = container->height = 0; + container->saved_width = container->saved_height = 0; + + if (destination->type == C_VIEW) { + new_parent = container_add_sibling(destination, container); + } else { + new_parent = destination; + container_add_child(destination, container); + } } + wl_signal_emit(&container->events.reparent, old_parent); if (container->type == C_VIEW) { -- cgit v1.2.3