diff options
Diffstat (limited to 'sway/commands/resize.c')
-rw-r--r-- | sway/commands/resize.c | 158 |
1 files changed, 93 insertions, 65 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index ca36e858..32b746ea 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c | |||
@@ -57,7 +57,7 @@ struct sway_container *container_find_resize_parent(struct sway_container *con, | |||
57 | (allow_last || index < siblings->length - 1)) { | 57 | (allow_last || index < siblings->length - 1)) { |
58 | return con; | 58 | return con; |
59 | } | 59 | } |
60 | con = con->parent; | 60 | con = con->pending.parent; |
61 | } | 61 | } |
62 | 62 | ||
63 | return NULL; | 63 | return NULL; |
@@ -75,6 +75,10 @@ void container_resize_tiled(struct sway_container *con, | |||
75 | return; | 75 | return; |
76 | } | 76 | } |
77 | 77 | ||
78 | if (container_is_scratchpad_hidden_or_child(con)) { | ||
79 | return; | ||
80 | } | ||
81 | |||
78 | // For HORIZONTAL or VERTICAL, we are growing in two directions so select | 82 | // For HORIZONTAL or VERTICAL, we are growing in two directions so select |
79 | // both adjacent siblings. For RIGHT or DOWN, just select the next sibling. | 83 | // both adjacent siblings. For RIGHT or DOWN, just select the next sibling. |
80 | // For LEFT or UP, convert it to a RIGHT or DOWN resize and reassign con to | 84 | // For LEFT or UP, convert it to a RIGHT or DOWN resize and reassign con to |
@@ -115,13 +119,13 @@ void container_resize_tiled(struct sway_container *con, | |||
115 | int sibling_amount = prev ? ceil((double)amount / 2.0) : amount; | 119 | int sibling_amount = prev ? ceil((double)amount / 2.0) : amount; |
116 | 120 | ||
117 | if (is_horizontal(axis)) { | 121 | if (is_horizontal(axis)) { |
118 | if (con->width + amount < MIN_SANE_W) { | 122 | if (con->pending.width + amount < MIN_SANE_W) { |
119 | return; | 123 | return; |
120 | } | 124 | } |
121 | if (next->width - sibling_amount < MIN_SANE_W) { | 125 | if (next->pending.width - sibling_amount < MIN_SANE_W) { |
122 | return; | 126 | return; |
123 | } | 127 | } |
124 | if (prev && prev->width - sibling_amount < MIN_SANE_W) { | 128 | if (prev && prev->pending.width - sibling_amount < MIN_SANE_W) { |
125 | return; | 129 | return; |
126 | } | 130 | } |
127 | if (con->child_total_width <= 0) { | 131 | if (con->child_total_width <= 0) { |
@@ -133,7 +137,7 @@ void container_resize_tiled(struct sway_container *con, | |||
133 | list_t *siblings = container_get_siblings(con); | 137 | list_t *siblings = container_get_siblings(con); |
134 | for (int i = 0; i < siblings->length; ++i) { | 138 | for (int i = 0; i < siblings->length; ++i) { |
135 | struct sway_container *con = siblings->items[i]; | 139 | struct sway_container *con = siblings->items[i]; |
136 | con->width_fraction = con->width / con->child_total_width; | 140 | con->width_fraction = con->pending.width / con->child_total_width; |
137 | } | 141 | } |
138 | 142 | ||
139 | double amount_fraction = (double)amount / con->child_total_width; | 143 | double amount_fraction = (double)amount / con->child_total_width; |
@@ -146,13 +150,13 @@ void container_resize_tiled(struct sway_container *con, | |||
146 | prev->width_fraction -= sibling_amount_fraction; | 150 | prev->width_fraction -= sibling_amount_fraction; |
147 | } | 151 | } |
148 | } else { | 152 | } else { |
149 | if (con->height + amount < MIN_SANE_H) { | 153 | if (con->pending.height + amount < MIN_SANE_H) { |
150 | return; | 154 | return; |
151 | } | 155 | } |
152 | if (next->height - sibling_amount < MIN_SANE_H) { | 156 | if (next->pending.height - sibling_amount < MIN_SANE_H) { |
153 | return; | 157 | return; |
154 | } | 158 | } |
155 | if (prev && prev->height - sibling_amount < MIN_SANE_H) { | 159 | if (prev && prev->pending.height - sibling_amount < MIN_SANE_H) { |
156 | return; | 160 | return; |
157 | } | 161 | } |
158 | if (con->child_total_height <= 0) { | 162 | if (con->child_total_height <= 0) { |
@@ -164,7 +168,7 @@ void container_resize_tiled(struct sway_container *con, | |||
164 | list_t *siblings = container_get_siblings(con); | 168 | list_t *siblings = container_get_siblings(con); |
165 | for (int i = 0; i < siblings->length; ++i) { | 169 | for (int i = 0; i < siblings->length; ++i) { |
166 | struct sway_container *con = siblings->items[i]; | 170 | struct sway_container *con = siblings->items[i]; |
167 | con->height_fraction = con->height / con->child_total_height; | 171 | con->height_fraction = con->pending.height / con->child_total_height; |
168 | } | 172 | } |
169 | 173 | ||
170 | double amount_fraction = (double)amount / con->child_total_height; | 174 | double amount_fraction = (double)amount / con->child_total_height; |
@@ -178,10 +182,10 @@ void container_resize_tiled(struct sway_container *con, | |||
178 | } | 182 | } |
179 | } | 183 | } |
180 | 184 | ||
181 | if (con->parent) { | 185 | if (con->pending.parent) { |
182 | arrange_container(con->parent); | 186 | arrange_container(con->pending.parent); |
183 | } else { | 187 | } else { |
184 | arrange_workspace(con->workspace); | 188 | arrange_workspace(con->pending.workspace); |
185 | } | 189 | } |
186 | } | 190 | } |
187 | 191 | ||
@@ -203,15 +207,15 @@ static struct cmd_results *resize_adjust_floating(uint32_t axis, | |||
203 | int min_width, max_width, min_height, max_height; | 207 | int min_width, max_width, min_height, max_height; |
204 | floating_calculate_constraints(&min_width, &max_width, | 208 | floating_calculate_constraints(&min_width, &max_width, |
205 | &min_height, &max_height); | 209 | &min_height, &max_height); |
206 | if (con->width + grow_width < min_width) { | 210 | if (con->pending.width + grow_width < min_width) { |
207 | grow_width = min_width - con->width; | 211 | grow_width = min_width - con->pending.width; |
208 | } else if (con->width + grow_width > max_width) { | 212 | } else if (con->pending.width + grow_width > max_width) { |
209 | grow_width = max_width - con->width; | 213 | grow_width = max_width - con->pending.width; |
210 | } | 214 | } |
211 | if (con->height + grow_height < min_height) { | 215 | if (con->pending.height + grow_height < min_height) { |
212 | grow_height = min_height - con->height; | 216 | grow_height = min_height - con->pending.height; |
213 | } else if (con->height + grow_height > max_height) { | 217 | } else if (con->pending.height + grow_height > max_height) { |
214 | grow_height = max_height - con->height; | 218 | grow_height = max_height - con->pending.height; |
215 | } | 219 | } |
216 | int grow_x = 0, grow_y = 0; | 220 | int grow_x = 0, grow_y = 0; |
217 | 221 | ||
@@ -227,15 +231,15 @@ static struct cmd_results *resize_adjust_floating(uint32_t axis, | |||
227 | if (grow_width == 0 && grow_height == 0) { | 231 | if (grow_width == 0 && grow_height == 0) { |
228 | return cmd_results_new(CMD_INVALID, "Cannot resize any further"); | 232 | return cmd_results_new(CMD_INVALID, "Cannot resize any further"); |
229 | } | 233 | } |
230 | con->x += grow_x; | 234 | con->pending.x += grow_x; |
231 | con->y += grow_y; | 235 | con->pending.y += grow_y; |
232 | con->width += grow_width; | 236 | con->pending.width += grow_width; |
233 | con->height += grow_height; | 237 | con->pending.height += grow_height; |
234 | 238 | ||
235 | con->content_x += grow_x; | 239 | con->pending.content_x += grow_x; |
236 | con->content_y += grow_y; | 240 | con->pending.content_y += grow_y; |
237 | con->content_width += grow_width; | 241 | con->pending.content_width += grow_width; |
238 | con->content_height += grow_height; | 242 | con->pending.content_height += grow_height; |
239 | 243 | ||
240 | arrange_container(con); | 244 | arrange_container(con); |
241 | 245 | ||
@@ -249,16 +253,35 @@ static struct cmd_results *resize_adjust_tiled(uint32_t axis, | |||
249 | struct movement_amount *amount) { | 253 | struct movement_amount *amount) { |
250 | struct sway_container *current = config->handler_context.container; | 254 | struct sway_container *current = config->handler_context.container; |
251 | 255 | ||
256 | if (container_is_scratchpad_hidden_or_child(current)) { | ||
257 | return cmd_results_new(CMD_FAILURE, "Cannot resize a hidden scratchpad container"); | ||
258 | } | ||
259 | |||
252 | if (amount->unit == MOVEMENT_UNIT_DEFAULT) { | 260 | if (amount->unit == MOVEMENT_UNIT_DEFAULT) { |
253 | amount->unit = MOVEMENT_UNIT_PPT; | 261 | amount->unit = MOVEMENT_UNIT_PPT; |
254 | } | 262 | } |
255 | if (amount->unit == MOVEMENT_UNIT_PPT) { | 263 | if (amount->unit == MOVEMENT_UNIT_PPT) { |
264 | struct sway_container *parent = current->pending.parent; | ||
256 | float pct = amount->amount / 100.0f; | 265 | float pct = amount->amount / 100.0f; |
257 | 266 | ||
258 | if (is_horizontal(axis)) { | 267 | if (is_horizontal(axis)) { |
259 | amount->amount = (float)current->width * pct; | 268 | while (parent && parent->pending.layout != L_HORIZ) { |
269 | parent = parent->pending.parent; | ||
270 | } | ||
271 | if (parent) { | ||
272 | amount->amount = (float)parent->pending.width * pct; | ||
273 | } else { | ||
274 | amount->amount = (float)current->pending.workspace->width * pct; | ||
275 | } | ||
260 | } else { | 276 | } else { |
261 | amount->amount = (float)current->height * pct; | 277 | while (parent && parent->pending.layout != L_VERT) { |
278 | parent = parent->pending.parent; | ||
279 | } | ||
280 | if (parent) { | ||
281 | amount->amount = (float)parent->pending.height * pct; | ||
282 | } else { | ||
283 | amount->amount = (float)current->pending.workspace->height * pct; | ||
284 | } | ||
262 | } | 285 | } |
263 | } | 286 | } |
264 | 287 | ||
@@ -277,24 +300,29 @@ static struct cmd_results *resize_adjust_tiled(uint32_t axis, | |||
277 | */ | 300 | */ |
278 | static struct cmd_results *resize_set_tiled(struct sway_container *con, | 301 | static struct cmd_results *resize_set_tiled(struct sway_container *con, |
279 | struct movement_amount *width, struct movement_amount *height) { | 302 | struct movement_amount *width, struct movement_amount *height) { |
303 | |||
304 | if (container_is_scratchpad_hidden_or_child(con)) { | ||
305 | return cmd_results_new(CMD_FAILURE, "Cannot resize a hidden scratchpad container"); | ||
306 | } | ||
307 | |||
280 | if (width->amount) { | 308 | if (width->amount) { |
281 | if (width->unit == MOVEMENT_UNIT_PPT || | 309 | if (width->unit == MOVEMENT_UNIT_PPT || |
282 | width->unit == MOVEMENT_UNIT_DEFAULT) { | 310 | width->unit == MOVEMENT_UNIT_DEFAULT) { |
283 | // Convert to px | 311 | // Convert to px |
284 | struct sway_container *parent = con->parent; | 312 | struct sway_container *parent = con->pending.parent; |
285 | while (parent && parent->layout != L_HORIZ) { | 313 | while (parent && parent->pending.layout != L_HORIZ) { |
286 | parent = parent->parent; | 314 | parent = parent->pending.parent; |
287 | } | 315 | } |
288 | if (parent) { | 316 | if (parent) { |
289 | width->amount = parent->width * width->amount / 100; | 317 | width->amount = parent->pending.width * width->amount / 100; |
290 | } else { | 318 | } else { |
291 | width->amount = con->workspace->width * width->amount / 100; | 319 | width->amount = con->pending.workspace->width * width->amount / 100; |
292 | } | 320 | } |
293 | width->unit = MOVEMENT_UNIT_PX; | 321 | width->unit = MOVEMENT_UNIT_PX; |
294 | } | 322 | } |
295 | if (width->unit == MOVEMENT_UNIT_PX) { | 323 | if (width->unit == MOVEMENT_UNIT_PX) { |
296 | container_resize_tiled(con, AXIS_HORIZONTAL, | 324 | container_resize_tiled(con, AXIS_HORIZONTAL, |
297 | width->amount - con->width); | 325 | width->amount - con->pending.width); |
298 | } | 326 | } |
299 | } | 327 | } |
300 | 328 | ||
@@ -302,20 +330,20 @@ static struct cmd_results *resize_set_tiled(struct sway_container *con, | |||
302 | if (height->unit == MOVEMENT_UNIT_PPT || | 330 | if (height->unit == MOVEMENT_UNIT_PPT || |
303 | height->unit == MOVEMENT_UNIT_DEFAULT) { | 331 | height->unit == MOVEMENT_UNIT_DEFAULT) { |
304 | // Convert to px | 332 | // Convert to px |
305 | struct sway_container *parent = con->parent; | 333 | struct sway_container *parent = con->pending.parent; |
306 | while (parent && parent->layout != L_VERT) { | 334 | while (parent && parent->pending.layout != L_VERT) { |
307 | parent = parent->parent; | 335 | parent = parent->pending.parent; |
308 | } | 336 | } |
309 | if (parent) { | 337 | if (parent) { |
310 | height->amount = parent->height * height->amount / 100; | 338 | height->amount = parent->pending.height * height->amount / 100; |
311 | } else { | 339 | } else { |
312 | height->amount = con->workspace->height * height->amount / 100; | 340 | height->amount = con->pending.workspace->height * height->amount / 100; |
313 | } | 341 | } |
314 | height->unit = MOVEMENT_UNIT_PX; | 342 | height->unit = MOVEMENT_UNIT_PX; |
315 | } | 343 | } |
316 | if (height->unit == MOVEMENT_UNIT_PX) { | 344 | if (height->unit == MOVEMENT_UNIT_PX) { |
317 | container_resize_tiled(con, AXIS_VERTICAL, | 345 | container_resize_tiled(con, AXIS_VERTICAL, |
318 | height->amount - con->height); | 346 | height->amount - con->pending.height); |
319 | } | 347 | } |
320 | } | 348 | } |
321 | 349 | ||
@@ -339,15 +367,15 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, | |||
339 | "Cannot resize a hidden scratchpad container by ppt"); | 367 | "Cannot resize a hidden scratchpad container by ppt"); |
340 | } | 368 | } |
341 | // Convert to px | 369 | // Convert to px |
342 | width->amount = con->workspace->width * width->amount / 100; | 370 | width->amount = con->pending.workspace->width * width->amount / 100; |
343 | width->unit = MOVEMENT_UNIT_PX; | 371 | width->unit = MOVEMENT_UNIT_PX; |
344 | // Falls through | 372 | // Falls through |
345 | case MOVEMENT_UNIT_PX: | 373 | case MOVEMENT_UNIT_PX: |
346 | case MOVEMENT_UNIT_DEFAULT: | 374 | case MOVEMENT_UNIT_DEFAULT: |
347 | width->amount = fmax(min_width, fmin(width->amount, max_width)); | 375 | width->amount = fmax(min_width, fmin(width->amount, max_width)); |
348 | grow_width = width->amount - con->width; | 376 | grow_width = width->amount - con->pending.width; |
349 | con->x -= grow_width / 2; | 377 | con->pending.x -= grow_width / 2; |
350 | con->width = width->amount; | 378 | con->pending.width = width->amount; |
351 | break; | 379 | break; |
352 | case MOVEMENT_UNIT_INVALID: | 380 | case MOVEMENT_UNIT_INVALID: |
353 | sway_assert(false, "invalid width unit"); | 381 | sway_assert(false, "invalid width unit"); |
@@ -363,15 +391,15 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, | |||
363 | "Cannot resize a hidden scratchpad container by ppt"); | 391 | "Cannot resize a hidden scratchpad container by ppt"); |
364 | } | 392 | } |
365 | // Convert to px | 393 | // Convert to px |
366 | height->amount = con->workspace->height * height->amount / 100; | 394 | height->amount = con->pending.workspace->height * height->amount / 100; |
367 | height->unit = MOVEMENT_UNIT_PX; | 395 | height->unit = MOVEMENT_UNIT_PX; |
368 | // Falls through | 396 | // Falls through |
369 | case MOVEMENT_UNIT_PX: | 397 | case MOVEMENT_UNIT_PX: |
370 | case MOVEMENT_UNIT_DEFAULT: | 398 | case MOVEMENT_UNIT_DEFAULT: |
371 | height->amount = fmax(min_height, fmin(height->amount, max_height)); | 399 | height->amount = fmax(min_height, fmin(height->amount, max_height)); |
372 | grow_height = height->amount - con->height; | 400 | grow_height = height->amount - con->pending.height; |
373 | con->y -= grow_height / 2; | 401 | con->pending.y -= grow_height / 2; |
374 | con->height = height->amount; | 402 | con->pending.height = height->amount; |
375 | break; | 403 | break; |
376 | case MOVEMENT_UNIT_INVALID: | 404 | case MOVEMENT_UNIT_INVALID: |
377 | sway_assert(false, "invalid height unit"); | 405 | sway_assert(false, "invalid height unit"); |
@@ -379,10 +407,10 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, | |||
379 | } | 407 | } |
380 | } | 408 | } |
381 | 409 | ||
382 | con->content_x -= grow_width / 2; | 410 | con->pending.content_x -= grow_width / 2; |
383 | con->content_y -= grow_height / 2; | 411 | con->pending.content_y -= grow_height / 2; |
384 | con->content_width += grow_width; | 412 | con->pending.content_width += grow_width; |
385 | con->content_height += grow_height; | 413 | con->pending.content_height += grow_height; |
386 | 414 | ||
387 | arrange_container(con); | 415 | arrange_container(con); |
388 | 416 | ||
@@ -415,7 +443,7 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) { | |||
415 | argc -= num_consumed_args; | 443 | argc -= num_consumed_args; |
416 | argv += num_consumed_args; | 444 | argv += num_consumed_args; |
417 | if (width.unit == MOVEMENT_UNIT_INVALID) { | 445 | if (width.unit == MOVEMENT_UNIT_INVALID) { |
418 | return cmd_results_new(CMD_INVALID, usage); | 446 | return cmd_results_new(CMD_INVALID, "%s", usage); |
419 | } | 447 | } |
420 | } | 448 | } |
421 | 449 | ||
@@ -427,20 +455,20 @@ static struct cmd_results *cmd_resize_set(int argc, char **argv) { | |||
427 | } | 455 | } |
428 | int num_consumed_args = parse_movement_amount(argc, argv, &height); | 456 | int num_consumed_args = parse_movement_amount(argc, argv, &height); |
429 | if (argc > num_consumed_args) { | 457 | if (argc > num_consumed_args) { |
430 | return cmd_results_new(CMD_INVALID, usage); | 458 | return cmd_results_new(CMD_INVALID, "%s", usage); |
431 | } | 459 | } |
432 | if (width.unit == MOVEMENT_UNIT_INVALID) { | 460 | if (width.unit == MOVEMENT_UNIT_INVALID) { |
433 | return cmd_results_new(CMD_INVALID, usage); | 461 | return cmd_results_new(CMD_INVALID, "%s", usage); |
434 | } | 462 | } |
435 | } | 463 | } |
436 | 464 | ||
437 | // If 0, don't resize that dimension | 465 | // If 0, don't resize that dimension |
438 | struct sway_container *con = config->handler_context.container; | 466 | struct sway_container *con = config->handler_context.container; |
439 | if (width.amount <= 0) { | 467 | if (width.amount <= 0) { |
440 | width.amount = con->width; | 468 | width.amount = con->pending.width; |
441 | } | 469 | } |
442 | if (height.amount <= 0) { | 470 | if (height.amount <= 0) { |
443 | height.amount = con->height; | 471 | height.amount = con->pending.height; |
444 | } | 472 | } |
445 | 473 | ||
446 | if (container_is_floating(con)) { | 474 | if (container_is_floating(con)) { |
@@ -462,7 +490,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv, | |||
462 | "[<amount> px|ppt [or <amount> px|ppt]]'"; | 490 | "[<amount> px|ppt [or <amount> px|ppt]]'"; |
463 | uint32_t axis = parse_resize_axis(*argv); | 491 | uint32_t axis = parse_resize_axis(*argv); |
464 | if (axis == WLR_EDGE_NONE) { | 492 | if (axis == WLR_EDGE_NONE) { |
465 | return cmd_results_new(CMD_INVALID, usage); | 493 | return cmd_results_new(CMD_INVALID, "%s", usage); |
466 | } | 494 | } |
467 | --argc; ++argv; | 495 | --argc; ++argv; |
468 | 496 | ||
@@ -473,7 +501,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv, | |||
473 | argc -= num_consumed_args; | 501 | argc -= num_consumed_args; |
474 | argv += num_consumed_args; | 502 | argv += num_consumed_args; |
475 | if (first_amount.unit == MOVEMENT_UNIT_INVALID) { | 503 | if (first_amount.unit == MOVEMENT_UNIT_INVALID) { |
476 | return cmd_results_new(CMD_INVALID, usage); | 504 | return cmd_results_new(CMD_INVALID, "%s", usage); |
477 | } | 505 | } |
478 | } else { | 506 | } else { |
479 | first_amount.amount = 10; | 507 | first_amount.amount = 10; |
@@ -483,7 +511,7 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv, | |||
483 | // "or" | 511 | // "or" |
484 | if (argc) { | 512 | if (argc) { |
485 | if (strcmp(*argv, "or") != 0) { | 513 | if (strcmp(*argv, "or") != 0) { |
486 | return cmd_results_new(CMD_INVALID, usage); | 514 | return cmd_results_new(CMD_INVALID, "%s", usage); |
487 | } | 515 | } |
488 | --argc; ++argv; | 516 | --argc; ++argv; |
489 | } | 517 | } |
@@ -493,10 +521,10 @@ static struct cmd_results *cmd_resize_adjust(int argc, char **argv, | |||
493 | if (argc) { | 521 | if (argc) { |
494 | int num_consumed_args = parse_movement_amount(argc, argv, &second_amount); | 522 | int num_consumed_args = parse_movement_amount(argc, argv, &second_amount); |
495 | if (argc > num_consumed_args) { | 523 | if (argc > num_consumed_args) { |
496 | return cmd_results_new(CMD_INVALID, usage); | 524 | return cmd_results_new(CMD_INVALID, "%s", usage); |
497 | } | 525 | } |
498 | if (second_amount.unit == MOVEMENT_UNIT_INVALID) { | 526 | if (second_amount.unit == MOVEMENT_UNIT_INVALID) { |
499 | return cmd_results_new(CMD_INVALID, usage); | 527 | return cmd_results_new(CMD_INVALID, "%s", usage); |
500 | } | 528 | } |
501 | } else { | 529 | } else { |
502 | second_amount.amount = 0; | 530 | second_amount.amount = 0; |
@@ -566,5 +594,5 @@ struct cmd_results *cmd_resize(int argc, char **argv) { | |||
566 | const char usage[] = "Expected 'resize <shrink|grow> " | 594 | const char usage[] = "Expected 'resize <shrink|grow> " |
567 | "<width|height|up|down|left|right> [<amount>] [px|ppt]'"; | 595 | "<width|height|up|down|left|right> [<amount>] [px|ppt]'"; |
568 | 596 | ||
569 | return cmd_results_new(CMD_INVALID, usage); | 597 | return cmd_results_new(CMD_INVALID, "%s", usage); |
570 | } | 598 | } |