summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 21:01:33 -0400
committerLibravatar Tony Crisci <tony@dubstepdish.com>2018-04-02 21:01:33 -0400
commit2c165e1288cbb60f5e677595e35f58a9c56c7010 (patch)
tree8dc7105631a62ce2635bb18cf26abea5d02e7837
parentcleanup split command handlers (diff)
downloadsway-2c165e1288cbb60f5e677595e35f58a9c56c7010.tar.gz
sway-2c165e1288cbb60f5e677595e35f58a9c56c7010.tar.zst
sway-2c165e1288cbb60f5e677595e35f58a9c56c7010.zip
fix more close segfaults
-rw-r--r--include/sway/tree/container.h2
-rw-r--r--sway/commands/kill.c5
-rw-r--r--sway/tree/container.c37
-rw-r--r--sway/tree/layout.c2
-rw-r--r--sway/tree/view.c2
5 files changed, 41 insertions, 7 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h
index 464f80c4..5d15f12b 100644
--- a/include/sway/tree/container.h
+++ b/include/sway/tree/container.h
@@ -134,6 +134,8 @@ struct sway_container *container_workspace_destroy(struct sway_container *contai
134struct sway_container *container_output_destroy(struct sway_container *container); 134struct sway_container *container_output_destroy(struct sway_container *container);
135struct sway_container *container_view_destroy(struct sway_container *container); 135struct sway_container *container_view_destroy(struct sway_container *container);
136 136
137struct sway_container *container_close(struct sway_container *container);
138
137// TODO move to layout.c 139// TODO move to layout.c
138struct sway_container *container_set_layout(struct sway_container *container, 140struct sway_container *container_set_layout(struct sway_container *container,
139 enum sway_container_layout layout); 141 enum sway_container_layout layout);
diff --git a/sway/commands/kill.c b/sway/commands/kill.c
index 46d6e98e..811c3e6b 100644
--- a/sway/commands/kill.c
+++ b/sway/commands/kill.c
@@ -19,11 +19,8 @@ struct cmd_results *cmd_kill(int argc, char **argv) {
19 "Can only kill views and containers with this command"); 19 "Can only kill views and containers with this command");
20 break; 20 break;
21 case C_CONTAINER: 21 case C_CONTAINER:
22 con = container_destroy(con);
23 arrange_windows(con, -1, -1);
24 break;
25 case C_VIEW: 22 case C_VIEW:
26 view_close(con->sway_view); 23 container_close(con);
27 break; 24 break;
28 } 25 }
29 26
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 4db93ce8..8688edd6 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -112,10 +112,45 @@ static struct sway_container *_container_destroy(struct sway_container *cont) {
112struct sway_container *container_destroy(struct sway_container *cont) { 112struct sway_container *container_destroy(struct sway_container *cont) {
113 struct sway_container *parent = _container_destroy(cont); 113 struct sway_container *parent = _container_destroy(cont);
114 parent = container_reap_empty(parent); 114 parent = container_reap_empty(parent);
115 arrange_windows(&root_container, -1, -1);
116 return parent; 115 return parent;
117} 116}
118 117
118static void container_close_func(struct sway_container *container, void *data) {
119 if (container->type == C_VIEW) {
120 view_close(container->sway_view);
121 }
122}
123
124struct sway_container *container_close(struct sway_container *con) {
125 if (!sway_assert(con != NULL, "container_close called with a NULL container")) {
126 return NULL;
127 }
128
129 switch (con->type) {
130 case C_TYPES:
131 wlr_log(L_ERROR, "tried to close an invalid container");
132 break;
133 case C_ROOT:
134 wlr_log(L_ERROR, "tried to close the root container");
135 break;
136 case C_OUTPUT:
137 container_output_destroy(con);
138 break;
139 case C_WORKSPACE:
140 container_workspace_destroy(con);
141 break;
142 case C_CONTAINER:
143 container_for_each_descendant_dfs(con, container_close_func, NULL);
144 break;
145 case C_VIEW:
146 view_close(con->sway_view);
147 break;
148
149 }
150
151 return con->parent;
152}
153
119struct sway_container *container_output_create( 154struct sway_container *container_output_create(
120 struct sway_output *sway_output) { 155 struct sway_output *sway_output) {
121 struct wlr_box size; 156 struct wlr_box size;
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 95a84d12..b0ce4aaf 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -110,7 +110,7 @@ struct sway_container *container_reap_empty(struct sway_container *container) {
110 wlr_log(L_DEBUG, "Reaping %p %s '%s'", container, 110 wlr_log(L_DEBUG, "Reaping %p %s '%s'", container,
111 container_type_to_str(container->type), container->name); 111 container_type_to_str(container->type), container->name);
112 while (container->type != C_ROOT && container->type != C_OUTPUT 112 while (container->type != C_ROOT && container->type != C_OUTPUT
113 && container->children->length == 0) { 113 && container->children && container->children->length == 0) {
114 if (container->type == C_WORKSPACE) { 114 if (container->type == C_WORKSPACE) {
115 if (!workspace_is_visible(container)) { 115 if (!workspace_is_visible(container)) {
116 struct sway_container *parent = container->parent; 116 struct sway_container *parent = container->parent;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 09c804e4..4e695b5f 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -84,7 +84,7 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
84 } 84 }
85 wlr_log(L_DEBUG, "Destroying view '%s'", view->name); 85 wlr_log(L_DEBUG, "Destroying view '%s'", view->name);
86 struct sway_container *parent = container_destroy(view); 86 struct sway_container *parent = container_destroy(view);
87 arrange_windows(parent, -1, -1); 87 arrange_windows(&root_container, -1, -1);
88 return parent; 88 return parent;
89} 89}
90 90