diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index d10251dd..56ccbc6c 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -255,6 +255,13 @@ void view_get_constraints(struct sway_view *view, double *min_width, uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, int height); +/** + * Whether or not the view is the only visible view in its tree. If the view + * is tiling, there may be floating views. If the view is floating, there may + * be tiling views or views in a different floating container. + */ +bool view_is_only_visible(struct sway_view *view); + /** * Configure the view's position and size based on the container's position and * size, taking borders into consideration. diff --git a/sway/input/seat.c b/sway/input/seat.c index 4817eae7..34b64d9c 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -760,6 +760,12 @@ void seat_set_focus_warp(struct sway_seat *seat, struct sway_node *node, seat->has_focus = true; + if (config->smart_gaps) { + // When smart gaps is on, gaps may change when the focus changes so + // the workspace needs to be arranged + arrange_workspace(new_workspace); + } + update_debug_tree(); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 788300cc..e1e616f9 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -1021,10 +1021,28 @@ void container_add_gaps(struct sway_container *c) { if (!c->view && c->layout != L_TABBED && c->layout != L_STACKED) { return; } - // Children of tabbed/stacked containers re-use the gaps of the container - enum sway_container_layout layout = container_parent_layout(c); - if (layout == L_TABBED || layout == L_STACKED) { - return; + // Descendants of tabbed/stacked containers re-use the gaps of the container + struct sway_container *temp = c; + while (temp) { + enum sway_container_layout layout = container_parent_layout(temp); + if (layout == L_TABBED || layout == L_STACKED) { + return; + } + temp = temp->parent; + } + // If smart gaps is on, don't add gaps if there is only one view visible + if (config->smart_gaps) { + struct sway_view *view = c->view; + if (!view) { + struct sway_seat *seat = + input_manager_get_default_seat(input_manager); + struct sway_container *focus = + seat_get_focus_inactive_view(seat, &c->node); + view = focus ? focus->view : NULL; + } + if (view && view_is_only_visible(view)) { + return; + } } struct sway_workspace *ws = c->workspace; diff --git a/sway/tree/view.c b/sway/tree/view.c index a024f325..3b271159 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -162,6 +162,23 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, return 0; } +bool view_is_only_visible(struct sway_view *view) { + bool only_view = true; + struct sway_container *con = view->container; + while (con) { + enum sway_container_layout layout = container_parent_layout(con); + if (layout != L_TABBED && layout != L_STACKED) { + list_t *siblings = container_get_siblings(con); + if (siblings && siblings->length > 1) { + only_view = false; + break; + } + } + con = con->parent; + } + return only_view; +} + void view_autoconfigure(struct sway_view *view) { if (!view->container->workspace) { // Hidden in the scratchpad @@ -178,24 +195,9 @@ void view_autoconfigure(struct sway_view *view) { } struct sway_workspace *ws = view->container->workspace; - - bool other_views = false; - if (config->hide_edge_borders == E_SMART) { - struct sway_container *con = view->container; - while (con) { - enum sway_container_layout layout = container_parent_layout(con); - if (layout != L_TABBED && layout != L_STACKED) { - list_t *siblings = container_get_siblings(con); - if (siblings && siblings->length > 1) { - other_views = true; - break; - } - } - con = con->parent; - } - } - struct sway_container *con = view->container; + bool other_views = config->hide_edge_borders == E_SMART ? + !view_is_only_visible(view) : false; view->border_top = view->border_bottom = true; view->border_left = view->border_right = true; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 9dd5c815..e9e5dfa2 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -640,11 +640,17 @@ void workspace_add_gaps(struct sway_workspace *ws) { if (ws->current_gaps > 0) { return; } - bool should_apply = - config->edge_gaps || (config->smart_gaps && ws->tiling->length > 1); - if (!should_apply) { + if (!config->edge_gaps) { return; } + if (config->smart_gaps) { + struct sway_seat *seat = input_manager_get_default_seat(input_manager); + struct sway_container *focus = + seat_get_focus_inactive_view(seat, &ws->node); + if (focus && focus->view && view_is_only_visible(focus->view)) { + return; + } + } ws->current_gaps = ws->gaps_outer;