diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-07-14 18:04:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-14 18:04:50 -0400 |
commit | 1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5 (patch) | |
tree | 320a7d0455f6d433bbce76324ad816e29af803d4 | |
parent | Merge pull request #750 from deklov/sway-lock-01 (diff) | |
parent | Suspend destruction of wss when creating views (diff) | |
download | sway-1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5.tar.gz sway-1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5.tar.zst sway-1e95191900d1f16b4d195f2d05f1eb7cb1f62ad5.zip |
Merge pull request #726 from Hummer12007/hwc
Spawn new views to target ws's focused container
-rw-r--r-- | include/focus.h | 2 | ||||
-rw-r--r-- | sway/focus.c | 3 | ||||
-rw-r--r-- | sway/handlers.c | 31 |
3 files changed, 33 insertions, 3 deletions
diff --git a/include/focus.h b/include/focus.h index 4abd6080..602b6122 100644 --- a/include/focus.h +++ b/include/focus.h | |||
@@ -34,6 +34,8 @@ bool set_focused_container_for(swayc_t *ancestor, swayc_t *container); | |||
34 | extern bool locked_container_focus; | 34 | extern bool locked_container_focus; |
35 | extern bool locked_view_focus; | 35 | extern bool locked_view_focus; |
36 | 36 | ||
37 | // Prevents wss from being destroyed on focus switch | ||
38 | extern bool suspend_workspace_cleanup; | ||
37 | 39 | ||
38 | bool move_focus(enum movement_direction direction); | 40 | bool move_focus(enum movement_direction direction); |
39 | 41 | ||
diff --git a/sway/focus.c b/sway/focus.c index 1d21ac35..0d9ee7e3 100644 --- a/sway/focus.c +++ b/sway/focus.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | bool locked_container_focus = false; | 12 | bool locked_container_focus = false; |
13 | bool locked_view_focus = false; | 13 | bool locked_view_focus = false; |
14 | bool suspend_workspace_cleanup = false; | ||
14 | 15 | ||
15 | // switches parent focus to c. will switch it accordingly | 16 | // switches parent focus to c. will switch it accordingly |
16 | static void update_focus(swayc_t *c) { | 17 | static void update_focus(swayc_t *c) { |
@@ -40,7 +41,7 @@ static void update_focus(swayc_t *c) { | |||
40 | ipc_event_workspace(prev, c, "focus"); | 41 | ipc_event_workspace(prev, c, "focus"); |
41 | 42 | ||
42 | // if the old workspace has no children, destroy it | 43 | // if the old workspace has no children, destroy it |
43 | if(prev->children->length == 0 && prev->floating->length == 0){ | 44 | if(prev->children->length == 0 && prev->floating->length == 0 && !suspend_workspace_cleanup) { |
44 | destroy_workspace(prev); | 45 | destroy_workspace(prev); |
45 | } else { | 46 | } else { |
46 | // update visibility of old workspace | 47 | // update visibility of old workspace |
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 | ||