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.
This commit is contained in:
Ronan Pigott 2020-10-25 14:20:11 -07:00 committed by Tudor Brindus
parent b4850876dc
commit ece6a1d408
8 changed files with 51 additions and 35 deletions

View file

@ -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);

View file

@ -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();

View file

@ -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;

View file

@ -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

View file

@ -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);

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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) {