diff options
Diffstat (limited to 'sway/handlers.c')
-rw-r--r-- | sway/handlers.c | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/sway/handlers.c b/sway/handlers.c index 647f9771..4336b6c7 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -198,6 +198,27 @@ static bool client_is_panel(struct wl_client *client) { | |||
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | 200 | ||
201 | static void ws_cleanup() { | ||
202 | swayc_t *op, *ws; | ||
203 | int i = 0, j; | ||
204 | if (!root_container.children) | ||
205 | return; | ||
206 | while (i < root_container.children->length) { | ||
207 | op = root_container.children->items[i++]; | ||
208 | if (!op->children) | ||
209 | continue; | ||
210 | j = 0; | ||
211 | while (j < op->children->length) { | ||
212 | ws = op->children->items[j++]; | ||
213 | if (ws->children->length == 0 && ws->floating->length == 0 && ws != op->focused) { | ||
214 | if (destroy_workspace(ws)) { | ||
215 | j--; | ||
216 | } | ||
217 | } | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
201 | static bool handle_view_created(wlc_handle handle) { | 222 | static bool handle_view_created(wlc_handle handle) { |
202 | // if view is child of another view, the use that as focused container | 223 | // if view is child of another view, the use that as focused container |
203 | wlc_handle parent = wlc_view_get_parent(handle); | 224 | wlc_handle parent = wlc_view_get_parent(handle); |
@@ -226,8 +247,8 @@ static bool handle_view_created(wlc_handle handle) { | |||
226 | // using newview as a temp storage location here, | 247 | // using newview as a temp storage location here, |
227 | // rather than adding yet another workspace var | 248 | // rather than adding yet another workspace var |
228 | newview = workspace_for_pid(pid); | 249 | newview = workspace_for_pid(pid); |
229 | if (newview && newview != current_ws) { | 250 | if (newview) { |
230 | focused = newview; | 251 | focused = get_focused_container(newview); |
231 | return_to_workspace = true; | 252 | return_to_workspace = true; |
232 | } | 253 | } |
233 | newview = NULL; | 254 | newview = NULL; |
@@ -295,6 +316,9 @@ static bool handle_view_created(wlc_handle handle) { | |||
295 | break; | 316 | break; |
296 | } | 317 | } |
297 | 318 | ||
319 | // Prevent current ws from being destroyed, if empty | ||
320 | suspend_workspace_cleanup = true; | ||
321 | |||
298 | if (newview) { | 322 | if (newview) { |
299 | set_focused_container(newview); | 323 | set_focused_container(newview); |
300 | swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); | 324 | swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); |
@@ -343,6 +367,9 @@ static bool handle_view_created(wlc_handle handle) { | |||
343 | workspace_switch(current_ws); | 367 | workspace_switch(current_ws); |
344 | set_focused_container(current_ws->focused); | 368 | set_focused_container(current_ws->focused); |
345 | } | 369 | } |
370 | |||
371 | suspend_workspace_cleanup = false; | ||
372 | ws_cleanup(); | ||
346 | return true; | 373 | return true; |
347 | } | 374 | } |
348 | 375 | ||