summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/container.h4
-rw-r--r--sway/container.c104
-rw-r--r--sway/focus.c20
-rw-r--r--sway/layout.c2
4 files changed, 77 insertions, 53 deletions
diff --git a/include/container.h b/include/container.h
index 29f75f45..cfb2e868 100644
--- a/include/container.h
+++ b/include/container.h
@@ -103,6 +103,10 @@ swayc_t *swayc_active_workspace_for(swayc_t *view);
103 103
104bool swayc_is_fullscreen(swayc_t *view); 104bool swayc_is_fullscreen(swayc_t *view);
105bool swayc_is_active(swayc_t *view); 105bool swayc_is_active(swayc_t *view);
106// Is `parent` the parent of `child`
107bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
108// Is `child` a child of `parent`
109bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
106 110
107// Mapping functions 111// Mapping functions
108 112
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
550bool 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
560bool 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
552void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 566void 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
571void set_view_visibility(swayc_t *view, void *data) { 585void 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
602void update_visibility(swayc_t *container) { 614void 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
625void reset_gaps(swayc_t *view, void *data) { 645void reset_gaps(swayc_t *view, void *data) {
diff --git a/sway/focus.c b/sway/focus.c
index f7b55b27..45108a11 100644
--- a/sway/focus.c
+++ b/sway/focus.c
@@ -14,6 +14,10 @@ static void update_focus(swayc_t *c) {
14 // Handle if focus switches 14 // Handle if focus switches
15 swayc_t *parent = c->parent; 15 swayc_t *parent = c->parent;
16 if (parent->focused != c) { 16 if (parent->focused != c) {
17 // Get previous focus
18 swayc_t *prev = parent->focused;
19 // Set new focus
20 parent->focused = c;
17 switch (c->type) { 21 switch (c->type) {
18 // Shouldnt happen 22 // Shouldnt happen
19 case C_ROOT: return; 23 case C_ROOT: return;
@@ -25,16 +29,13 @@ static void update_focus(swayc_t *c) {
25 29
26 // Case where workspace changes 30 // Case where workspace changes
27 case C_WORKSPACE: 31 case C_WORKSPACE:
28 if (parent->focused) { 32 if (prev) {
29 swayc_t *ws = parent->focused; 33 // update visibility of old workspace
30 // hide visibility of old workspace 34 update_visibility(prev);
31 bool visible = false; 35 destroy_workspace(prev);
32 container_map(ws, set_view_visibility, &visible);
33 // set visibility of new workspace
34 visible = true;
35 container_map(c, set_view_visibility, &visible);
36 destroy_workspace(ws);
37 } 36 }
37 // Update visibility of newly focused workspace
38 update_visibility(c);
38 break; 39 break;
39 40
40 default: 41 default:
@@ -44,7 +45,6 @@ static void update_focus(swayc_t *c) {
44 // for example, stacked and tabbing change stuff. 45 // for example, stacked and tabbing change stuff.
45 break; 46 break;
46 } 47 }
47 c->parent->focused = c;
48 } 48 }
49} 49}
50 50
diff --git a/sway/layout.c b/sway/layout.c
index 5ade5e63..f04007ed 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -221,7 +221,7 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir
221} 221}
222 222
223void move_container_to(swayc_t* container, swayc_t* destination) { 223void move_container_to(swayc_t* container, swayc_t* destination) {
224 if (container == destination) { 224 if (container == destination && swayc_is_parent_of(container, destination)) {
225 return; 225 return;
226 } 226 }
227 swayc_t *parent = remove_child(container); 227 swayc_t *parent = remove_child(container);