Fix smart gaps
This commit is contained in:
parent
51f68e10ad
commit
742d1764a6
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -1021,11 +1021,29 @@ 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);
|
||||
// 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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue