summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 12:34:01 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-03 12:34:01 -0400
commit09d448ea2df60b7e4504b1ec4728e7f1df0244b7 (patch)
tree7555d93cbc9f701a173044dc3d4e437d1db95f67
parentmove view and workspace destructors to container.c (diff)
downloadsway-09d448ea2df60b7e4504b1ec4728e7f1df0244b7.tar.gz
sway-09d448ea2df60b7e4504b1ec4728e7f1df0244b7.tar.zst
sway-09d448ea2df60b7e4504b1ec4728e7f1df0244b7.zip
unify container destroy functions
-rw-r--r--include/sway/tree/container.h2
-rw-r--r--sway/config/output.c2
-rw-r--r--sway/desktop/output.c4
-rw-r--r--sway/tree/container.c37
-rw-r--r--sway/tree/output.c36
5 files changed, 40 insertions, 41 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 278505ce..c6393dc0 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -133,8 +133,6 @@ struct sway_container *container_destroy(struct sway_container *container);
133// TODO make me private 133// TODO make me private
134struct sway_container *container_finish(struct sway_container *cont); 134struct sway_container *container_finish(struct sway_container *cont);
135 135
136struct sway_container *container_output_destroy(struct sway_container *container);
137
138struct sway_container *container_close(struct sway_container *container); 136struct sway_container *container_close(struct sway_container *container);
139 137
140// TODO move to layout.c 138// TODO move to layout.c
diff --git a/sway/config/output.c b/sway/config/output.c
index b4e56efa..c4b74ce2 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -127,7 +127,7 @@ void apply_output_config(struct output_config *oc, struct sway_container *output
127 if (oc && oc->enabled == 0) { 127 if (oc && oc->enabled == 0) {
128 wlr_output_layout_remove(root_container.sway_root->output_layout, 128 wlr_output_layout_remove(root_container.sway_root->output_layout,
129 wlr_output); 129 wlr_output);
130 container_output_destroy(output); 130 container_destroy(output);
131 return; 131 return;
132 } 132 }
133 133
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 10ed1f6d..a1f89cf9 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -338,12 +338,12 @@ void output_damage_whole_view(struct sway_output *output,
338static void damage_handle_destroy(struct wl_listener *listener, void *data) { 338static void damage_handle_destroy(struct wl_listener *listener, void *data) {
339 struct sway_output *output = 339 struct sway_output *output =
340 wl_container_of(listener, output, damage_destroy); 340 wl_container_of(listener, output, damage_destroy);
341 container_output_destroy(output->swayc); 341 container_destroy(output->swayc);
342} 342}
343 343
344static void handle_destroy(struct wl_listener *listener, void *data) { 344static void handle_destroy(struct wl_listener *listener, void *data) {
345 struct sway_output *output = wl_container_of(listener, output, destroy); 345 struct sway_output *output = wl_container_of(listener, output, destroy);
346 container_output_destroy(output->swayc); 346 container_destroy(output->swayc);
347} 347}
348 348
349static void handle_mode(struct wl_listener *listener, void *data) { 349static void handle_mode(struct wl_listener *listener, void *data) {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index c1ebf4f1..1c41bf5d 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -109,6 +109,43 @@ struct sway_container *container_finish(struct sway_container *cont) {
109 free(cont); 109 free(cont);
110 return parent; 110 return parent;
111} 111}
112
113static struct sway_container *container_output_destroy(struct sway_container *output) {
114 if (!sway_assert(output, "cannot destroy null output")) {
115 return NULL;
116 }
117
118 if (output->children->length > 0) {
119 // TODO save workspaces when there are no outputs.
120 // TODO also check if there will ever be no outputs except for exiting
121 // program
122 if (root_container.children->length > 1) {
123 int p = root_container.children->items[0] == output;
124 // Move workspace from this output to another output
125 while (output->children->length) {
126 struct sway_container *child = output->children->items[0];
127 container_remove_child(child);
128 container_add_child(root_container.children->items[p], child);
129 }
130 container_sort_workspaces(root_container.children->items[p]);
131 arrange_windows(root_container.children->items[p],
132 -1, -1);
133 }
134 }
135
136 wl_list_remove(&output->sway_output->destroy.link);
137 wl_list_remove(&output->sway_output->mode.link);
138 wl_list_remove(&output->sway_output->transform.link);
139 wl_list_remove(&output->sway_output->scale.link);
140
141 wl_list_remove(&output->sway_output->damage_destroy.link);
142 wl_list_remove(&output->sway_output->damage_frame.link);
143
144 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
145 container_finish(output);
146 return &root_container;
147}
148
112static struct sway_container *container_workspace_destroy( 149static struct sway_container *container_workspace_destroy(
113 struct sway_container *workspace) { 150 struct sway_container *workspace) {
114 if (!sway_assert(workspace, "cannot destroy null workspace")) { 151 if (!sway_assert(workspace, "cannot destroy null workspace")) {
diff --git a/sway/tree/output.c b/sway/tree/output.c
index 0509db23..af17b856 100644
--- a/sway/tree/output.c
+++ b/sway/tree/output.c
@@ -4,42 +4,6 @@
4#include "sway/output.h" 4#include "sway/output.h"
5#include "log.h" 5#include "log.h"
6 6
7struct sway_container *container_output_destroy(struct sway_container *output) {
8 if (!sway_assert(output, "cannot destroy null output")) {
9 return NULL;
10 }
11
12 if (output->children->length > 0) {
13 // TODO save workspaces when there are no outputs.
14 // TODO also check if there will ever be no outputs except for exiting
15 // program
16 if (root_container.children->length > 1) {
17 int p = root_container.children->items[0] == output;
18 // Move workspace from this output to another output
19 while (output->children->length) {
20 struct sway_container *child = output->children->items[0];
21 container_remove_child(child);
22 container_add_child(root_container.children->items[p], child);
23 }
24 container_sort_workspaces(root_container.children->items[p]);
25 arrange_windows(root_container.children->items[p],
26 -1, -1);
27 }
28 }
29
30 wl_list_remove(&output->sway_output->destroy.link);
31 wl_list_remove(&output->sway_output->mode.link);
32 wl_list_remove(&output->sway_output->transform.link);
33 wl_list_remove(&output->sway_output->scale.link);
34
35 wl_list_remove(&output->sway_output->damage_destroy.link);
36 wl_list_remove(&output->sway_output->damage_frame.link);
37
38 wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
39 container_destroy(output);
40 return &root_container;
41}
42
43struct sway_container *output_by_name(const char *name) { 7struct sway_container *output_by_name(const char *name) {
44 for (int i = 0; i < root_container.children->length; ++i) { 8 for (int i = 0; i < root_container.children->length; ++i) {
45 struct sway_container *output = root_container.children->items[i]; 9 struct sway_container *output = root_container.children->items[i];