aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-11 11:03:43 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-11 11:03:43 +1000
commit9e96cfd310c4e5dc60f07d772e60b139ff7dc448 (patch)
tree9961c8705208b2f127133f0533bd305a6f75015e /sway/tree/arrange.c
parentRefactor everything that needs to arrange windows (diff)
parentMerge pull request #2124 from emersion/drag-icons (diff)
downloadsway-9e96cfd310c4e5dc60f07d772e60b139ff7dc448.tar.gz
sway-9e96cfd310c4e5dc60f07d772e60b139ff7dc448.tar.zst
sway-9e96cfd310c4e5dc60f07d772e60b139ff7dc448.zip
Merge remote-tracking branch 'upstream/master' into atomic
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c53
1 files changed, 52 insertions, 1 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index e138410d..ac99c5df 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -41,6 +41,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
41 child->width = parent->width; 41 child->width = parent->width;
42 } 42 }
43 } 43 }
44 remove_gaps(child);
44 total_width += child->width; 45 total_width += child->width;
45 } 46 }
46 double scale = parent->width / total_width; 47 double scale = parent->width / total_width;
@@ -63,6 +64,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
63 if (i == num_children - 1) { 64 if (i == num_children - 1) {
64 child->width = parent->x + parent->width - child->x; 65 child->width = parent->x + parent->width - child->x;
65 } 66 }
67 add_gaps(child);
66 } 68 }
67} 69}
68 70
@@ -78,7 +80,7 @@ static void apply_vert_layout(struct sway_container *parent) {
78 parent_offset = 80 parent_offset =
79 container_titlebar_height() * parent->parent->children->length; 81 container_titlebar_height() * parent->parent->children->length;
80 } 82 }
81 size_t parent_height = parent->height - parent_offset; 83 size_t parent_height = parent->height + parent_offset;
82 84
83 // Calculate total height of children 85 // Calculate total height of children
84 double total_height = 0; 86 double total_height = 0;
@@ -91,6 +93,7 @@ static void apply_vert_layout(struct sway_container *parent) {
91 child->height = parent_height; 93 child->height = parent_height;
92 } 94 }
93 } 95 }
96 remove_gaps(child);
94 total_height += child->height; 97 total_height += child->height;
95 } 98 }
96 double scale = parent_height / total_height; 99 double scale = parent_height / total_height;
@@ -114,6 +117,7 @@ static void apply_vert_layout(struct sway_container *parent) {
114 child->height = 117 child->height =
115 parent->y + parent_offset + parent_height - child->y; 118 parent->y + parent_offset + parent_height - child->y;
116 } 119 }
120 add_gaps(child);
117 } 121 }
118} 122}
119 123
@@ -131,10 +135,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
131 size_t parent_height = parent->height - parent_offset; 135 size_t parent_height = parent->height - parent_offset;
132 for (int i = 0; i < parent->children->length; ++i) { 136 for (int i = 0; i < parent->children->length; ++i) {
133 struct sway_container *child = parent->children->items[i]; 137 struct sway_container *child = parent->children->items[i];
138 remove_gaps(child);
134 child->x = parent->x; 139 child->x = parent->x;
135 child->y = parent->y + parent_offset; 140 child->y = parent->y + parent_offset;
136 child->width = parent->width; 141 child->width = parent->width;
137 child->height = parent_height; 142 child->height = parent_height;
143 add_gaps(child);
138 } 144 }
139} 145}
140 146
@@ -185,6 +191,11 @@ static void arrange_children_of(struct sway_container *parent,
185 // Recurse into child containers 191 // Recurse into child containers
186 for (int i = 0; i < parent->children->length; ++i) { 192 for (int i = 0; i < parent->children->length; ++i) {
187 struct sway_container *child = parent->children->items[i]; 193 struct sway_container *child = parent->children->items[i];
194 if (parent->has_gaps && !child->has_gaps) {
195 child->has_gaps = true;
196 child->gaps_inner = parent->gaps_inner;
197 child->gaps_outer = parent->gaps_outer;
198 }
188 if (child->type == C_VIEW) { 199 if (child->type == C_VIEW) {
189 view_autoconfigure(child->sway_view); 200 view_autoconfigure(child->sway_view);
190 } else { 201 } else {
@@ -203,10 +214,12 @@ static void arrange_workspace(struct sway_container *workspace,
203 struct wlr_box *area = &output->sway_output->usable_area; 214 struct wlr_box *area = &output->sway_output->usable_area;
204 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 215 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
205 area->width, area->height, area->x, area->y); 216 area->width, area->height, area->x, area->y);
217 remove_gaps(workspace);
206 workspace->width = area->width; 218 workspace->width = area->width;
207 workspace->height = area->height; 219 workspace->height = area->height;
208 workspace->x = output->x + area->x; 220 workspace->x = output->x + area->x;
209 workspace->y = output->y + area->y; 221 workspace->y = output->y + area->y;
222 add_gaps(workspace);
210 transaction_add_container(transaction, workspace); 223 transaction_add_container(transaction, workspace);
211 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, 224 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
212 workspace->x, workspace->y); 225 workspace->x, workspace->y);
@@ -285,3 +298,41 @@ void arrange_and_commit(struct sway_container *container) {
285 arrange_windows(container, transaction); 298 arrange_windows(container, transaction);
286 transaction_commit(transaction); 299 transaction_commit(transaction);
287} 300}
301
302void remove_gaps(struct sway_container *c) {
303 if (c->current_gaps == 0) {
304 wlr_log(L_DEBUG, "Removing gaps: not gapped: %p", c);
305 return;
306 }
307
308 c->width += c->current_gaps * 2;
309 c->height += c->current_gaps * 2;
310 c->x -= c->current_gaps;
311 c->y -= c->current_gaps;
312
313 c->current_gaps = 0;
314
315 wlr_log(L_DEBUG, "Removing gaps %p", c);
316}
317
318void add_gaps(struct sway_container *c) {
319 if (c->current_gaps > 0 || c->type == C_CONTAINER) {
320 wlr_log(L_DEBUG, "Not adding gaps: %p", c);
321 return;
322 }
323
324 if (c->type == C_WORKSPACE &&
325 !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) {
326 return;
327 }
328
329 double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner;
330
331 c->x += gaps;
332 c->y += gaps;
333 c->width -= 2 * gaps;
334 c->height -= 2 * gaps;
335 c->current_gaps = gaps;
336
337 wlr_log(L_DEBUG, "Adding gaps: %p", c);
338}