From ece6a1d408456ade74c88dee7d4b9e0491f0bdaf Mon Sep 17 00:00:00 2001 From: Ronan Pigott Date: Sun, 25 Oct 2020 14:20:11 -0700 Subject: [PATCH] Change workspace_layout to match i3 behavior In i3, the workspace_layout command does not affect the workspace layout. Instead, new workspace level containers are wrapped in the desired layout and the workspace layout always defaults to the output orientation. --- include/sway/tree/workspace.h | 4 ++-- sway/desktop/xdg_shell.c | 11 ++++++----- sway/input/seatop_move_tiling.c | 2 +- sway/sway.5.scd | 2 +- sway/tree/container.c | 7 ++++--- sway/tree/output.c | 3 --- sway/tree/view.c | 23 +++++++++++----------- sway/tree/workspace.c | 34 ++++++++++++++++++++++++--------- 8 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index fe200ec0..3c9f93ed 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -110,13 +110,13 @@ void workspace_unwrap_children(struct sway_workspace *ws, void workspace_detach(struct sway_workspace *workspace); -void workspace_add_tiling(struct sway_workspace *workspace, +struct sway_container *workspace_add_tiling(struct sway_workspace *workspace, struct sway_container *con); void workspace_add_floating(struct sway_workspace *workspace, struct sway_container *con); -void workspace_insert_tiling(struct sway_workspace *workspace, +struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace, struct sway_container *con, int index); void workspace_remove_gaps(struct sway_workspace *ws); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index f02021e1..fdac6171 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -349,19 +349,20 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data) return; } + struct sway_container *container = view->container; if (e->fullscreen && e->output && e->output->data) { struct sway_output *output = e->output->data; struct sway_workspace *ws = output_get_active_workspace(output); - if (ws && !container_is_scratchpad_hidden(view->container)) { - if (container_is_floating(view->container)) { - workspace_add_floating(ws, view->container); + if (ws && !container_is_scratchpad_hidden(container)) { + if (container_is_floating(container)) { + workspace_add_floating(ws, container); } else { - workspace_add_tiling(ws, view->container); + container = workspace_add_tiling(ws, container); } } } - container_set_fullscreen(view->container, e->fullscreen); + container_set_fullscreen(container, e->fullscreen); arrange_root(); transaction_commit_dirty(); diff --git a/sway/input/seatop_move_tiling.c b/sway/input/seatop_move_tiling.c index c7285bec..704e7270 100644 --- a/sway/input/seatop_move_tiling.c +++ b/sway/input/seatop_move_tiling.c @@ -247,7 +247,7 @@ static void finalize_move(struct sway_seat *seat) { // Moving container into empty workspace if (target_node->type == N_WORKSPACE && edge == WLR_EDGE_NONE) { - workspace_add_tiling(new_ws, con); + con = workspace_add_tiling(new_ws, con); } else if (target_node->type == N_CONTAINER) { // Moving container before/after another struct sway_container *target = target_node->sway_container; diff --git a/sway/sway.5.scd b/sway/sway.5.scd index f608ad2e..02592b5f 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -89,7 +89,7 @@ The following commands may only be used in the configuration file. _swaynag\_command -_ *workspace_layout* default|stacking|tabbed - Specifies the initial layout for new workspaces. + Specifies the initial layout for new containers in an empty workspace. *xwayland* enable|disable|force Enables or disables Xwayland support, which allows X11 applications to be diff --git a/sway/tree/container.c b/sway/tree/container.c index b0d23700..23b6c997 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -804,9 +804,10 @@ void container_set_floating(struct sway_container *container, bool enable) { container->width = reference->width; container->height = reference->height; } else { - workspace_add_tiling(workspace, container); - container->width = workspace->width; - container->height = workspace->height; + struct sway_container *other = + workspace_add_tiling(workspace, container); + other->width = workspace->width; + other->height = workspace->height; } if (container->view) { view_set_tiled(container->view, true); diff --git a/sway/tree/output.c b/sway/tree/output.c index f15a84b3..a8ae30f7 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -395,9 +395,6 @@ void output_get_box(struct sway_output *output, struct wlr_box *box) { enum sway_container_layout output_get_default_layout( struct sway_output *output) { - if (config->default_layout != L_NONE) { - return config->default_layout; - } if (config->default_orientation != L_NONE) { return config->default_orientation; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 354f2d34..e690c334 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -732,10 +732,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, ws = seat_get_last_known_workspace(seat); } + struct sway_container *container = view->container; if (target_sibling) { - container_add_sibling(target_sibling, view->container, 1); + container_add_sibling(target_sibling, container, 1); } else if (ws) { - workspace_add_tiling(ws, view->container); + container = workspace_add_tiling(ws, container); } ipc_event_window(view->container, "new"); @@ -759,26 +760,26 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, } if (config->popup_during_fullscreen == POPUP_LEAVE && - view->container->workspace && - view->container->workspace->fullscreen && - view->container->workspace->fullscreen->view) { - struct sway_container *fs = view->container->workspace->fullscreen; + container->workspace && + container->workspace->fullscreen && + container->workspace->fullscreen->view) { + struct sway_container *fs = container->workspace->fullscreen; if (view_is_transient_for(view, fs->view)) { container_set_fullscreen(fs, false); } } view_update_title(view, false); - container_update_representation(view->container); + container_update_representation(container); if (fullscreen) { container_set_fullscreen(view->container, true); arrange_workspace(view->container->workspace); } else { - if (view->container->parent) { - arrange_container(view->container->parent); - } else if (view->container->workspace) { - arrange_workspace(view->container->workspace); + if (container->parent) { + arrange_container(container->parent); + } else if (container->workspace) { + arrange_workspace(container->workspace); } } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index ffcbe933..e40792ae 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -627,6 +627,21 @@ struct sway_container *workspace_find_container(struct sway_workspace *ws, return NULL; } +static void set_workspace(struct sway_container *container, void *data) { + container->workspace = container->parent->workspace; +} + +static void workspace_attach_tiling(struct sway_workspace *ws, + struct sway_container *con) { + list_add(ws->tiling, con); + con->workspace = ws; + container_for_each_child(con, set_workspace, NULL); + container_handle_fullscreen_reparent(con); + workspace_update_representation(ws); + node_set_dirty(&ws->node); + node_set_dirty(&con->node); +} + struct sway_container *workspace_wrap_children(struct sway_workspace *ws) { struct sway_container *fs = ws->fullscreen; struct sway_container *middle = container_create(NULL); @@ -636,7 +651,7 @@ struct sway_container *workspace_wrap_children(struct sway_workspace *ws) { container_detach(child); container_add_child(middle, child); } - workspace_add_tiling(ws, middle); + workspace_attach_tiling(ws, middle); ws->fullscreen = fs; return middle; } @@ -668,15 +683,14 @@ void workspace_detach(struct sway_workspace *workspace) { node_set_dirty(&output->node); } -static void set_workspace(struct sway_container *container, void *data) { - container->workspace = container->parent->workspace; -} - -void workspace_add_tiling(struct sway_workspace *workspace, +struct sway_container *workspace_add_tiling(struct sway_workspace *workspace, struct sway_container *con) { if (con->workspace) { container_detach(con); } + if (config->default_layout != L_NONE) { + con = container_split(con, config->default_layout); + } list_add(workspace->tiling, con); con->workspace = workspace; container_for_each_child(con, set_workspace, NULL); @@ -684,6 +698,7 @@ void workspace_add_tiling(struct sway_workspace *workspace, workspace_update_representation(workspace); node_set_dirty(&workspace->node); node_set_dirty(&con->node); + return con; } void workspace_add_floating(struct sway_workspace *workspace, @@ -699,13 +714,13 @@ void workspace_add_floating(struct sway_workspace *workspace, node_set_dirty(&con->node); } -void workspace_insert_tiling(struct sway_workspace *workspace, +struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace, struct sway_container *con, int index) { if (con->workspace) { container_detach(con); } - if (workspace->layout == L_STACKED || workspace->layout == L_TABBED) { - con = container_split(con, workspace->layout); + if (config->default_layout != L_NONE) { + con = container_split(con, config->default_layout); } list_insert(workspace->tiling, index, con); con->workspace = workspace; @@ -714,6 +729,7 @@ void workspace_insert_tiling(struct sway_workspace *workspace, workspace_update_representation(workspace); node_set_dirty(&workspace->node); node_set_dirty(&con->node); + return con; } void workspace_add_gaps(struct sway_workspace *ws) {