aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-19 17:00:51 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-08-26 09:52:12 +1000
commit8bed4be1f387f9aa48910db1cf979cd847a9a2e3 (patch)
tree6bb0cd51d006de03535d4019d05c6787e8dd17aa /sway/tree/arrange.c
parentMerge pull request #2512 from apreiml/workspace_move_wrap (diff)
downloadsway-8bed4be1f387f9aa48910db1cf979cd847a9a2e3.tar.gz
sway-8bed4be1f387f9aa48910db1cf979cd847a9a2e3.tar.zst
sway-8bed4be1f387f9aa48910db1cf979cd847a9a2e3.zip
Make separate gaps functions per container type
In preparation for using type safety.
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c54
1 files changed, 8 insertions, 46 deletions
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
318void 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
334void 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}