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) --- include/sway/tree/container.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/sway/tree/container.h') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 44ff9f7d..16a180f8 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -113,7 +113,7 @@ struct sway_container { enum sway_container_type type; enum sway_container_layout layout; - enum sway_container_layout prev_layout; + enum sway_container_layout prev_split_layout; bool is_sticky; -- 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. --- include/sway/tree/container.h | 8 +++++++ sway/tree/container.c | 51 ++++++++++++++++++++++++++++++++++++++----- sway/tree/layout.c | 2 +- 3 files changed, 54 insertions(+), 7 deletions(-) (limited to 'include/sway/tree/container.h') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 16a180f8..d82db89c 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -328,6 +328,14 @@ void container_floating_translate(struct sway_container *con, void container_floating_move_to(struct sway_container *con, double lx, double ly); +/** + * Move a floating container to the center of the workspace. + */ +void container_floating_move_to_center(struct sway_container *con); + +void container_floating_move_to_container(struct sway_container *container, + struct sway_container *destination); + /** * Mark a container as dirty if it isn't already. Dirty containers will be * included in the next transaction then unmarked as dirty. diff --git a/sway/tree/container.c b/sway/tree/container.c index 6da5ac3c..f31c152f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1163,19 +1163,16 @@ void container_floating_translate(struct sway_container *con, double x_amount, double y_amount) { con->x += x_amount; con->y += y_amount; - con->current.swayc_x += x_amount; - con->current.swayc_y += y_amount; if (con->type == C_VIEW) { con->sway_view->x += x_amount; con->sway_view->y += y_amount; - con->current.view_x += x_amount; - con->current.view_y += y_amount; } else { for (int i = 0; i < con->children->length; ++i) { struct sway_container *child = con->children->items[i]; container_floating_translate(child, x_amount, y_amount); } } + container_set_dirty(con); } /** @@ -1219,9 +1216,7 @@ void container_floating_move_to(struct sway_container *con, "Expected a floating container")) { return; } - desktop_damage_whole_container(con); container_floating_translate(con, lx - con->x, ly - con->y); - desktop_damage_whole_container(con); struct sway_container *old_workspace = container_parent(con, C_WORKSPACE); struct sway_container *new_output = container_floating_find_output(con); if (!sway_assert(new_output, "Unable to find any output")) { @@ -1239,6 +1234,50 @@ void container_floating_move_to(struct sway_container *con, } } +void container_floating_move_to_center(struct sway_container *con) { + if (!sway_assert(container_is_floating(con), + "Expected a floating container")) { + return; + } + struct sway_container *ws = container_parent(con, C_WORKSPACE); + double new_lx = ws->x + (ws->width - con->width) / 2; + double new_ly = ws->y + (ws->height - con->height) / 2; + container_floating_translate(con, new_lx - con->x, new_ly - con->y); +} + +void container_floating_move_to_container(struct sway_container *container, + struct sway_container *destination) { + // 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_ws = container_parent(container, C_WORKSPACE); + if (old_ws != new_ws) { + container_remove_child(container); + container_add_child(new_ws->sway_workspace->floating, container); + arrange_windows(old_ws); + arrange_windows(new_ws); + workspace_detect_urgent(old_ws); + workspace_detect_urgent(new_ws); + } + // If the container's center doesn't overlap the new workspace, center it + // within the workspace. + struct sway_container *output = container_floating_find_output(container); + if (new_ws->parent != output) { + container_floating_move_to_center(container); + } +} + void container_set_dirty(struct sway_container *container) { if (container->dirty) { return; 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. --- include/sway/tree/container.h | 9 +++++--- sway/input/seat.c | 4 ---- sway/tree/container.c | 40 ++++++------------------------------ sway/tree/layout.c | 48 +++++++++++++++++++++++++++++++------------ 4 files changed, 47 insertions(+), 54 deletions(-) (limited to 'include/sway/tree/container.h') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index d82db89c..4d0e6003 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -322,6 +322,12 @@ void container_get_box(struct sway_container *container, struct wlr_box *box); void container_floating_translate(struct sway_container *con, double x_amount, double y_amount); +/** + * Choose an output for the floating container's new position. + */ +struct sway_container *container_floating_find_output( + struct sway_container *con); + /** * Move a floating container to a new layout-local position. */ @@ -333,9 +339,6 @@ void container_floating_move_to(struct sway_container *con, */ void container_floating_move_to_center(struct sway_container *con); -void container_floating_move_to_container(struct sway_container *container, - struct sway_container *destination); - /** * Mark a container as dirty if it isn't already. Dirty containers will be * included in the next transaction then unmarked as dirty. diff --git a/sway/input/seat.c b/sway/input/seat.c index dd4d5c3b..6dd7cf7d 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -717,12 +717,8 @@ void seat_set_focus_warp(struct sway_seat *seat, // If we've focused a floating container, bring it to the front. // We do this by putting it at the end of the floating list. - // This must happen for both the pending and current children lists. if (container && container_is_floating(container)) { list_move_to_end(container->parent->children, container); - if (container_has_ancestor(container, container->current.parent)) { - list_move_to_end(container->parent->current.children, container); - } } // clean up unfocused empty workspace on new output diff --git a/sway/tree/container.c b/sway/tree/container.c index f31c152f..4507655e 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1182,7 +1182,7 @@ void container_floating_translate(struct sway_container *con, * one, otherwise we'll choose whichever output is closest to the container's * center. */ -static struct sway_container *container_floating_find_output( +struct sway_container *container_floating_find_output( struct sway_container *con) { double center_x = con->x + con->width / 2; double center_y = con->y + con->height / 2; @@ -1245,39 +1245,6 @@ void container_floating_move_to_center(struct sway_container *con) { container_floating_translate(con, new_lx - con->x, new_ly - con->y); } -void container_floating_move_to_container(struct sway_container *container, - struct sway_container *destination) { - // 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_ws = container_parent(container, C_WORKSPACE); - if (old_ws != new_ws) { - container_remove_child(container); - container_add_child(new_ws->sway_workspace->floating, container); - arrange_windows(old_ws); - arrange_windows(new_ws); - workspace_detect_urgent(old_ws); - workspace_detect_urgent(new_ws); - } - // If the container's center doesn't overlap the new workspace, center it - // within the workspace. - struct sway_container *output = container_floating_find_output(container); - if (new_ws->parent != output) { - container_floating_move_to_center(container); - } -} - void container_set_dirty(struct sway_container *container) { if (container->dirty) { return; @@ -1357,6 +1324,11 @@ void container_set_fullscreen(struct sway_container *container, bool enable) { container->y = container->saved_y; container->width = container->saved_width; container->height = container->saved_height; + struct sway_container *output = + container_floating_find_output(container); + if (!container_has_ancestor(container, output)) { + container_floating_move_to_center(container); + } } else { container->width = container->saved_width; container->height = container->saved_height; 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