diff options
-rw-r--r-- | include/sway/tree/arrange.h | 6 | ||||
-rw-r--r-- | include/sway/tree/container.h | 4 | ||||
-rw-r--r-- | include/sway/tree/workspace.h | 4 | ||||
-rw-r--r-- | sway/tree/arrange.c | 54 | ||||
-rw-r--r-- | sway/tree/container.c | 33 | ||||
-rw-r--r-- | sway/tree/layout.c | 5 | ||||
-rw-r--r-- | sway/tree/workspace.c | 35 |
7 files changed, 86 insertions, 55 deletions
diff --git a/include/sway/tree/arrange.h b/include/sway/tree/arrange.h index d6abcc81..346103d3 100644 --- a/include/sway/tree/arrange.h +++ b/include/sway/tree/arrange.h | |||
@@ -4,12 +4,6 @@ | |||
4 | 4 | ||
5 | struct sway_container; | 5 | struct sway_container; |
6 | 6 | ||
7 | // Remove gaps around container | ||
8 | void remove_gaps(struct sway_container *c); | ||
9 | |||
10 | // Add gaps around container | ||
11 | void add_gaps(struct sway_container *c); | ||
12 | |||
13 | /** | 7 | /** |
14 | * Arrange layout for all the children of the given container. | 8 | * Arrange layout for all the children of the given container. |
15 | */ | 9 | */ |
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 2cedb613..2b6e6e0c 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -335,6 +335,10 @@ struct sway_output *container_get_effective_output(struct sway_container *con); | |||
335 | 335 | ||
336 | void container_discover_outputs(struct sway_container *con); | 336 | void container_discover_outputs(struct sway_container *con); |
337 | 337 | ||
338 | void container_remove_gaps(struct sway_container *container); | ||
339 | |||
340 | void container_add_gaps(struct sway_container *container); | ||
341 | |||
338 | int container_sibling_index(const struct sway_container *child); | 342 | int container_sibling_index(const struct sway_container *child); |
339 | 343 | ||
340 | #endif | 344 | #endif |
diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index efcb7c69..04325919 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h | |||
@@ -75,4 +75,8 @@ struct sway_container *workspace_wrap_children(struct sway_container *ws); | |||
75 | void workspace_add_floating(struct sway_container *workspace, | 75 | void workspace_add_floating(struct sway_container *workspace, |
76 | struct sway_container *con); | 76 | struct sway_container *con); |
77 | 77 | ||
78 | void workspace_remove_gaps(struct sway_container *ws); | ||
79 | |||
80 | void workspace_add_gaps(struct sway_container *ws); | ||
81 | |||
78 | #endif | 82 | #endif |
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index a4b058f3..0da61a4c 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c | |||
@@ -39,7 +39,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
39 | child->width = parent->width; | 39 | child->width = parent->width; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | remove_gaps(child); | 42 | container_remove_gaps(child); |
43 | total_width += child->width; | 43 | total_width += child->width; |
44 | } | 44 | } |
45 | double scale = parent->width / total_width; | 45 | double scale = parent->width / total_width; |
@@ -62,7 +62,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
62 | if (i == num_children - 1) { | 62 | if (i == num_children - 1) { |
63 | child->width = parent->x + parent->width - child->x; | 63 | child->width = parent->x + parent->width - child->x; |
64 | } | 64 | } |
65 | add_gaps(child); | 65 | container_add_gaps(child); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
@@ -91,7 +91,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
91 | child->height = parent_height; | 91 | child->height = parent_height; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | remove_gaps(child); | 94 | container_remove_gaps(child); |
95 | total_height += child->height; | 95 | total_height += child->height; |
96 | } | 96 | } |
97 | double scale = parent_height / total_height; | 97 | double scale = parent_height / total_height; |
@@ -115,7 +115,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
115 | child->height = | 115 | child->height = |
116 | parent->y + parent_offset + parent_height - child->y; | 116 | parent->y + parent_offset + parent_height - child->y; |
117 | } | 117 | } |
118 | add_gaps(child); | 118 | container_add_gaps(child); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
@@ -133,12 +133,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { | |||
133 | size_t parent_height = parent->height - parent_offset; | 133 | size_t parent_height = parent->height - parent_offset; |
134 | for (int i = 0; i < parent->children->length; ++i) { | 134 | for (int i = 0; i < parent->children->length; ++i) { |
135 | struct sway_container *child = parent->children->items[i]; | 135 | struct sway_container *child = parent->children->items[i]; |
136 | remove_gaps(child); | 136 | container_remove_gaps(child); |
137 | child->x = parent->x; | 137 | child->x = parent->x; |
138 | child->y = parent->y + parent_offset; | 138 | child->y = parent->y + parent_offset; |
139 | child->width = parent->width; | 139 | child->width = parent->width; |
140 | child->height = parent_height; | 140 | child->height = parent_height; |
141 | add_gaps(child); | 141 | container_add_gaps(child); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
@@ -205,7 +205,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
205 | struct wlr_box *area = &output->sway_output->usable_area; | 205 | struct wlr_box *area = &output->sway_output->usable_area; |
206 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 206 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
207 | area->width, area->height, area->x, area->y); | 207 | area->width, area->height, area->x, area->y); |
208 | remove_gaps(workspace); | 208 | workspace_remove_gaps(workspace); |
209 | 209 | ||
210 | double prev_x = workspace->x; | 210 | double prev_x = workspace->x; |
211 | double prev_y = workspace->y; | 211 | double prev_y = workspace->y; |
@@ -230,7 +230,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | add_gaps(workspace); | 233 | workspace_add_gaps(workspace); |
234 | container_set_dirty(workspace); | 234 | container_set_dirty(workspace); |
235 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, | 235 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, |
236 | workspace->x, workspace->y); | 236 | workspace->x, workspace->y); |
@@ -314,41 +314,3 @@ void arrange_windows(struct sway_container *container) { | |||
314 | break; | 314 | break; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | |||
318 | void remove_gaps(struct sway_container *c) { | ||
319 | if (c->current_gaps == 0) { | ||
320 | wlr_log(WLR_DEBUG, "Removing gaps: not gapped: %p", c); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | c->width += c->current_gaps * 2; | ||
325 | c->height += c->current_gaps * 2; | ||
326 | c->x -= c->current_gaps; | ||
327 | c->y -= c->current_gaps; | ||
328 | |||
329 | c->current_gaps = 0; | ||
330 | |||
331 | wlr_log(WLR_DEBUG, "Removing gaps %p", c); | ||
332 | } | ||
333 | |||
334 | void add_gaps(struct sway_container *c) { | ||
335 | if (c->current_gaps > 0 || c->type == C_CONTAINER) { | ||
336 | wlr_log(WLR_DEBUG, "Not adding gaps: %p", c); | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | if (c->type == C_WORKSPACE && | ||
341 | !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) { | ||
342 | return; | ||
343 | } | ||
344 | |||
345 | double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
346 | |||
347 | c->x += gaps; | ||
348 | c->y += gaps; | ||
349 | c->width -= 2 * gaps; | ||
350 | c->height -= 2 * gaps; | ||
351 | c->current_gaps = gaps; | ||
352 | |||
353 | wlr_log(WLR_DEBUG, "Adding gaps: %p", c); | ||
354 | } | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index 5721c35c..f9611342 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -1124,7 +1124,38 @@ void container_discover_outputs(struct sway_container *con) { | |||
1124 | } | 1124 | } |
1125 | } | 1125 | } |
1126 | 1126 | ||
1127 | void container_remove_gaps(struct sway_container *c) { | ||
1128 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1129 | "Expected a container or view")) { | ||
1130 | return; | ||
1131 | } | ||
1132 | if (c->current_gaps == 0) { | ||
1133 | return; | ||
1134 | } | ||
1135 | |||
1136 | c->width += c->current_gaps * 2; | ||
1137 | c->height += c->current_gaps * 2; | ||
1138 | c->x -= c->current_gaps; | ||
1139 | c->y -= c->current_gaps; | ||
1140 | c->current_gaps = 0; | ||
1141 | } | ||
1142 | |||
1143 | void container_add_gaps(struct sway_container *c) { | ||
1144 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1145 | "Expected a container or view")) { | ||
1146 | return; | ||
1147 | } | ||
1148 | if (c->current_gaps > 0 || c->type != C_VIEW) { | ||
1149 | return; | ||
1150 | } | ||
1151 | |||
1152 | c->current_gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
1153 | c->x += c->current_gaps; | ||
1154 | c->y += c->current_gaps; | ||
1155 | c->width -= 2 * c->current_gaps; | ||
1156 | c->height -= 2 * c->current_gaps; | ||
1157 | } | ||
1158 | |||
1127 | int container_sibling_index(const struct sway_container *child) { | 1159 | int container_sibling_index(const struct sway_container *child) { |
1128 | return list_find(child->parent->children, child); | 1160 | return list_find(child->parent->children, child); |
1129 | } | 1161 | } |
1130 | |||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 601d0e91..85fe7643 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -218,7 +218,8 @@ struct sway_container *container_split(struct sway_container *child, | |||
218 | 218 | ||
219 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); | 219 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); |
220 | 220 | ||
221 | remove_gaps(child); | 221 | child->type == C_WORKSPACE ? workspace_remove_gaps(child) |
222 | : container_remove_gaps(child); | ||
222 | 223 | ||
223 | cont->prev_split_layout = L_NONE; | 224 | cont->prev_split_layout = L_NONE; |
224 | cont->width = child->width; | 225 | cont->width = child->width; |
@@ -229,7 +230,7 @@ struct sway_container *container_split(struct sway_container *child, | |||
229 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | 230 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); |
230 | bool set_focus = (seat_get_focus(seat) == child); | 231 | bool set_focus = (seat_get_focus(seat) == child); |
231 | 232 | ||
232 | add_gaps(cont); | 233 | container_add_gaps(cont); |
233 | 234 | ||
234 | if (child->type == C_WORKSPACE) { | 235 | if (child->type == C_WORKSPACE) { |
235 | struct sway_container *workspace = child; | 236 | struct sway_container *workspace = child; |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 93c4b3d3..d930826e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -665,3 +665,38 @@ void workspace_add_floating(struct sway_container *workspace, | |||
665 | container_set_dirty(workspace); | 665 | container_set_dirty(workspace); |
666 | container_set_dirty(con); | 666 | container_set_dirty(con); |
667 | } | 667 | } |
668 | |||
669 | void workspace_remove_gaps(struct sway_container *ws) { | ||
670 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
671 | return; | ||
672 | } | ||
673 | if (ws->current_gaps == 0) { | ||
674 | return; | ||
675 | } | ||
676 | |||
677 | ws->width += ws->current_gaps * 2; | ||
678 | ws->height += ws->current_gaps * 2; | ||
679 | ws->x -= ws->current_gaps; | ||
680 | ws->y -= ws->current_gaps; | ||
681 | ws->current_gaps = 0; | ||
682 | } | ||
683 | |||
684 | void workspace_add_gaps(struct sway_container *ws) { | ||
685 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
686 | return; | ||
687 | } | ||
688 | if (ws->current_gaps > 0) { | ||
689 | return; | ||
690 | } | ||
691 | bool should_apply = | ||
692 | config->edge_gaps || (config->smart_gaps && ws->children->length > 1); | ||
693 | if (!should_apply) { | ||
694 | return; | ||
695 | } | ||
696 | |||
697 | ws->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner; | ||
698 | ws->x += ws->current_gaps; | ||
699 | ws->y += ws->current_gaps; | ||
700 | ws->width -= 2 * ws->current_gaps; | ||
701 | ws->height -= 2 * ws->current_gaps; | ||
702 | } | ||