diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-04-03 19:23:59 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-04-03 19:23:59 -0400 |
commit | 481a8275c178f81bb2d9927c5047e959fdbc383a (patch) | |
tree | 4a2f1f85be06a17f2885a53676bd446d8fd8c502 | |
parent | fix old todos (diff) | |
download | sway-481a8275c178f81bb2d9927c5047e959fdbc383a.tar.gz sway-481a8275c178f81bb2d9927c5047e959fdbc383a.tar.zst sway-481a8275c178f81bb2d9927c5047e959fdbc383a.zip |
address feedback
-rw-r--r-- | sway/commands/kill.c | 14 | ||||
-rw-r--r-- | sway/desktop/output.c | 2 | ||||
-rw-r--r-- | sway/tree/container.c | 127 | ||||
-rw-r--r-- | sway/tree/layout.c | 2 | ||||
-rw-r--r-- | sway/tree/view.c | 4 |
5 files changed, 75 insertions, 74 deletions
diff --git a/sway/commands/kill.c b/sway/commands/kill.c index 811c3e6b..f3fa52f1 100644 --- a/sway/commands/kill.c +++ b/sway/commands/kill.c | |||
@@ -10,19 +10,7 @@ struct cmd_results *cmd_kill(int argc, char **argv) { | |||
10 | struct sway_container *con = | 10 | struct sway_container *con = |
11 | config->handler_context.current_container; | 11 | config->handler_context.current_container; |
12 | 12 | ||
13 | switch (con->type) { | 13 | container_close(con); |
14 | case C_ROOT: | ||
15 | case C_OUTPUT: | ||
16 | case C_WORKSPACE: | ||
17 | case C_TYPES: | ||
18 | return cmd_results_new(CMD_INVALID, NULL, | ||
19 | "Can only kill views and containers with this command"); | ||
20 | break; | ||
21 | case C_CONTAINER: | ||
22 | case C_VIEW: | ||
23 | container_close(con); | ||
24 | break; | ||
25 | } | ||
26 | 14 | ||
27 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 15 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
28 | } | 16 | } |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index e60fac5f..de5076d8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -25,7 +25,7 @@ | |||
25 | struct sway_container *output_by_name(const char *name) { | 25 | struct sway_container *output_by_name(const char *name) { |
26 | for (int i = 0; i < root_container.children->length; ++i) { | 26 | for (int i = 0; i < root_container.children->length; ++i) { |
27 | struct sway_container *output = root_container.children->items[i]; | 27 | struct sway_container *output = root_container.children->items[i]; |
28 | if (strcasecmp(output->name, name) == 0){ | 28 | if (strcasecmp(output->name, name) == 0) { |
29 | return output; | 29 | return output; |
30 | } | 30 | } |
31 | } | 31 | } |
diff --git a/sway/tree/container.c b/sway/tree/container.c index f616af09..77c61b3f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -186,45 +186,44 @@ static struct sway_container *container_workspace_destroy( | |||
186 | return parent; | 186 | return parent; |
187 | } | 187 | } |
188 | 188 | ||
189 | static void container_root_finish(struct sway_container *con) { | ||
190 | wlr_log(L_ERROR, "TODO: destroy the root container"); | ||
191 | } | ||
189 | 192 | ||
190 | static void reap_empty_func(struct sway_container *con, void *data) { | 193 | static bool container_reap_empty(struct sway_container *con) { |
191 | switch (con->type) { | 194 | switch (con->type) { |
192 | case C_TYPES: | 195 | case C_ROOT: |
193 | case C_ROOT: | 196 | case C_OUTPUT: |
194 | case C_OUTPUT: | 197 | // dont reap these |
195 | // dont reap these | 198 | break; |
196 | break; | 199 | case C_WORKSPACE: |
197 | case C_WORKSPACE: | 200 | if (!workspace_is_visible(con) && con->children->length == 0) { |
198 | if (!workspace_is_visible(con) && con->children->length == 0) { | 201 | container_workspace_destroy(con); |
199 | container_workspace_destroy(con); | 202 | return true; |
200 | } | 203 | } |
201 | break; | 204 | break; |
202 | case C_CONTAINER: | 205 | case C_CONTAINER: |
203 | if (con->children->length == 0) { | 206 | if (con->children->length == 0) { |
207 | container_finish(con); | ||
208 | return true; | ||
209 | } else if (con->children->length == 1) { | ||
210 | struct sway_container *child = con->children->items[0]; | ||
211 | if (child->type == C_CONTAINER) { | ||
212 | container_remove_child(child); | ||
213 | container_replace_child(con, child); | ||
204 | container_finish(con); | 214 | container_finish(con); |
205 | } else if (con->children->length == 1) { | 215 | return true; |
206 | struct sway_container *only_child = con->children->items[0]; | ||
207 | if (only_child->type == C_CONTAINER) { | ||
208 | container_remove_child(only_child); | ||
209 | container_replace_child(con, only_child); | ||
210 | container_finish(con); | ||
211 | } | ||
212 | } | 216 | } |
213 | case C_VIEW: | 217 | } |
214 | break; | 218 | case C_VIEW: |
219 | break; | ||
220 | case C_TYPES: | ||
221 | sway_assert(false, "container_reap_empty called on an invalid " | ||
222 | "container"); | ||
223 | break; | ||
215 | } | 224 | } |
216 | } | ||
217 | |||
218 | struct sway_container *container_reap_empty(struct sway_container *container) { | ||
219 | struct sway_container *parent = container->parent; | ||
220 | |||
221 | container_for_each_descendant_dfs(container, reap_empty_func, NULL); | ||
222 | 225 | ||
223 | return parent; | 226 | return false; |
224 | } | ||
225 | |||
226 | static void container_root_finish(struct sway_container *con) { | ||
227 | wlr_log(L_ERROR, "TODO: destroy the root container"); | ||
228 | } | 227 | } |
229 | 228 | ||
230 | struct sway_container *container_destroy(struct sway_container *con) { | 229 | struct sway_container *container_destroy(struct sway_container *con) { |
@@ -232,38 +231,52 @@ struct sway_container *container_destroy(struct sway_container *con) { | |||
232 | return NULL; | 231 | return NULL; |
233 | } | 232 | } |
234 | 233 | ||
235 | struct sway_container *anscestor = NULL; | 234 | struct sway_container *parent = con->parent; |
236 | 235 | ||
237 | switch (con->type) { | 236 | switch (con->type) { |
238 | case C_ROOT: | 237 | case C_ROOT: |
239 | container_root_finish(con); | 238 | container_root_finish(con); |
240 | break; | 239 | break; |
241 | case C_OUTPUT: | 240 | case C_OUTPUT: |
242 | anscestor = container_output_destroy(con); | 241 | // dont try to reap the root after this |
242 | container_output_destroy(con); | ||
243 | break; | 243 | break; |
244 | case C_WORKSPACE: | 244 | case C_WORKSPACE: |
245 | anscestor = container_workspace_destroy(con); | 245 | // dont try to reap the output after this |
246 | container_workspace_destroy(con); | ||
246 | break; | 247 | break; |
247 | case C_CONTAINER: | 248 | case C_CONTAINER: |
248 | if (con->children != NULL && con->children->length) { | 249 | if (con->children->length) { |
249 | assert(false && | 250 | for (int i = 0; i < con->children->length; ++i) { |
250 | "dont destroy container containers with children"); | 251 | struct sway_container *child = con->children->items[0]; |
252 | container_remove_child(child); | ||
253 | container_add_child(parent, child); | ||
254 | } | ||
255 | container_finish(con); | ||
251 | } | 256 | } |
252 | container_finish(con); | 257 | container_finish(con); |
253 | // TODO return parent to arrange maybe? | ||
254 | break; | 258 | break; |
255 | case C_VIEW: | 259 | case C_VIEW: |
256 | container_finish(con); | 260 | container_finish(con); |
257 | // TODO return parent to arrange maybe? | ||
258 | break; | 261 | break; |
259 | case C_TYPES: | 262 | case C_TYPES: |
260 | wlr_log(L_ERROR, "tried to destroy an invalid container"); | 263 | wlr_log(L_ERROR, "container_destroy called on an invalid " |
264 | "container"); | ||
261 | break; | 265 | break; |
262 | } | 266 | } |
263 | 267 | ||
264 | container_reap_empty(&root_container); | 268 | struct sway_container *tmp = parent; |
269 | while (parent) { | ||
270 | tmp = parent->parent; | ||
271 | |||
272 | if (!container_reap_empty(parent)) { | ||
273 | break; | ||
274 | } | ||
275 | |||
276 | parent = tmp; | ||
277 | } | ||
265 | 278 | ||
266 | return anscestor; | 279 | return tmp; |
267 | } | 280 | } |
268 | 281 | ||
269 | static void container_close_func(struct sway_container *container, void *data) { | 282 | static void container_close_func(struct sway_container *container, void *data) { |
@@ -274,23 +287,23 @@ static void container_close_func(struct sway_container *container, void *data) { | |||
274 | 287 | ||
275 | struct sway_container *container_close(struct sway_container *con) { | 288 | struct sway_container *container_close(struct sway_container *con) { |
276 | if (!sway_assert(con != NULL, | 289 | if (!sway_assert(con != NULL, |
277 | "container_close called with a NULL container")) { | 290 | "container_close called with a NULL container")) { |
278 | return NULL; | 291 | return NULL; |
279 | } | 292 | } |
280 | 293 | ||
281 | struct sway_container *parent = con->parent; | 294 | struct sway_container *parent = con->parent; |
282 | 295 | ||
283 | switch (con->type) { | 296 | switch (con->type) { |
284 | case C_TYPES: | 297 | case C_TYPES: |
285 | case C_ROOT: | 298 | case C_ROOT: |
286 | case C_OUTPUT: | 299 | case C_OUTPUT: |
287 | case C_WORKSPACE: | 300 | case C_WORKSPACE: |
288 | case C_CONTAINER: | 301 | case C_CONTAINER: |
289 | container_for_each_descendant_dfs(con, container_close_func, NULL); | 302 | container_for_each_descendant_dfs(con, container_close_func, NULL); |
290 | break; | 303 | break; |
291 | case C_VIEW: | 304 | case C_VIEW: |
292 | view_close(con->sway_view); | 305 | view_close(con->sway_view); |
293 | break; | 306 | break; |
294 | 307 | ||
295 | } | 308 | } |
296 | 309 | ||
@@ -365,8 +378,8 @@ struct sway_container *container_output_create( | |||
365 | static struct sway_container *get_workspace_initial_output(const char *name) { | 378 | static struct sway_container *get_workspace_initial_output(const char *name) { |
366 | struct sway_container *parent; | 379 | struct sway_container *parent; |
367 | // Search for workspace<->output pair | 380 | // Search for workspace<->output pair |
368 | int i, e = config->workspace_outputs->length; | 381 | int e = config->workspace_outputs->length; |
369 | for (i = 0; i < e; ++i) { | 382 | for (int i = 0; i < config->workspace_outputs->length; ++i) { |
370 | struct workspace_output *wso = config->workspace_outputs->items[i]; | 383 | struct workspace_output *wso = config->workspace_outputs->items[i]; |
371 | if (strcasecmp(wso->workspace, name) == 0) { | 384 | if (strcasecmp(wso->workspace, name) == 0) { |
372 | // Find output to use if it exists | 385 | // Find output to use if it exists |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index c3cdaae0..3cbbf3b4 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -174,7 +174,7 @@ enum sway_container_layout container_get_default_layout( | |||
174 | } | 174 | } |
175 | 175 | ||
176 | if (!sway_assert(con != NULL, | 176 | if (!sway_assert(con != NULL, |
177 | "container_get_default_layout must be called on an attached " | 177 | "container_get_default_layout must be called on an attached" |
178 | " container below the root container")) { | 178 | " container below the root container")) { |
179 | return 0; | 179 | return 0; |
180 | } | 180 | } |
diff --git a/sway/tree/view.c b/sway/tree/view.c index c06924f5..aa010a40 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -149,12 +149,12 @@ void view_unmap(struct sway_view *view) { | |||
149 | 149 | ||
150 | view_damage_whole(view); | 150 | view_damage_whole(view); |
151 | 151 | ||
152 | container_destroy(view->swayc); | 152 | struct sway_container *parent = container_destroy(view->swayc); |
153 | 153 | ||
154 | view->swayc = NULL; | 154 | view->swayc = NULL; |
155 | view->surface = NULL; | 155 | view->surface = NULL; |
156 | 156 | ||
157 | arrange_windows(&root_container, -1, -1); | 157 | arrange_windows(parent, -1, -1); |
158 | } | 158 | } |
159 | 159 | ||
160 | void view_update_position(struct sway_view *view, double ox, double oy) { | 160 | void view_update_position(struct sway_view *view, double ox, double oy) { |