diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-04-02 22:37:21 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-04-02 22:37:21 -0400 |
commit | 2992b72d61933568476e2bf4baf573e714f9ed40 (patch) | |
tree | 0682e081d94d73ef2b4b9a7f8d1646c11bb33b8e /sway | |
parent | fix more close segfaults (diff) | |
download | sway-2992b72d61933568476e2bf4baf573e714f9ed40.tar.gz sway-2992b72d61933568476e2bf4baf573e714f9ed40.tar.zst sway-2992b72d61933568476e2bf4baf573e714f9ed40.zip |
change reap container approach
Diffstat (limited to 'sway')
-rw-r--r-- | sway/tree/container.c | 54 | ||||
-rw-r--r-- | sway/tree/layout.c | 29 | ||||
-rw-r--r-- | sway/tree/view.c | 10 |
3 files changed, 58 insertions, 35 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 8688edd6..686a52c7 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -1,4 +1,5 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | 1 | #define _POSIX_C_SOURCE 200809L |
2 | #include <assert.h> | ||
2 | #include <stdint.h> | 3 | #include <stdint.h> |
3 | #include <stdlib.h> | 4 | #include <stdlib.h> |
4 | #include <string.h> | 5 | #include <string.h> |
@@ -109,12 +110,55 @@ static struct sway_container *_container_destroy(struct sway_container *cont) { | |||
109 | return parent; | 110 | return parent; |
110 | } | 111 | } |
111 | 112 | ||
112 | struct sway_container *container_destroy(struct sway_container *cont) { | 113 | static void reap_empty_func(struct sway_container *con, void *data) { |
113 | struct sway_container *parent = _container_destroy(cont); | 114 | switch (con->type) { |
114 | parent = container_reap_empty(parent); | 115 | case C_TYPES: |
116 | case C_ROOT: | ||
117 | case C_OUTPUT: | ||
118 | // dont reap these | ||
119 | break; | ||
120 | case C_WORKSPACE: | ||
121 | if (!workspace_is_visible(con) && con->children->length == 0) { | ||
122 | container_workspace_destroy(con); | ||
123 | } | ||
124 | break; | ||
125 | case C_CONTAINER: | ||
126 | if (con->children->length == 0) { | ||
127 | _container_destroy(con); | ||
128 | } else if (con->children->length == 1) { | ||
129 | struct sway_container *only_child = con->children->items[0]; | ||
130 | if (only_child->type == C_CONTAINER) { | ||
131 | container_remove_child(only_child); | ||
132 | container_replace_child(con, only_child); | ||
133 | _container_destroy(con); | ||
134 | } | ||
135 | } | ||
136 | case C_VIEW: | ||
137 | break; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | struct sway_container *container_reap_empty(struct sway_container *container) { | ||
142 | struct sway_container *parent = container->parent; | ||
143 | |||
144 | container_for_each_descendant_dfs(container, reap_empty_func, NULL); | ||
145 | |||
115 | return parent; | 146 | return parent; |
116 | } | 147 | } |
117 | 148 | ||
149 | void container_destroy(struct sway_container *cont) { | ||
150 | if (cont == NULL) { | ||
151 | return; | ||
152 | } | ||
153 | |||
154 | if (cont->children != NULL && cont->children->length) { | ||
155 | assert(false && "dont destroy containers with children"); | ||
156 | } | ||
157 | |||
158 | _container_destroy(cont); | ||
159 | container_reap_empty(&root_container); | ||
160 | } | ||
161 | |||
118 | static void container_close_func(struct sway_container *container, void *data) { | 162 | static void container_close_func(struct sway_container *container, void *data) { |
119 | if (container->type == C_VIEW) { | 163 | if (container->type == C_VIEW) { |
120 | view_close(container->sway_view); | 164 | view_close(container->sway_view); |
@@ -126,6 +170,8 @@ struct sway_container *container_close(struct sway_container *con) { | |||
126 | return NULL; | 170 | return NULL; |
127 | } | 171 | } |
128 | 172 | ||
173 | struct sway_container *parent = con->parent; | ||
174 | |||
129 | switch (con->type) { | 175 | switch (con->type) { |
130 | case C_TYPES: | 176 | case C_TYPES: |
131 | wlr_log(L_ERROR, "tried to close an invalid container"); | 177 | wlr_log(L_ERROR, "tried to close an invalid container"); |
@@ -148,7 +194,7 @@ struct sway_container *container_close(struct sway_container *con) { | |||
148 | 194 | ||
149 | } | 195 | } |
150 | 196 | ||
151 | return con->parent; | 197 | return parent; |
152 | } | 198 | } |
153 | 199 | ||
154 | struct sway_container *container_output_create( | 200 | struct sway_container *container_output_create( |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index b0ce4aaf..79470f98 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -103,32 +103,6 @@ void container_add_child(struct sway_container *parent, | |||
103 | child->parent = parent; | 103 | child->parent = parent; |
104 | } | 104 | } |
105 | 105 | ||
106 | struct sway_container *container_reap_empty(struct sway_container *container) { | ||
107 | if (container == NULL) { | ||
108 | return NULL; | ||
109 | } | ||
110 | wlr_log(L_DEBUG, "Reaping %p %s '%s'", container, | ||
111 | container_type_to_str(container->type), container->name); | ||
112 | while (container->type != C_ROOT && container->type != C_OUTPUT | ||
113 | && container->children && container->children->length == 0) { | ||
114 | if (container->type == C_WORKSPACE) { | ||
115 | if (!workspace_is_visible(container)) { | ||
116 | struct sway_container *parent = container->parent; | ||
117 | container_workspace_destroy(container); | ||
118 | return parent; | ||
119 | } | ||
120 | return container; | ||
121 | } else if (container->type == C_CONTAINER) { | ||
122 | struct sway_container *parent = container->parent; | ||
123 | container_destroy(container); | ||
124 | container = parent; | ||
125 | } else { | ||
126 | container = container->parent; | ||
127 | } | ||
128 | } | ||
129 | return container; | ||
130 | } | ||
131 | |||
132 | struct sway_container *container_remove_child(struct sway_container *child) { | 106 | struct sway_container *container_remove_child(struct sway_container *child) { |
133 | struct sway_container *parent = child->parent; | 107 | struct sway_container *parent = child->parent; |
134 | for (int i = 0; i < parent->children->length; ++i) { | 108 | for (int i = 0; i < parent->children->length; ++i) { |
@@ -309,6 +283,8 @@ void arrange_windows(struct sway_container *container, | |||
309 | container->children->length); | 283 | container->children->length); |
310 | break; | 284 | break; |
311 | case L_VERT: | 285 | case L_VERT: |
286 | assert(container); | ||
287 | assert(container->children); | ||
312 | apply_vert_layout(container, x, y, width, height, 0, | 288 | apply_vert_layout(container, x, y, width, height, 0, |
313 | container->children->length); | 289 | container->children->length); |
314 | break; | 290 | break; |
@@ -381,6 +357,7 @@ void apply_vert_layout(struct sway_container *container, | |||
381 | const double x, const double y, | 357 | const double x, const double y, |
382 | const double width, const double height, const int start, | 358 | const double width, const double height, const int start, |
383 | const int end) { | 359 | const int end) { |
360 | assert(container); | ||
384 | int i; | 361 | int i; |
385 | double scale = 0; | 362 | double scale = 0; |
386 | // Calculate total height | 363 | // Calculate total height |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 4e695b5f..eeadc5d8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -78,14 +78,12 @@ void view_close(struct sway_view *view) { | |||
78 | } | 78 | } |
79 | } | 79 | } |
80 | 80 | ||
81 | struct sway_container *container_view_destroy(struct sway_container *view) { | 81 | void container_view_destroy(struct sway_container *view) { |
82 | if (!view) { | 82 | if (!view) { |
83 | return NULL; | 83 | return; |
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 | container_destroy(view); |
87 | arrange_windows(&root_container, -1, -1); | ||
88 | return parent; | ||
89 | } | 87 | } |
90 | 88 | ||
91 | void view_damage_whole(struct sway_view *view) { | 89 | void view_damage_whole(struct sway_view *view) { |
@@ -164,6 +162,8 @@ void view_unmap(struct sway_view *view) { | |||
164 | 162 | ||
165 | view->swayc = NULL; | 163 | view->swayc = NULL; |
166 | view->surface = NULL; | 164 | view->surface = NULL; |
165 | |||
166 | arrange_windows(&root_container, -1, -1); | ||
167 | } | 167 | } |
168 | 168 | ||
169 | void view_update_position(struct sway_view *view, double ox, double oy) { | 169 | void view_update_position(struct sway_view *view, double ox, double oy) { |