diff options
author | 2015-08-27 23:18:28 -0700 | |
---|---|---|
committer | 2015-08-27 23:18:28 -0700 | |
commit | 5678d824e43d1ae2e2abaa1bc9a03391a4683a86 (patch) | |
tree | c097bfa46406f94903e942832e36bd3e96d343bb /sway/container.c | |
parent | proper visibility update (diff) | |
download | sway-5678d824e43d1ae2e2abaa1bc9a03391a4683a86.tar.gz sway-5678d824e43d1ae2e2abaa1bc9a03391a4683a86.tar.zst sway-5678d824e43d1ae2e2abaa1bc9a03391a4683a86.zip |
update visibility + container info functions
Diffstat (limited to 'sway/container.c')
-rw-r--r-- | sway/container.c | 104 |
1 files changed, 62 insertions, 42 deletions
diff --git a/sway/container.c b/sway/container.c index d6d27033..19a40090 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -547,6 +547,20 @@ bool swayc_is_active(swayc_t *view) { | |||
547 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED); | 547 | return view && view->type == C_VIEW && (wlc_view_get_state(view->handle) & WLC_BIT_ACTIVATED); |
548 | } | 548 | } |
549 | 549 | ||
550 | bool swayc_is_parent_of(swayc_t *parent, swayc_t *child) { | ||
551 | while (child != &root_container) { | ||
552 | child = child->parent; | ||
553 | if (child == parent) { | ||
554 | return true; | ||
555 | } | ||
556 | } | ||
557 | return false; | ||
558 | } | ||
559 | |||
560 | bool swayc_is_child_of(swayc_t *child, swayc_t *parent) { | ||
561 | return swayc_is_parent_of(parent, child); | ||
562 | } | ||
563 | |||
550 | // Mapping | 564 | // Mapping |
551 | 565 | ||
552 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { | 566 | void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { |
@@ -568,58 +582,64 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi | |||
568 | } | 582 | } |
569 | } | 583 | } |
570 | 584 | ||
571 | void set_view_visibility(swayc_t *view, void *data) { | 585 | void update_visibility_output(swayc_t *container, wlc_handle output) { |
572 | if (!ASSERT_NONNULL(view)) { | 586 | // Inherit visibility |
573 | return; | 587 | swayc_t *parent = container->parent; |
574 | } | 588 | container->visible = parent->visible; |
575 | // TODO add something like this. | 589 | // special cases where visibility depends on focus |
576 | // if (container->type == C_ROOT) { | 590 | if (parent->type == C_OUTPUT |
577 | // container->visible = true; | 591 | || parent->layout == L_TABBED |
578 | // } else { | 592 | || parent->layout == L_STACKED) { |
579 | // // Inherit visibility | 593 | container->visible = parent->focused == container; |
580 | // swayc_t *parent = container->parent; | 594 | } |
581 | // container->visible = parent->visible; | 595 | // Set visibility and output for view |
582 | // // special cases where visibility depends on focus | 596 | if (container->type == C_VIEW) { |
583 | // if (parent->type == C_OUTPUT || parent->layout == L_TABBED || | 597 | wlc_view_set_output(container->handle, output); |
584 | // parent->layout == L_STACKED) { | 598 | wlc_view_set_mask(container->handle, container->visible ? VISIBLE : 0); |
585 | // container->visible = parent->focused == container; | 599 | if (container->visible) { |
586 | // } | 600 | wlc_view_bring_to_front(container->handle); |
587 | // } | ||
588 | bool visible = *(bool *)data; | ||
589 | if (view->type == C_VIEW) { | ||
590 | wlc_view_set_output(view->handle, swayc_parent_by_type(view, C_OUTPUT)->handle); | ||
591 | wlc_view_set_mask(view->handle, visible ? VISIBLE : 0); | ||
592 | if (visible) { | ||
593 | wlc_view_bring_to_front(view->handle); | ||
594 | } else { | 601 | } else { |
595 | wlc_view_send_to_back(view->handle); | 602 | wlc_view_send_to_back(container->handle); |
603 | } | ||
604 | } | ||
605 | // Update visibility for children | ||
606 | else if (container->children) { | ||
607 | int i, len = container->children->length; | ||
608 | for (i = 0; i < len; ++i) { | ||
609 | update_visibility_output(container->children->items[i], output); | ||
596 | } | 610 | } |
597 | } | 611 | } |
598 | view->visible = visible; | ||
599 | sway_log(L_DEBUG, "Container %p is now %s", view, visible ? "visible" : "invisible"); | ||
600 | } | 612 | } |
601 | 613 | ||
602 | void update_visibility(swayc_t *container) { | 614 | void update_visibility(swayc_t *container) { |
603 | if (!container) { | 615 | if (!container) return; |
616 | switch (container->type) { | ||
617 | case C_ROOT: | ||
618 | container->visible = true; | ||
619 | if (container->children) { | ||
620 | int i, len = container->children->length; | ||
621 | for (i = 0; i < len; ++i) { | ||
622 | update_visibility(container->children->items[i]); | ||
623 | } | ||
624 | } | ||
604 | return; | 625 | return; |
605 | } | 626 | |
606 | swayc_t *ws; | 627 | case C_OUTPUT: |
607 | if (container->type == C_ROOT || container->type == C_OUTPUT) { | 628 | container->visible = true; |
608 | int i, len = container->children->length; | 629 | if (container->children) { |
609 | for (i = 0; i < len; ++i) { | 630 | int i, len = container->children->length; |
610 | update_visibility(container->children->items[i]); | 631 | for (i = 0; i < len; ++i) { |
632 | update_visibility_output(container->children->items[i], container->handle); | ||
633 | } | ||
611 | } | 634 | } |
612 | return; | 635 | return; |
613 | } else if (container->type == C_WORKSPACE) { | 636 | |
614 | container->visible = container->parent->focused == container; | 637 | default: |
615 | ws = container; | 638 | { |
616 | } else { | 639 | swayc_t *op = swayc_parent_by_type(container, C_OUTPUT); |
617 | ws = swayc_active_workspace_for(container); | 640 | update_visibility_output(container, op->handle); |
641 | } | ||
618 | } | 642 | } |
619 | // TODO better visibility setting | ||
620 | bool visible = (ws->parent->focused == ws); | ||
621 | sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible"); | ||
622 | container_map(ws, set_view_visibility, &visible); | ||
623 | } | 643 | } |
624 | 644 | ||
625 | void reset_gaps(swayc_t *view, void *data) { | 645 | void reset_gaps(swayc_t *view, void *data) { |