diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-03-31 00:44:17 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-03-31 15:37:16 -0400 |
commit | 7706d83160267be61accb1b6f7bdc2f43299cae7 (patch) | |
tree | 64b9751ee7edf613c9e3a06d1f5446501f4ddbaf /sway/tree/layout.c | |
parent | Merge pull request #1684 from swaywm/follow-warp (diff) | |
download | sway-7706d83160267be61accb1b6f7bdc2f43299cae7.tar.gz sway-7706d83160267be61accb1b6f7bdc2f43299cae7.tar.zst sway-7706d83160267be61accb1b6f7bdc2f43299cae7.zip |
basic split containers
Diffstat (limited to 'sway/tree/layout.c')
-rw-r--r-- | sway/tree/layout.c | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ce0682dc..62df19e9 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
2 | #include <ctype.h> | 3 | #include <ctype.h> |
3 | #include <math.h> | 4 | #include <math.h> |
4 | #include <stdbool.h> | 5 | #include <stdbool.h> |
@@ -100,6 +101,8 @@ void container_add_child(struct sway_container *parent, | |||
100 | parent, parent->type, parent->width, parent->height); | 101 | parent, parent->type, parent->width, parent->height); |
101 | list_add(parent->children, child); | 102 | list_add(parent->children, child); |
102 | child->parent = parent; | 103 | child->parent = parent; |
104 | // TODO: set focus for this container? | ||
105 | sway_input_manager_set_focus(input_manager, child); | ||
103 | } | 106 | } |
104 | 107 | ||
105 | struct sway_container *container_reap_empty(struct sway_container *container) { | 108 | struct sway_container *container_reap_empty(struct sway_container *container) { |
@@ -135,7 +138,7 @@ struct sway_container *container_remove_child(struct sway_container *child) { | |||
135 | } | 138 | } |
136 | } | 139 | } |
137 | child->parent = NULL; | 140 | child->parent = NULL; |
138 | return container_reap_empty(parent); | 141 | return parent; |
139 | } | 142 | } |
140 | 143 | ||
141 | void container_move_to(struct sway_container* container, | 144 | void container_move_to(struct sway_container* container, |
@@ -322,7 +325,12 @@ static void apply_horiz_layout(struct sway_container *container, | |||
322 | wlr_log(L_DEBUG, | 325 | wlr_log(L_DEBUG, |
323 | "Calculating arrangement for %p:%d (will scale %f by %f)", | 326 | "Calculating arrangement for %p:%d (will scale %f by %f)", |
324 | child, child->type, width, scale); | 327 | child, child->type, width, scale); |
325 | view_set_position(child->sway_view, child_x, y); | 328 | if (child->type == C_VIEW) { |
329 | view_set_position(child->sway_view, child_x, y); | ||
330 | } else { | ||
331 | child->x = child_x; | ||
332 | child->y = y; | ||
333 | } | ||
326 | 334 | ||
327 | if (i == end - 1) { | 335 | if (i == end - 1) { |
328 | double remaining_width = x + width - child_x; | 336 | double remaining_width = x + width - child_x; |
@@ -505,9 +513,9 @@ static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { | |||
505 | return NULL; | 513 | return NULL; |
506 | } | 514 | } |
507 | 515 | ||
508 | static struct sway_container *get_swayc_in_direction_under( | 516 | struct sway_container *container_get_in_direction( |
509 | struct sway_container *container, enum movement_direction dir, | 517 | struct sway_container *container, struct sway_seat *seat, |
510 | struct sway_seat *seat, struct sway_container *limit) { | 518 | enum movement_direction dir) { |
511 | if (dir == MOVE_CHILD) { | 519 | if (dir == MOVE_CHILD) { |
512 | return sway_seat_get_focus_inactive(seat, container); | 520 | return sway_seat_get_focus_inactive(seat, container); |
513 | } | 521 | } |
@@ -559,7 +567,6 @@ static struct sway_container *get_swayc_in_direction_under( | |||
559 | 567 | ||
560 | struct sway_container *wrap_candidate = NULL; | 568 | struct sway_container *wrap_candidate = NULL; |
561 | while (true) { | 569 | while (true) { |
562 | // Test if we can even make a difference here | ||
563 | bool can_move = false; | 570 | bool can_move = false; |
564 | int desired; | 571 | int desired; |
565 | int idx = index_child(container); | 572 | int idx = index_child(container); |
@@ -589,7 +596,7 @@ static struct sway_container *get_swayc_in_direction_under( | |||
589 | } | 596 | } |
590 | if (next->children && next->children->length) { | 597 | if (next->children && next->children->length) { |
591 | // TODO consider floating children as well | 598 | // TODO consider floating children as well |
592 | return sway_seat_get_focus_inactive(seat, next); | 599 | return sway_seat_get_focus_by_type(seat, next, C_VIEW); |
593 | } else { | 600 | } else { |
594 | return next; | 601 | return next; |
595 | } | 602 | } |
@@ -619,21 +626,22 @@ static struct sway_container *get_swayc_in_direction_under( | |||
619 | wrap_candidate = parent->children->items[0]; | 626 | wrap_candidate = parent->children->items[0]; |
620 | } | 627 | } |
621 | if (config->force_focus_wrapping) { | 628 | if (config->force_focus_wrapping) { |
622 | return wrap_candidate; | 629 | return sway_seat_get_focus_by_type(seat, wrap_candidate, C_VIEW); |
623 | } | 630 | } |
624 | } | 631 | } |
625 | } else { | 632 | } else { |
626 | wlr_log(L_DEBUG, | 633 | wlr_log(L_DEBUG, |
627 | "cont %d-%p dir %i sibling %d: %p", idx, | 634 | "cont %d-%p dir %i sibling %d: %p", idx, |
628 | container, dir, desired, parent->children->items[desired]); | 635 | container, dir, desired, parent->children->items[desired]); |
629 | return parent->children->items[desired]; | 636 | return sway_seat_get_focus_by_type(seat, |
637 | parent->children->items[desired], C_VIEW); | ||
630 | } | 638 | } |
631 | } | 639 | } |
632 | 640 | ||
633 | if (!can_move) { | 641 | if (!can_move) { |
634 | container = parent; | 642 | container = parent; |
635 | parent = parent->parent; | 643 | parent = parent->parent; |
636 | if (!parent || container == limit) { | 644 | if (!parent) { |
637 | // wrapping is the last chance | 645 | // wrapping is the last chance |
638 | return wrap_candidate; | 646 | return wrap_candidate; |
639 | } | 647 | } |
@@ -641,8 +649,71 @@ static struct sway_container *get_swayc_in_direction_under( | |||
641 | } | 649 | } |
642 | } | 650 | } |
643 | 651 | ||
644 | struct sway_container *container_get_in_direction( | 652 | struct sway_container *container_replace_child(struct sway_container *child, |
645 | struct sway_container *container, struct sway_seat *seat, | 653 | struct sway_container *new_child) { |
646 | enum movement_direction dir) { | 654 | struct sway_container *parent = child->parent; |
647 | return get_swayc_in_direction_under(container, dir, seat, NULL); | 655 | if (parent == NULL) { |
656 | return NULL; | ||
657 | } | ||
658 | int i = index_child(child); | ||
659 | |||
660 | // TODO floating | ||
661 | parent->children->items[i] = new_child; | ||
662 | new_child->parent = parent; | ||
663 | child->parent = NULL; | ||
664 | |||
665 | // Set geometry for new child | ||
666 | new_child->x = child->x; | ||
667 | new_child->y = child->y; | ||
668 | new_child->width = child->width; | ||
669 | new_child->height = child->height; | ||
670 | |||
671 | // reset geometry for child | ||
672 | child->width = 0; | ||
673 | child->height = 0; | ||
674 | |||
675 | return parent; | ||
676 | } | ||
677 | |||
678 | struct sway_container *container_split(struct sway_container *child, | ||
679 | enum sway_container_layout layout) { | ||
680 | // TODO floating: cannot split a floating container | ||
681 | if (!sway_assert(child, "child cannot be null")) { | ||
682 | return NULL; | ||
683 | } | ||
684 | struct sway_container *cont = container_create(C_CONTAINER); | ||
685 | |||
686 | wlr_log(L_DEBUG, "creating container %p around %p", cont, child); | ||
687 | |||
688 | cont->prev_layout = L_NONE; | ||
689 | cont->layout = layout; | ||
690 | cont->width = child->width; | ||
691 | cont->height = child->height; | ||
692 | cont->x = child->x; | ||
693 | cont->y = child->y; | ||
694 | |||
695 | /* Container inherits all of workspaces children, layout and whatnot */ | ||
696 | if (child->type == C_WORKSPACE) { | ||
697 | struct sway_container *workspace = child; | ||
698 | // reorder focus | ||
699 | int i; | ||
700 | for (i = 0; i < workspace->children->length; ++i) { | ||
701 | ((struct sway_container *)workspace->children->items[i])->parent = | ||
702 | cont; | ||
703 | } | ||
704 | |||
705 | // Swap children | ||
706 | list_t *tmp_list = workspace->children; | ||
707 | workspace->children = cont->children; | ||
708 | cont->children = tmp_list; | ||
709 | // add container to workspace chidren | ||
710 | container_add_child(workspace, cont); | ||
711 | // give them proper layouts | ||
712 | cont->layout = workspace->workspace_layout; | ||
713 | cont->prev_layout = workspace->prev_layout; | ||
714 | } else { // Or is built around container | ||
715 | container_replace_child(child, cont); | ||
716 | container_add_child(cont, child); | ||
717 | } | ||
718 | return cont; | ||
648 | } | 719 | } |