aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 11:58:17 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 13:49:34 -0400
commit49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6 (patch)
treeb67a66382125811fde75e5c3dff37d7081860c78 /sway/tree/workspace.c
parentMerge pull request #1664 from swaywm/xwayland-add-to-focused (diff)
downloadsway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.tar.gz
sway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.tar.zst
sway-49379dd0fc0758f89d7f4fa4fb5b08c7f4c26ae6.zip
Fix workspace deletion edge cases
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c56
1 files changed, 54 insertions, 2 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 5800ea09..c629f1f1 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -6,9 +6,10 @@
6#include <stdio.h> 6#include <stdio.h>
7#include <strings.h> 7#include <strings.h>
8#include "stringop.h" 8#include "stringop.h"
9#include "sway/tree/container.h"
10#include "sway/input/input-manager.h" 9#include "sway/input/input-manager.h"
11#include "sway/input/seat.h" 10#include "sway/input/seat.h"
11#include "sway/ipc-server.h"
12#include "sway/tree/container.h"
12#include "sway/tree/workspace.h" 13#include "sway/tree/workspace.h"
13#include "log.h" 14#include "log.h"
14#include "util.h" 15#include "util.h"
@@ -202,7 +203,48 @@ struct sway_container *workspace_create(const char *name) {
202 sway_seat_get_focus_inactive(seat, &root_container); 203 sway_seat_get_focus_inactive(seat, &root_container);
203 parent = focus; 204 parent = focus;
204 parent = container_parent(parent, C_OUTPUT); 205 parent = container_parent(parent, C_OUTPUT);
205 return container_workspace_create(parent, name); 206 struct sway_container *new_ws = container_workspace_create(parent, name);
207 ipc_event_workspace(NULL, new_ws, "init");
208 return new_ws;
209}
210
211struct sway_container *container_workspace_destroy(
212 struct sway_container *workspace) {
213 if (!sway_assert(workspace, "cannot destroy null workspace")) {
214 return NULL;
215 }
216
217 // Do not destroy this if it's the last workspace on this output
218 struct sway_container *output = container_parent(workspace, C_OUTPUT);
219 if (output && output->children->length == 1) {
220 return NULL;
221 }
222
223 struct sway_container *parent = workspace->parent;
224 if (workspace->children->length == 0) {
225 // destroy the WS if there are no children (TODO check for floating)
226 wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
227 ipc_event_workspace(workspace, NULL, "empty");
228 } else {
229 // Move children to a different workspace on this output
230 struct sway_container *new_workspace = NULL;
231 // TODO move floating
232 for (int i = 0; i < output->children->length; i++) {
233 if (output->children->items[i] != workspace) {
234 new_workspace = output->children->items[i];
235 break;
236 }
237 }
238
239 wlr_log(L_DEBUG, "moving children to different workspace '%s' -> '%s'",
240 workspace->name, new_workspace->name);
241 for (int i = 0; i < workspace->children->length; i++) {
242 container_move_to(workspace->children->items[i], new_workspace);
243 }
244 }
245
246 container_destroy(workspace);
247 return parent;
206} 248}
207 249
208/** 250/**
@@ -343,3 +385,13 @@ bool workspace_switch(struct sway_container *workspace) {
343 arrange_windows(output, -1, -1); 385 arrange_windows(output, -1, -1);
344 return true; 386 return true;
345} 387}
388
389bool workspace_is_visible(struct sway_container *ws) {
390 struct sway_container *output = container_parent(ws, C_OUTPUT);
391 struct sway_seat *seat = input_manager_current_seat(input_manager);
392 struct sway_container *focus = sway_seat_get_focus_inactive(seat, output);
393 if (focus->type != C_WORKSPACE) {
394 focus = container_parent(focus, C_WORKSPACE);
395 }
396 return focus == ws;
397}