diff options
author | 2015-08-22 15:19:02 -0400 | |
---|---|---|
committer | 2015-08-22 15:19:02 -0400 | |
commit | 07229edfe627762df9c27ed2700d737f74bb7b88 (patch) | |
tree | 9808dad1127cd98a8dbe91e7b16f75ccb056c1bb /sway/layout.c | |
parent | Set x/y positions for output containers (diff) | |
download | sway-07229edfe627762df9c27ed2700d737f74bb7b88.tar.gz sway-07229edfe627762df9c27ed2700d737f74bb7b88.tar.zst sway-07229edfe627762df9c27ed2700d737f74bb7b88.zip |
Implement output positioning
:tada:
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 76 |
1 files changed, 67 insertions, 9 deletions
diff --git a/sway/layout.c b/sway/layout.c index 7f3adc31..7a7ccc0e 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -169,8 +169,6 @@ void arrange_windows(swayc_t *container, double width, double height) { | |||
169 | for (i = 0; i < container->children->length; ++i) { | 169 | for (i = 0; i < container->children->length; ++i) { |
170 | swayc_t *child = container->children->items[i]; | 170 | swayc_t *child = container->children->items[i]; |
171 | sway_log(L_DEBUG, "Arranging output at %d", x); | 171 | sway_log(L_DEBUG, "Arranging output at %d", x); |
172 | child->x = x; | ||
173 | child->y = y; | ||
174 | arrange_windows(child, -1, -1); | 172 | arrange_windows(child, -1, -1); |
175 | x += child->width; | 173 | x += child->width; |
176 | } | 174 | } |
@@ -340,19 +338,79 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) | |||
340 | // Test if we can even make a difference here | 338 | // Test if we can even make a difference here |
341 | bool can_move = false; | 339 | bool can_move = false; |
342 | int diff = 0; | 340 | int diff = 0; |
343 | if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { | 341 | int i; |
344 | if (parent->layout == L_HORIZ || parent->type == C_ROOT) { | 342 | if (parent->type == C_ROOT) { |
343 | // Find the next output | ||
344 | int target = -1, max_x = 0, max_y = 0, self = -1; | ||
345 | sway_log(L_DEBUG, "Moving between outputs"); | ||
346 | |||
347 | for (i = 0; i < parent->children->length; ++i) { | ||
348 | swayc_t *next = parent->children->items[i]; | ||
349 | if (next == container) { | ||
350 | self = i; | ||
351 | sway_log(L_DEBUG, "self is %p %d", next, self); | ||
352 | continue; | ||
353 | } | ||
354 | if (next->type == C_OUTPUT) { | ||
355 | sway_log(L_DEBUG, "Testing with %p %d (dir %d)", next, i, dir); | ||
356 | // Check if it's more extreme | ||
357 | if (dir == MOVE_RIGHT) { | ||
358 | if (container->x + container->width <= next->x) { | ||
359 | if (target == -1 || next->x < max_x) { | ||
360 | target = i; | ||
361 | max_x = next->x; | ||
362 | } | ||
363 | } | ||
364 | } else if (dir == MOVE_LEFT) { | ||
365 | sway_log(L_DEBUG, "next->x: %d, next->width: %d, container->x: %d", | ||
366 | (int)next->x, (int)next->width, (int)container->x); | ||
367 | if (container->x > next->x + next->width) { | ||
368 | sway_log(L_DEBUG, "match"); | ||
369 | if (target == -1 || max_x < next->x) { | ||
370 | sway_log(L_DEBUG, "hit"); | ||
371 | target = i; | ||
372 | max_x = next->x; | ||
373 | } | ||
374 | } | ||
375 | } else if (dir == MOVE_DOWN) { | ||
376 | if (container->y + container->height <= next->y) { | ||
377 | if (target == -1 || next->y < max_y) { | ||
378 | target = i; | ||
379 | max_y = next->y; | ||
380 | } | ||
381 | } | ||
382 | } else if (dir == MOVE_UP) { | ||
383 | if (container->y > next->y + next->height) { | ||
384 | if (target == -1 || max_y < next->y) { | ||
385 | target = i; | ||
386 | max_y = next->y; | ||
387 | } | ||
388 | } | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | |||
393 | if (target == -1) { | ||
394 | can_move = false; | ||
395 | } else { | ||
345 | can_move = true; | 396 | can_move = true; |
346 | diff = dir == MOVE_LEFT ? -1 : 1; | 397 | diff = target - self; |
347 | } | 398 | } |
348 | } else { | 399 | } else { |
349 | if (parent->layout == L_VERT) { | 400 | if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { |
350 | can_move = true; | 401 | if (parent->layout == L_HORIZ) { |
351 | diff = dir == MOVE_UP ? -1 : 1; | 402 | can_move = true; |
403 | diff = dir == MOVE_LEFT ? -1 : 1; | ||
404 | } | ||
405 | } else { | ||
406 | if (parent->layout == L_VERT) { | ||
407 | can_move = true; | ||
408 | diff = dir == MOVE_UP ? -1 : 1; | ||
409 | } | ||
352 | } | 410 | } |
353 | } | 411 | } |
412 | |||
354 | if (can_move) { | 413 | if (can_move) { |
355 | int i; | ||
356 | for (i = 0; i < parent->children->length; ++i) { | 414 | for (i = 0; i < parent->children->length; ++i) { |
357 | swayc_t *child = parent->children->items[i]; | 415 | swayc_t *child = parent->children->items[i]; |
358 | if (child == container) { | 416 | if (child == container) { |