aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-08-28 07:41:36 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-08-28 07:41:36 -0400
commit9751fff5c51ba9e4d046e3fd3df5dd3f07ab069b (patch)
treef24d9614b7d0be9163d0abe224f8aa283aff9238
parentMerge pull request #144 from Luminarys/master (diff)
parentforgot visibility of floating containers (diff)
downloadsway-9751fff5c51ba9e4d046e3fd3df5dd3f07ab069b.tar.gz
sway-9751fff5c51ba9e4d046e3fd3df5dd3f07ab069b.tar.zst
sway-9751fff5c51ba9e4d046e3fd3df5dd3f07ab069b.zip
Merge pull request #145 from taiyu-len/master
use previous output containers
-rw-r--r--include/container.h5
-rw-r--r--sway/container.c131
-rw-r--r--sway/focus.c20
-rw-r--r--sway/layout.c2
4 files changed, 115 insertions, 43 deletions
diff --git a/include/container.h b/include/container.h
index 6c0de104..cfb2e868 100644
--- a/include/container.h
+++ b/include/container.h
@@ -94,6 +94,7 @@ swayc_t *swayc_focus_by_layout(swayc_t *container, enum swayc_layouts);
94 94
95 95
96swayc_t *swayc_by_handle(wlc_handle handle); 96swayc_t *swayc_by_handle(wlc_handle handle);
97swayc_t *swayc_by_name(const char *name);
97swayc_t *swayc_active_output(void); 98swayc_t *swayc_active_output(void);
98swayc_t *swayc_active_workspace(void); 99swayc_t *swayc_active_workspace(void);
99swayc_t *swayc_active_workspace_for(swayc_t *view); 100swayc_t *swayc_active_workspace_for(swayc_t *view);
@@ -102,6 +103,10 @@ swayc_t *swayc_active_workspace_for(swayc_t *view);
102 103
103bool swayc_is_fullscreen(swayc_t *view); 104bool swayc_is_fullscreen(swayc_t *view);
104bool 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);
105 110
106// Mapping functions 111// Mapping functions
107 112
diff --git a/sway/container.c b/sway/container.c
index abbd5504..d60aa6ff 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -57,6 +57,19 @@ static void free_swayc(swayc_t *cont) {
57swayc_t *new_output(wlc_handle handle) { 57swayc_t *new_output(wlc_handle handle) {
58 const struct wlc_size *size = wlc_output_get_resolution(handle); 58 const struct wlc_size *size = wlc_output_get_resolution(handle);
59 const char *name = wlc_output_get_name(handle); 59 const char *name = wlc_output_get_name(handle);
60 // Find current outputs to see if this already exists
61 {
62 int i, len = root_container.children->length;
63 for (i = 0; i < len; ++i) {
64 swayc_t *op = root_container.children->items[i];
65 const char *op_name = op->name;
66 if (op_name && name && strcmp(op_name, name) == 0) {
67 sway_log(L_DEBUG, "restoring output %lu:%s", handle, op_name);
68 return op;
69 }
70 }
71 }
72
60 sway_log(L_DEBUG, "Added output %lu:%s", handle, name); 73 sway_log(L_DEBUG, "Added output %lu:%s", handle, name);
61 74
62 struct output_config *oc = NULL; 75 struct output_config *oc = NULL;
@@ -329,7 +342,7 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
329 342
330 // Do not destroy if there are children 343 // Do not destroy if there are children
331 if (workspace->children->length == 0 && workspace->floating->length == 0) { 344 if (workspace->children->length == 0 && workspace->floating->length == 0) {
332 sway_log(L_DEBUG, "'%s'", workspace->name); 345 sway_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
333 swayc_t *parent = workspace->parent; 346 swayc_t *parent = workspace->parent;
334 free_swayc(workspace); 347 free_swayc(workspace);
335 return parent; 348 return parent;
@@ -396,6 +409,17 @@ swayc_t *swayc_by_test(swayc_t *container, bool (*test)(swayc_t *view, void *dat
396 return NULL; 409 return NULL;
397} 410}
398 411
412static bool test_name(swayc_t *view, void *data) {
413 if (!view && !view->name) {
414 return false;
415 }
416 return strcmp(view->name, data) == 0;
417}
418
419swayc_t *swayc_by_name(const char *name) {
420 return swayc_by_test(&root_container, test_name, (void *)name);
421}
422
399swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { 423swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
400 if (!ASSERT_NONNULL(container)) { 424 if (!ASSERT_NONNULL(container)) {
401 return NULL; 425 return NULL;
@@ -523,6 +547,20 @@ bool swayc_is_active(swayc_t *view) {
523 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);
524} 548}
525 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
526// Mapping 564// Mapping
527 565
528void 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) {
@@ -544,43 +582,72 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
544 } 582 }
545} 583}
546 584
547void set_view_visibility(swayc_t *view, void *data) { 585void update_visibility_output(swayc_t *container, wlc_handle output) {
548 if (!ASSERT_NONNULL(view)) { 586 // Inherit visibility
549 return; 587 swayc_t *parent = container->parent;
550 } 588 container->visible = parent->visible;
551 // TODO add something like this. 589 // special cases where visibility depends on focus
552// if (container->type == C_ROOT) { 590 if (parent->type == C_OUTPUT
553// container->visible = true; 591 || parent->layout == L_TABBED
554// } else { 592 || parent->layout == L_STACKED) {
555// // Inherit visibility 593 container->visible = parent->focused == container;
556// swayc_t *parent = container->parent; 594 }
557// container->visible = parent->visible; 595 // Set visibility and output for view
558// // special cases where visibility depends on focus 596 if (container->type == C_VIEW) {
559// if (parent->type == C_OUTPUT || parent->layout == L_TABBED || 597 wlc_view_set_output(container->handle, output);
560// parent->layout == L_STACKED) { 598 wlc_view_set_mask(container->handle, container->visible ? VISIBLE : 0);
561// container->visible = parent->focused == container; 599 if (container->visible) {
562// } 600 wlc_view_bring_to_front(container->handle);
563// }
564 bool visible = *(bool *)data;
565 if (view->type == C_VIEW) {
566 wlc_view_set_output(view->handle, swayc_parent_by_type(view, C_OUTPUT)->handle);
567 wlc_view_set_mask(view->handle, visible ? VISIBLE : 0);
568 if (visible) {
569 wlc_view_bring_to_front(view->handle);
570 } else { 601 } else {
571 wlc_view_send_to_back(view->handle); 602 wlc_view_send_to_back(container->handle);
603 }
604 }
605 // Update visibility for children
606 else {
607 if (container->children) {
608 int i, len = container->children->length;
609 for (i = 0; i < len; ++i) {
610 update_visibility_output(container->children->items[i], output);
611 }
612 }
613 if (container->floating) {
614 int i, len = container->floating->length;
615 for (i = 0; i < len; ++i) {
616 update_visibility_output(container->floating->items[i], output);
617 }
572 } 618 }
573 } 619 }
574 view->visible = visible;
575 sway_log(L_DEBUG, "Container %p is now %s", view, visible ? "visible" : "invisible");
576} 620}
577 621
578void update_visibility(swayc_t *container) { 622void update_visibility(swayc_t *container) {
579 swayc_t *ws = swayc_active_workspace_for(container); 623 if (!container) return;
580 // TODO better visibility setting 624 switch (container->type) {
581 bool visible = (ws->parent->focused == ws); 625 case C_ROOT:
582 sway_log(L_DEBUG, "Setting visibility of container %p to %s", container, visible ? "visible" : "invisible"); 626 container->visible = true;
583 container_map(ws, set_view_visibility, &visible); 627 if (container->children) {
628 int i, len = container->children->length;
629 for (i = 0; i < len; ++i) {
630 update_visibility(container->children->items[i]);
631 }
632 }
633 return;
634
635 case C_OUTPUT:
636 container->visible = true;
637 if (container->children) {
638 int i, len = container->children->length;
639 for (i = 0; i < len; ++i) {
640 update_visibility_output(container->children->items[i], container->handle);
641 }
642 }
643 return;
644
645 default:
646 {
647 swayc_t *op = swayc_parent_by_type(container, C_OUTPUT);
648 update_visibility_output(container, op->handle);
649 }
650 }
584} 651}
585 652
586void reset_gaps(swayc_t *view, void *data) { 653void 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);