aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/tree/container.h12
-rw-r--r--sway/commands/move.c1
-rw-r--r--sway/tree/arrange.c55
-rw-r--r--sway/tree/container.c67
-rw-r--r--sway/tree/view.c16
-rw-r--r--sway/tree/workspace.c38
6 files changed, 53 insertions, 136 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 4efde640..099a8089 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -116,14 +116,6 @@ struct sway_container {
bool border_left;
bool border_right;
- // The gaps currently applied to the container.
- struct {
- int top;
- int right;
- int bottom;
- int left;
- } current_gaps;
-
struct sway_workspace *workspace; // NULL when hidden in the scratchpad
struct sway_container *parent; // NULL if container in root of workspace
list_t *children; // struct sway_container
@@ -296,10 +288,6 @@ struct sway_output *container_get_effective_output(struct sway_container *con);
void container_discover_outputs(struct sway_container *con);
-void container_remove_gaps(struct sway_container *container);
-
-void container_add_gaps(struct sway_container *container);
-
enum sway_container_layout container_parent_layout(struct sway_container *con);
enum sway_container_layout container_current_parent_layout(
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 2a1993ae..5779b431 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -235,7 +235,6 @@ static void container_move_to_container(struct sway_container *container,
struct sway_workspace *old_workspace = container->workspace;
container_detach(container);
- container_remove_gaps(container);
container->width = container->height = 0;
container->width_fraction = container->height_fraction = 0;
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index dd0a72cd..caafb1af 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -52,23 +52,39 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
child->width_fraction /= total_width_fraction;
}
+ // Calculate gap size
+ double inner_gap = 0;
+ struct sway_container *child = children->items[0];
+ struct sway_workspace *ws = child->workspace;
+ if (ws) {
+ inner_gap = ws->gaps_inner;
+ }
+ // Descendants of tabbed/stacked containers don't have gaps
+ struct sway_container *temp = child;
+ while (temp) {
+ enum sway_container_layout layout = container_parent_layout(temp);
+ if (layout == L_TABBED || layout == L_STACKED) {
+ inner_gap = 0;
+ }
+ temp = temp->parent;
+ }
+ double child_total_width = parent->width - inner_gap * (children->length - 1);
+
// Resize windows
sway_log(SWAY_DEBUG, "Arranging %p horizontally", parent);
double child_x = parent->x;
for (int i = 0; i < children->length; ++i) {
struct sway_container *child = children->items[i];
- container_remove_gaps(child);
child->x = child_x;
child->y = parent->y;
- child->width = floor(child->width_fraction * parent->width);
+ child->width = floor(child->width_fraction * child_total_width);
child->height = parent->height;
- child_x += child->width;
+ child_x += child->width + inner_gap;
// Make last child use remaining width of parent
if (i == children->length - 1) {
child->width = parent->x + parent->width - child->x;
}
- container_add_gaps(child);
}
}
@@ -111,23 +127,39 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
child->height_fraction /= total_height_fraction;
}
- // Resize
+ // Calculate gap size
+ double inner_gap = 0;
+ struct sway_container *child = children->items[0];
+ struct sway_workspace *ws = child->workspace;
+ if (ws) {
+ inner_gap = ws->gaps_inner;
+ }
+ // Descendants of tabbed/stacked containers don't have gaps
+ struct sway_container *temp = child;
+ while (temp) {
+ enum sway_container_layout layout = container_parent_layout(temp);
+ if (layout == L_TABBED || layout == L_STACKED) {
+ inner_gap = 0;
+ }
+ temp = temp->parent;
+ }
+ double child_total_height = parent->height - inner_gap * (children->length - 1);
+
+ // Resize windows
sway_log(SWAY_DEBUG, "Arranging %p vertically", parent);
double child_y = parent->y;
for (int i = 0; i < children->length; ++i) {
struct sway_container *child = children->items[i];
- container_remove_gaps(child);
child->x = parent->x;
child->y = child_y;
child->width = parent->width;
- child->height = floor(child->height_fraction * parent->height);
- child_y += child->height;
+ child->height = floor(child->height_fraction * child_total_height);
+ child_y += child->height + inner_gap;
// Make last child use remaining height of parent
if (i == children->length - 1) {
child->height = parent->y + parent->height - child->y;
}
- container_add_gaps(child);
}
}
@@ -138,12 +170,10 @@ static void apply_tabbed_layout(list_t *children, struct wlr_box *parent) {
for (int i = 0; i < children->length; ++i) {
struct sway_container *child = children->items[i];
int parent_offset = child->view ? 0 : container_titlebar_height();
- container_remove_gaps(child);
child->x = parent->x;
child->y = parent->y + parent_offset;
child->width = parent->width;
child->height = parent->height - parent_offset;
- container_add_gaps(child);
}
}
@@ -155,12 +185,10 @@ static void apply_stacked_layout(list_t *children, struct wlr_box *parent) {
struct sway_container *child = children->items[i];
int parent_offset = child->view ? 0 :
container_titlebar_height() * children->length;
- container_remove_gaps(child);
child->x = parent->x;
child->y = parent->y + parent_offset;
child->width = parent->width;
child->height = parent->height - parent_offset;
- container_add_gaps(child);
}
}
@@ -226,7 +254,6 @@ void arrange_workspace(struct sway_workspace *workspace) {
struct wlr_box *area = &output->usable_area;
sway_log(SWAY_DEBUG, "Usable area for ws: %dx%d@%d,%d",
area->width, area->height, area->x, area->y);
- workspace_remove_gaps(workspace);
bool first_arrange = workspace->width == 0 && workspace->height == 0;
double prev_x = workspace->x;
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 068dbb88..10aed599 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -1173,72 +1173,6 @@ void container_discover_outputs(struct sway_container *con) {
}
}
-void container_remove_gaps(struct sway_container *c) {
- if (c->current_gaps.top == 0 && c->current_gaps.right == 0 &&
- c->current_gaps.bottom == 0 && c->current_gaps.left == 0) {
- return;
- }
-
- c->width += c->current_gaps.left + c->current_gaps.right;
- c->height += c->current_gaps.top + c->current_gaps.bottom;
- c->x -= c->current_gaps.left;
- c->y -= c->current_gaps.top;
-
- c->current_gaps.top = 0;
- c->current_gaps.right = 0;
- c->current_gaps.bottom = 0;
- c->current_gaps.left = 0;
-}
-
-void container_add_gaps(struct sway_container *c) {
- if (c->current_gaps.top > 0 || c->current_gaps.right > 0 ||
- c->current_gaps.bottom > 0 || c->current_gaps.left > 0) {
- return;
- }
- // Fullscreen global scratchpad containers cannot have gaps
- struct sway_workspace *ws = c->workspace;
- if (!ws) {
- return;
- }
- // Linear containers don't have gaps because it'd create double gaps
- if (!c->view && c->layout != L_TABBED && c->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();
- 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;
- }
- }
-
- c->current_gaps.top = c->y == ws->y ? ws->gaps_inner : 0;
- c->current_gaps.right = ws->gaps_inner;
- c->current_gaps.bottom = ws->gaps_inner;
- c->current_gaps.left = c->x == ws->x ? ws->gaps_inner : 0;
-
- c->x += c->current_gaps.left;
- c->y += c->current_gaps.top;
- c->width -= c->current_gaps.left + c->current_gaps.right;
- c->height -= c->current_gaps.top + c->current_gaps.bottom;
-}
-
enum sway_container_layout container_parent_layout(struct sway_container *con) {
if (con->parent) {
return con->parent->layout;
@@ -1421,7 +1355,6 @@ struct sway_container *container_split(struct sway_container *child,
cont->height_fraction = child->height_fraction;
cont->x = child->x;
cont->y = child->y;
- cont->current_gaps = child->current_gaps;
cont->layout = layout;
container_replace(child, cont);
diff --git a/sway/tree/view.c b/sway/tree/view.c
index f6d62ad6..be540804 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -183,14 +183,6 @@ bool view_is_only_visible(struct sway_view *view) {
}
static bool gaps_to_edge(struct sway_view *view) {
- struct sway_container *con = view->container;
- while (con) {
- if (con->current_gaps.top > 0 || con->current_gaps.right > 0 ||
- con->current_gaps.bottom > 0 || con->current_gaps.left > 0) {
- return true;
- }
- con = con->parent;
- }
struct side_gaps gaps = view->container->workspace->current_gaps;
return gaps.top > 0 || gaps.right > 0 || gaps.bottom > 0 || gaps.left > 0;
}
@@ -232,14 +224,14 @@ void view_autoconfigure(struct sway_view *view) {
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL || hide_smart) {
- con->border_left = con->x - con->current_gaps.left != ws->x;
- int right_x = con->x + con->width + con->current_gaps.right;
+ con->border_left = con->x != ws->x;
+ int right_x = con->x + con->width;
con->border_right = right_x != ws->x + ws->width;
}
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL || hide_smart) {
- con->border_top = con->y - con->current_gaps.top != ws->y;
- int bottom_y = con->y + con->height + con->current_gaps.bottom;
+ con->border_top = con->y != ws->y;
+ int bottom_y = con->y + con->height;
con->border_bottom = bottom_y != ws->y + ws->height;
}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 914b6a9d..accdf6e3 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -700,28 +700,7 @@ void workspace_insert_tiling(struct sway_workspace *workspace,
node_set_dirty(&con->node);
}
-void workspace_remove_gaps(struct sway_workspace *ws) {
- if (ws->current_gaps.top == 0 && ws->current_gaps.right == 0 &&
- ws->current_gaps.bottom == 0 && ws->current_gaps.left == 0) {
- return;
- }
-
- ws->width += ws->current_gaps.left + ws->current_gaps.right;
- ws->height += ws->current_gaps.top + ws->current_gaps.bottom;
- ws->x -= ws->current_gaps.left;
- ws->y -= ws->current_gaps.top;
-
- ws->current_gaps.top = 0;
- ws->current_gaps.right = 0;
- ws->current_gaps.bottom = 0;
- ws->current_gaps.left = 0;
-}
-
void workspace_add_gaps(struct sway_workspace *ws) {
- if (ws->current_gaps.top > 0 || ws->current_gaps.right > 0 ||
- ws->current_gaps.bottom > 0 || ws->current_gaps.left > 0) {
- return;
- }
if (config->smart_gaps) {
struct sway_seat *seat = input_manager_get_default_seat();
struct sway_container *focus =
@@ -730,20 +709,19 @@ void workspace_add_gaps(struct sway_workspace *ws) {
focus = seat_get_focus_inactive_view(seat, &focus->node);
}
if (focus && focus->view && view_is_only_visible(focus->view)) {
+ ws->current_gaps.top = 0;
+ ws->current_gaps.right = 0;
+ ws->current_gaps.bottom = 0;
+ ws->current_gaps.left = 0;
return;
}
}
ws->current_gaps = ws->gaps_outer;
- if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
- // We have to add inner gaps for this, because children of tabbed and
- // stacked containers don't apply their own gaps - they assume the
- // tabbed/stacked container is using gaps.
- ws->current_gaps.top += ws->gaps_inner;
- ws->current_gaps.right += ws->gaps_inner;
- ws->current_gaps.bottom += ws->gaps_inner;
- ws->current_gaps.left += ws->gaps_inner;
- }
+ ws->current_gaps.top += ws->gaps_inner;
+ ws->current_gaps.right += ws->gaps_inner;
+ ws->current_gaps.bottom += ws->gaps_inner;
+ ws->current_gaps.left += ws->gaps_inner;
ws->x += ws->current_gaps.left;
ws->y += ws->current_gaps.top;