diff options
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r-- | sway/tree/arrange.c | 102 |
1 files changed, 38 insertions, 64 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index 582b2891..533cf71c 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c | |||
@@ -47,11 +47,11 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
47 | double scale = parent->width / total_width; | 47 | double scale = parent->width / total_width; |
48 | 48 | ||
49 | // Resize windows | 49 | // Resize windows |
50 | wlr_log(L_DEBUG, "Arranging %p horizontally", parent); | 50 | wlr_log(WLR_DEBUG, "Arranging %p horizontally", parent); |
51 | double child_x = parent->x; | 51 | double child_x = parent->x; |
52 | for (size_t i = 0; i < num_children; ++i) { | 52 | for (size_t i = 0; i < num_children; ++i) { |
53 | struct sway_container *child = parent->children->items[i]; | 53 | struct sway_container *child = parent->children->items[i]; |
54 | wlr_log(L_DEBUG, | 54 | wlr_log(WLR_DEBUG, |
55 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 55 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
56 | child, child->type, child->width, scale); | 56 | child, child->type, child->width, scale); |
57 | child->x = child_x; | 57 | child->x = child_x; |
@@ -99,11 +99,11 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
99 | double scale = parent_height / total_height; | 99 | double scale = parent_height / total_height; |
100 | 100 | ||
101 | // Resize | 101 | // Resize |
102 | wlr_log(L_DEBUG, "Arranging %p vertically", parent); | 102 | wlr_log(WLR_DEBUG, "Arranging %p vertically", parent); |
103 | double child_y = parent->y + parent_offset; | 103 | double child_y = parent->y + parent_offset; |
104 | for (size_t i = 0; i < num_children; ++i) { | 104 | for (size_t i = 0; i < num_children; ++i) { |
105 | struct sway_container *child = parent->children->items[i]; | 105 | struct sway_container *child = parent->children->items[i]; |
106 | wlr_log(L_DEBUG, | 106 | wlr_log(WLR_DEBUG, |
107 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 107 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
108 | child, child->type, child->height, scale); | 108 | child, child->type, child->height, scale); |
109 | child->x = parent->x; | 109 | child->x = parent->x; |
@@ -144,42 +144,26 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { | |||
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | /** | 147 | static void arrange_children_of(struct sway_container *parent); |
148 | * If a container has been deleted from the pending tree state, we must add it | ||
149 | * to the transaction so it can be freed afterwards. To do this, we iterate the | ||
150 | * server's destroying_containers list and add all of them. We may add more than | ||
151 | * what we need to, but this is easy and has no negative consequences. | ||
152 | */ | ||
153 | static void add_deleted_containers(struct sway_transaction *transaction) { | ||
154 | for (int i = 0; i < server.destroying_containers->length; ++i) { | ||
155 | struct sway_container *child = server.destroying_containers->items[i]; | ||
156 | transaction_add_container(transaction, child); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | static void arrange_children_of(struct sway_container *parent, | ||
161 | struct sway_transaction *transaction); | ||
162 | 148 | ||
163 | static void arrange_floating(struct sway_container *floating, | 149 | static void arrange_floating(struct sway_container *floating) { |
164 | struct sway_transaction *transaction) { | ||
165 | for (int i = 0; i < floating->children->length; ++i) { | 150 | for (int i = 0; i < floating->children->length; ++i) { |
166 | struct sway_container *floater = floating->children->items[i]; | 151 | struct sway_container *floater = floating->children->items[i]; |
167 | if (floater->type == C_VIEW) { | 152 | if (floater->type == C_VIEW) { |
168 | view_autoconfigure(floater->sway_view); | 153 | view_autoconfigure(floater->sway_view); |
169 | } else { | 154 | } else { |
170 | arrange_children_of(floater, transaction); | 155 | arrange_children_of(floater); |
171 | } | 156 | } |
172 | transaction_add_container(transaction, floater); | 157 | container_set_dirty(floater); |
173 | } | 158 | } |
174 | transaction_add_container(transaction, floating); | 159 | container_set_dirty(floating); |
175 | } | 160 | } |
176 | 161 | ||
177 | static void arrange_children_of(struct sway_container *parent, | 162 | static void arrange_children_of(struct sway_container *parent) { |
178 | struct sway_transaction *transaction) { | ||
179 | if (config->reloading) { | 163 | if (config->reloading) { |
180 | return; | 164 | return; |
181 | } | 165 | } |
182 | wlr_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent, | 166 | wlr_log(WLR_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent, |
183 | parent->name, parent->width, parent->height, parent->x, parent->y); | 167 | parent->name, parent->width, parent->height, parent->x, parent->y); |
184 | 168 | ||
185 | // Calculate x, y, width and height of children | 169 | // Calculate x, y, width and height of children |
@@ -198,7 +182,7 @@ static void arrange_children_of(struct sway_container *parent, | |||
198 | apply_horiz_layout(parent); | 182 | apply_horiz_layout(parent); |
199 | break; | 183 | break; |
200 | case L_FLOATING: | 184 | case L_FLOATING: |
201 | arrange_floating(parent, transaction); | 185 | arrange_floating(parent); |
202 | break; | 186 | break; |
203 | } | 187 | } |
204 | 188 | ||
@@ -213,20 +197,19 @@ static void arrange_children_of(struct sway_container *parent, | |||
213 | if (child->type == C_VIEW) { | 197 | if (child->type == C_VIEW) { |
214 | view_autoconfigure(child->sway_view); | 198 | view_autoconfigure(child->sway_view); |
215 | } else { | 199 | } else { |
216 | arrange_children_of(child, transaction); | 200 | arrange_children_of(child); |
217 | } | 201 | } |
218 | transaction_add_container(transaction, child); | 202 | container_set_dirty(child); |
219 | } | 203 | } |
220 | } | 204 | } |
221 | 205 | ||
222 | static void arrange_workspace(struct sway_container *workspace, | 206 | static void arrange_workspace(struct sway_container *workspace) { |
223 | struct sway_transaction *transaction) { | ||
224 | if (config->reloading) { | 207 | if (config->reloading) { |
225 | return; | 208 | return; |
226 | } | 209 | } |
227 | struct sway_container *output = workspace->parent; | 210 | struct sway_container *output = workspace->parent; |
228 | struct wlr_box *area = &output->sway_output->usable_area; | 211 | struct wlr_box *area = &output->sway_output->usable_area; |
229 | wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 212 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
230 | area->width, area->height, area->x, area->y); | 213 | area->width, area->height, area->x, area->y); |
231 | remove_gaps(workspace); | 214 | remove_gaps(workspace); |
232 | workspace->width = area->width; | 215 | workspace->width = area->width; |
@@ -234,15 +217,14 @@ static void arrange_workspace(struct sway_container *workspace, | |||
234 | workspace->x = output->x + area->x; | 217 | workspace->x = output->x + area->x; |
235 | workspace->y = output->y + area->y; | 218 | workspace->y = output->y + area->y; |
236 | add_gaps(workspace); | 219 | add_gaps(workspace); |
237 | transaction_add_container(transaction, workspace); | 220 | container_set_dirty(workspace); |
238 | wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, | 221 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, |
239 | workspace->x, workspace->y); | 222 | workspace->x, workspace->y); |
240 | arrange_floating(workspace->sway_workspace->floating, transaction); | 223 | arrange_floating(workspace->sway_workspace->floating); |
241 | arrange_children_of(workspace, transaction); | 224 | arrange_children_of(workspace); |
242 | } | 225 | } |
243 | 226 | ||
244 | static void arrange_output(struct sway_container *output, | 227 | static void arrange_output(struct sway_container *output) { |
245 | struct sway_transaction *transaction) { | ||
246 | if (config->reloading) { | 228 | if (config->reloading) { |
247 | return; | 229 | return; |
248 | } | 230 | } |
@@ -253,16 +235,16 @@ static void arrange_output(struct sway_container *output, | |||
253 | output->y = output_box->y; | 235 | output->y = output_box->y; |
254 | output->width = output_box->width; | 236 | output->width = output_box->width; |
255 | output->height = output_box->height; | 237 | output->height = output_box->height; |
256 | transaction_add_container(transaction, output); | 238 | container_set_dirty(output); |
257 | wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", | 239 | wlr_log(WLR_DEBUG, "Arranging output '%s' at %f,%f", |
258 | output->name, output->x, output->y); | 240 | output->name, output->x, output->y); |
259 | for (int i = 0; i < output->children->length; ++i) { | 241 | for (int i = 0; i < output->children->length; ++i) { |
260 | struct sway_container *workspace = output->children->items[i]; | 242 | struct sway_container *workspace = output->children->items[i]; |
261 | arrange_workspace(workspace, transaction); | 243 | arrange_workspace(workspace); |
262 | } | 244 | } |
263 | } | 245 | } |
264 | 246 | ||
265 | static void arrange_root(struct sway_transaction *transaction) { | 247 | static void arrange_root() { |
266 | if (config->reloading) { | 248 | if (config->reloading) { |
267 | return; | 249 | return; |
268 | } | 250 | } |
@@ -274,48 +256,40 @@ static void arrange_root(struct sway_transaction *transaction) { | |||
274 | root_container.y = layout_box->y; | 256 | root_container.y = layout_box->y; |
275 | root_container.width = layout_box->width; | 257 | root_container.width = layout_box->width; |
276 | root_container.height = layout_box->height; | 258 | root_container.height = layout_box->height; |
277 | transaction_add_container(transaction, &root_container); | 259 | container_set_dirty(&root_container); |
278 | for (int i = 0; i < root_container.children->length; ++i) { | 260 | for (int i = 0; i < root_container.children->length; ++i) { |
279 | struct sway_container *output = root_container.children->items[i]; | 261 | struct sway_container *output = root_container.children->items[i]; |
280 | arrange_output(output, transaction); | 262 | arrange_output(output); |
281 | } | 263 | } |
282 | } | 264 | } |
283 | 265 | ||
284 | void arrange_windows(struct sway_container *container, | 266 | void arrange_windows(struct sway_container *container) { |
285 | struct sway_transaction *transaction) { | ||
286 | switch (container->type) { | 267 | switch (container->type) { |
287 | case C_ROOT: | 268 | case C_ROOT: |
288 | arrange_root(transaction); | 269 | arrange_root(); |
289 | break; | 270 | break; |
290 | case C_OUTPUT: | 271 | case C_OUTPUT: |
291 | arrange_output(container, transaction); | 272 | arrange_output(container); |
292 | break; | 273 | break; |
293 | case C_WORKSPACE: | 274 | case C_WORKSPACE: |
294 | arrange_workspace(container, transaction); | 275 | arrange_workspace(container); |
295 | break; | 276 | break; |
296 | case C_CONTAINER: | 277 | case C_CONTAINER: |
297 | arrange_children_of(container, transaction); | 278 | arrange_children_of(container); |
298 | transaction_add_container(transaction, container); | 279 | container_set_dirty(container); |
299 | break; | 280 | break; |
300 | case C_VIEW: | 281 | case C_VIEW: |
301 | view_autoconfigure(container->sway_view); | 282 | view_autoconfigure(container->sway_view); |
302 | transaction_add_container(transaction, container); | 283 | container_set_dirty(container); |
303 | break; | 284 | break; |
304 | case C_TYPES: | 285 | case C_TYPES: |
305 | break; | 286 | break; |
306 | } | 287 | } |
307 | add_deleted_containers(transaction); | ||
308 | } | ||
309 | |||
310 | void arrange_and_commit(struct sway_container *container) { | ||
311 | struct sway_transaction *transaction = transaction_create(); | ||
312 | arrange_windows(container, transaction); | ||
313 | transaction_commit(transaction); | ||
314 | } | 288 | } |
315 | 289 | ||
316 | void remove_gaps(struct sway_container *c) { | 290 | void remove_gaps(struct sway_container *c) { |
317 | if (c->current_gaps == 0) { | 291 | if (c->current_gaps == 0) { |
318 | wlr_log(L_DEBUG, "Removing gaps: not gapped: %p", c); | 292 | wlr_log(WLR_DEBUG, "Removing gaps: not gapped: %p", c); |
319 | return; | 293 | return; |
320 | } | 294 | } |
321 | 295 | ||
@@ -326,12 +300,12 @@ void remove_gaps(struct sway_container *c) { | |||
326 | 300 | ||
327 | c->current_gaps = 0; | 301 | c->current_gaps = 0; |
328 | 302 | ||
329 | wlr_log(L_DEBUG, "Removing gaps %p", c); | 303 | wlr_log(WLR_DEBUG, "Removing gaps %p", c); |
330 | } | 304 | } |
331 | 305 | ||
332 | void add_gaps(struct sway_container *c) { | 306 | void add_gaps(struct sway_container *c) { |
333 | if (c->current_gaps > 0 || c->type == C_CONTAINER) { | 307 | if (c->current_gaps > 0 || c->type == C_CONTAINER) { |
334 | wlr_log(L_DEBUG, "Not adding gaps: %p", c); | 308 | wlr_log(WLR_DEBUG, "Not adding gaps: %p", c); |
335 | return; | 309 | return; |
336 | } | 310 | } |
337 | 311 | ||
@@ -348,5 +322,5 @@ void add_gaps(struct sway_container *c) { | |||
348 | c->height -= 2 * gaps; | 322 | c->height -= 2 * gaps; |
349 | c->current_gaps = gaps; | 323 | c->current_gaps = gaps; |
350 | 324 | ||
351 | wlr_log(L_DEBUG, "Adding gaps: %p", c); | 325 | wlr_log(WLR_DEBUG, "Adding gaps: %p", c); |
352 | } | 326 | } |