aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c88
1 files changed, 80 insertions, 8 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 721b557e..53c95820 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -43,6 +43,7 @@ void arrange_output(struct sway_container *output) {
43 "called arrange_output() on non-output container")) { 43 "called arrange_output() on non-output container")) {
44 return; 44 return;
45 } 45 }
46
46 const struct wlr_box *output_box = wlr_output_layout_get_box( 47 const struct wlr_box *output_box = wlr_output_layout_get_box(
47 root_container.sway_root->output_layout, 48 root_container.sway_root->output_layout,
48 output->sway_output->wlr_output); 49 output->sway_output->wlr_output);
@@ -52,6 +53,7 @@ void arrange_output(struct sway_container *output) {
52 output->height = output_box->height; 53 output->height = output_box->height;
53 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", 54 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
54 output->name, output->x, output->y); 55 output->name, output->x, output->y);
56
55 for (int i = 0; i < output->children->length; ++i) { 57 for (int i = 0; i < output->children->length; ++i) {
56 struct sway_container *workspace = output->children->items[i]; 58 struct sway_container *workspace = output->children->items[i];
57 arrange_workspace(workspace); 59 arrange_workspace(workspace);
@@ -67,18 +69,62 @@ void arrange_workspace(struct sway_container *workspace) {
67 "called arrange_workspace() on non-workspace container")) { 69 "called arrange_workspace() on non-workspace container")) {
68 return; 70 return;
69 } 71 }
72
70 struct sway_container *output = workspace->parent; 73 struct sway_container *output = workspace->parent;
71 struct wlr_box *area = &output->sway_output->usable_area; 74 struct wlr_box *area = &output->sway_output->usable_area;
72 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 75 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
73 area->width, area->height, area->x, area->y); 76 area->width, area->height, area->x, area->y);
77
78 remove_gaps(workspace);
79
74 workspace->width = area->width; 80 workspace->width = area->width;
75 workspace->height = area->height; 81 workspace->height = area->height;
76 workspace->x = output->x + area->x; 82 workspace->x = output->x + area->x;
77 workspace->y = output->y + area->y; 83 workspace->y = output->y + area->y;
84
85 add_gaps(workspace);
86
78 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", 87 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f",
79 workspace->name, workspace->x, workspace->y); 88 workspace->name, workspace->x, workspace->y);
80 arrange_children_of(workspace); 89 arrange_children_of(workspace);
81 container_damage_whole(workspace); 90}
91
92void remove_gaps(struct sway_container *c) {
93 if (c->current_gaps == 0) {
94 wlr_log(L_DEBUG, "Removing gaps: not gapped: %p", c);
95 return;
96 }
97
98 c->width += c->current_gaps * 2;
99 c->height += c->current_gaps * 2;
100 c->x -= c->current_gaps;
101 c->y -= c->current_gaps;
102
103 c->current_gaps = 0;
104
105 wlr_log(L_DEBUG, "Removing gaps %p", c);
106}
107
108void add_gaps(struct sway_container *c) {
109 if (c->current_gaps > 0 || c->type == C_CONTAINER) {
110 wlr_log(L_DEBUG, "Not adding gaps: %p", c);
111 return;
112 }
113
114 if (c->type == C_WORKSPACE &&
115 !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) {
116 return;
117 }
118
119 double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner;
120
121 c->x += gaps;
122 c->y += gaps;
123 c->width -= 2 * gaps;
124 c->height -= 2 * gaps;
125 c->current_gaps = gaps;
126
127 wlr_log(L_DEBUG, "Adding gaps: %p", c);
82} 128}
83 129
84static void apply_horiz_layout(struct sway_container *parent) { 130static void apply_horiz_layout(struct sway_container *parent) {
@@ -99,6 +145,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
99 double total_width = 0; 145 double total_width = 0;
100 for (size_t i = 0; i < num_children; ++i) { 146 for (size_t i = 0; i < num_children; ++i) {
101 struct sway_container *child = parent->children->items[i]; 147 struct sway_container *child = parent->children->items[i];
148
102 if (child->width <= 0) { 149 if (child->width <= 0) {
103 if (num_children > 1) { 150 if (num_children > 1) {
104 child->width = parent->width / (num_children - 1); 151 child->width = parent->width / (num_children - 1);
@@ -106,6 +153,7 @@ static void apply_horiz_layout(struct sway_container *parent) {
106 child->width = parent->width; 153 child->width = parent->width;
107 } 154 }
108 } 155 }
156 remove_gaps(child);
109 total_width += child->width; 157 total_width += child->width;
110 } 158 }
111 double scale = parent->width / total_width; 159 double scale = parent->width / total_width;
@@ -121,12 +169,19 @@ static void apply_horiz_layout(struct sway_container *parent) {
121 child, child->type, child->width, scale); 169 child, child->type, child->width, scale);
122 child->x = child_x; 170 child->x = child_x;
123 child->y = parent->y + parent_offset; 171 child->y = parent->y + parent_offset;
124 child->width = floor(child->width * scale);
125 child->height = parent_height; 172 child->height = parent_height;
173
174 if (i == num_children - 1) {
175 // Make last child use remaining width of parent
176 child->width = parent->x + parent->width - child->x;
177 } else {
178 child->width = floor(child->width * scale);
179 }
180
126 child_x += child->width; 181 child_x += child->width;
182
183 add_gaps(child);
127 } 184 }
128 // Make last child use remaining width of parent
129 child->width = parent->x + parent->width - child->x;
130} 185}
131 186
132static void apply_vert_layout(struct sway_container *parent) { 187static void apply_vert_layout(struct sway_container *parent) {
@@ -141,12 +196,13 @@ static void apply_vert_layout(struct sway_container *parent) {
141 parent_offset = 196 parent_offset =
142 container_titlebar_height() * parent->parent->children->length; 197 container_titlebar_height() * parent->parent->children->length;
143 } 198 }
144 size_t parent_height = parent->height - parent_offset; 199 size_t parent_height = parent->height + parent_offset;
145 200
146 // Calculate total height of children 201 // Calculate total height of children
147 double total_height = 0; 202 double total_height = 0;
148 for (size_t i = 0; i < num_children; ++i) { 203 for (size_t i = 0; i < num_children; ++i) {
149 struct sway_container *child = parent->children->items[i]; 204 struct sway_container *child = parent->children->items[i];
205
150 if (child->height <= 0) { 206 if (child->height <= 0) {
151 if (num_children > 1) { 207 if (num_children > 1) {
152 child->height = parent_height / (num_children - 1); 208 child->height = parent_height / (num_children - 1);
@@ -154,6 +210,7 @@ static void apply_vert_layout(struct sway_container *parent) {
154 child->height = parent_height; 210 child->height = parent_height;
155 } 211 }
156 } 212 }
213 remove_gaps(child);
157 total_height += child->height; 214 total_height += child->height;
158 } 215 }
159 double scale = parent_height / total_height; 216 double scale = parent_height / total_height;
@@ -170,11 +227,18 @@ static void apply_vert_layout(struct sway_container *parent) {
170 child->x = parent->x; 227 child->x = parent->x;
171 child->y = child_y; 228 child->y = child_y;
172 child->width = parent->width; 229 child->width = parent->width;
173 child->height = floor(child->height * scale); 230
231 if (i == num_children - 1) {
232 // Make last child use remaining height of parent
233 child->height = parent->y + parent_offset + parent_height - child->y;
234 } else {
235 child->height = floor(child->height * scale);
236 }
237
174 child_y += child->height; 238 child_y += child->height;
239
240 add_gaps(child);
175 } 241 }
176 // Make last child use remaining height of parent
177 child->height = parent->y + parent_offset + parent_height - child->y;
178} 242}
179 243
180static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { 244static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
@@ -191,10 +255,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
191 size_t parent_height = parent->height - parent_offset; 255 size_t parent_height = parent->height - parent_offset;
192 for (int i = 0; i < parent->children->length; ++i) { 256 for (int i = 0; i < parent->children->length; ++i) {
193 struct sway_container *child = parent->children->items[i]; 257 struct sway_container *child = parent->children->items[i];
258 remove_gaps(child);
194 child->x = parent->x; 259 child->x = parent->x;
195 child->y = parent->y + parent_offset; 260 child->y = parent->y + parent_offset;
196 child->width = parent->width; 261 child->width = parent->width;
197 child->height = parent_height; 262 child->height = parent_height;
263 add_gaps(child);
198 } 264 }
199} 265}
200 266
@@ -211,6 +277,7 @@ void arrange_children_of(struct sway_container *parent) {
211 if (workspace->type != C_WORKSPACE) { 277 if (workspace->type != C_WORKSPACE) {
212 workspace = container_parent(workspace, C_WORKSPACE); 278 workspace = container_parent(workspace, C_WORKSPACE);
213 } 279 }
280
214 if (workspace->sway_workspace->fullscreen) { 281 if (workspace->sway_workspace->fullscreen) {
215 // Just arrange the fullscreen view and jump out 282 // Just arrange the fullscreen view and jump out
216 view_autoconfigure(workspace->sway_workspace->fullscreen); 283 view_autoconfigure(workspace->sway_workspace->fullscreen);
@@ -241,6 +308,11 @@ void arrange_children_of(struct sway_container *parent) {
241 // Apply x, y, width and height to children and recurse if needed 308 // Apply x, y, width and height to children and recurse if needed
242 for (int i = 0; i < parent->children->length; ++i) { 309 for (int i = 0; i < parent->children->length; ++i) {
243 struct sway_container *child = parent->children->items[i]; 310 struct sway_container *child = parent->children->items[i];
311 if (parent->has_gaps && !child->has_gaps) {
312 child->has_gaps = true;
313 child->gaps_inner = parent->gaps_inner;
314 child->gaps_outer = parent->gaps_outer;
315 }
244 if (child->type == C_VIEW) { 316 if (child->type == C_VIEW) {
245 view_autoconfigure(child->sway_view); 317 view_autoconfigure(child->sway_view);
246 } else { 318 } else {