diff --git a/include/container.h b/include/container.h index 26da851e0..d9f33b8ae 100644 --- a/include/container.h +++ b/include/container.h @@ -240,6 +240,12 @@ bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); * Returns true if the child is a desecendant of the parent. */ bool swayc_is_child_of(swayc_t *child, swayc_t *parent); + +/** + * Returns true if view is stacked or tabbed. + */ +bool swayc_is_tabbed_stacked(swayc_t *view); + /** * Returns the gap (padding) of the container. * diff --git a/sway/border.c b/sway/border.c index ada5af2af..061c14277 100644 --- a/sway/border.c +++ b/sway/border.c @@ -237,7 +237,7 @@ void update_view_border(swayc_t *view) { swayc_t *p = view->parent; - if (p->layout == L_TABBED || p->layout == L_STACKED) { + if (swayc_is_tabbed_stacked(view)) { cr = create_border_buffer(view, view->border_geometry, &surface); if (focused == view) { render_borders(view, cr, &config->border_colors.focused, false); diff --git a/sway/commands.c b/sway/commands.c index 07dd715ca..12d60854e 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -1764,8 +1764,16 @@ static struct cmd_results *cmd_layout(int argc, char **argv) { // cmd_workspace_layout parent->layout = L_HORIZ; } else if (strcasecmp(argv[0], "tabbed") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_TABBED); + } + parent->layout = L_TABBED; } else if (strcasecmp(argv[0], "stacking") == 0) { + if (parent->type != C_CONTAINER) { + parent = new_container(parent, L_STACKED); + } + parent->layout = L_STACKED; } else if (strcasecmp(argv[0], "splith") == 0) { parent->layout = L_HORIZ; diff --git a/sway/container.c b/sway/container.c index e77ba0629..2b100f40e 100644 --- a/sway/container.c +++ b/sway/container.c @@ -237,7 +237,7 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { add_child(workspace, cont); // give them proper layouts cont->layout = workspace->layout; - workspace->layout = layout; + /* TODO: might break shit in move_container!!! workspace->layout = layout; */ set_focused_container_for(workspace, get_focused_view(workspace)); } else { // Or is built around container swayc_t *parent = replace_child(child, cont); @@ -722,9 +722,7 @@ void update_visibility_output(swayc_t *container, wlc_handle output) { swayc_t *parent = container->parent; container->visible = parent->visible; // special cases where visibility depends on focus - if (parent->type == C_OUTPUT - || parent->layout == L_TABBED - || parent->layout == L_STACKED) { + if (parent->type == C_OUTPUT || swayc_is_tabbed_stacked(container)) { container->visible = parent->focused == container && parent->visible; } // Set visibility and output for view @@ -814,3 +812,8 @@ static void close_view(swayc_t *container, void *data) { void close_views(swayc_t *container) { container_map(container, close_view, NULL); } + +bool swayc_is_tabbed_stacked(swayc_t *view) { + return (view->parent->layout == L_TABBED + || view->parent->layout == L_STACKED); +} diff --git a/sway/focus.c b/sway/focus.c index 8acdc772c..8ce224560 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -149,7 +149,7 @@ bool set_focused_container(swayc_t *c) { } // rearrange if parent container is tabbed/stacked - if (p->parent->layout == L_TABBED || p->parent->layout == L_STACKED) { + if (swayc_is_tabbed_stacked(p)) { arrange_windows(p->parent, -1, -1); } } else if (p->type == C_WORKSPACE) { diff --git a/sway/layout.c b/sway/layout.c index 0328d3612..527579d95 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -458,7 +458,7 @@ void update_geometry(swayc_t *container) { // use parent size if window is in a stacked/tabbed layout swayc_t *parent = container->parent; - if (parent->layout == L_STACKED || parent->layout == L_TABBED) { + if (swayc_is_tabbed_stacked(container)) { width = parent->width; height = parent->height; } @@ -833,6 +833,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { swayc_t *view = container->floating->items[i]; if (view->type == C_VIEW) { update_geometry(view); + sway_log(L_DEBUG, "Set floating view to %.f x %.f @ %.f, %.f", view->width, + view->height, view->x, view->y); if (swayc_is_fullscreen(view)) { wlc_view_bring_to_front(view->handle); } else if (!container->focused