summaryrefslogtreecommitdiffstats
path: root/sway/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/sway/container.c b/sway/container.c
index e679e823..62c5bda0 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -4,6 +4,7 @@
4#include "config.h" 4#include "config.h"
5#include "container.h" 5#include "container.h"
6#include "workspace.h" 6#include "workspace.h"
7#include "focus.h"
7#include "layout.h" 8#include "layout.h"
8#include "log.h" 9#include "log.h"
9 10
@@ -21,11 +22,26 @@ static swayc_t *new_swayc(enum swayc_types type) {
21} 22}
22 23
23static void free_swayc(swayc_t *c) { 24static void free_swayc(swayc_t *c) {
24 //TODO does not properly handle containers with children, 25 // TODO does not properly handle containers with children,
25 //TODO but functions that call this usually check for that 26 // TODO but functions that call this usually check for that
26 if (c->children) { 27 if (c->children) {
28 if (c->children->length) {
29 int i;
30 for (i = 0; i < c->children->length; ++i) {
31 free_swayc(c->children->items[i]);
32 }
33 }
27 list_free(c->children); 34 list_free(c->children);
28 } 35 }
36 if (c->floating) {
37 if (c->floating->length) {
38 int i;
39 for (i = 0; i < c->floating->length; ++i) {
40 free_swayc(c->floating->items[i]);
41 }
42 }
43 list_free(c->floating);
44 }
29 if (c->parent) { 45 if (c->parent) {
30 remove_child(c); 46 remove_child(c);
31 } 47 }
@@ -37,6 +53,10 @@ static void free_swayc(swayc_t *c) {
37 53
38/* New containers */ 54/* New containers */
39 55
56static bool workspace_test(swayc_t *view, void *name) {
57 return strcasecmp(view->name, (char *)name);
58}
59
40swayc_t *new_output(wlc_handle handle) { 60swayc_t *new_output(wlc_handle handle) {
41 const struct wlc_size* size = wlc_output_get_resolution(handle); 61 const struct wlc_size* size = wlc_output_get_resolution(handle);
42 const char *name = wlc_output_get_name(handle); 62 const char *name = wlc_output_get_name(handle);
@@ -58,6 +78,10 @@ swayc_t *new_output(wlc_handle handle) {
58 struct workspace_output *wso = config->workspace_outputs->items[i]; 78 struct workspace_output *wso = config->workspace_outputs->items[i];
59 if (strcasecmp(wso->output, name) == 0) { 79 if (strcasecmp(wso->output, name) == 0) {
60 sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); 80 sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
81 // Check if any other workspaces are using this name
82 if (find_container(&root_container, workspace_test, wso->workspace)) {
83 break;
84 }
61 ws_name = strdup(wso->workspace); 85 ws_name = strdup(wso->workspace);
62 break; 86 break;
63 } 87 }
@@ -186,7 +210,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
186 list_add(active_workspace->floating, view); 210 list_add(active_workspace->floating, view);
187 view->parent = active_workspace; 211 view->parent = active_workspace;
188 if (active_workspace->focused == NULL) { 212 if (active_workspace->focused == NULL) {
189 active_workspace->focused = view; 213 set_focused_container_for(active_workspace, view);
190 } 214 }
191 return view; 215 return view;
192} 216}
@@ -206,6 +230,18 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
206 // NOTE: This is called from elsewhere without checking children length 230 // NOTE: This is called from elsewhere without checking children length
207 // TODO move containers to other workspaces? 231 // TODO move containers to other workspaces?
208 // for now just dont delete 232 // for now just dont delete
233
234 // Do not destroy this if it's the last workspace on this output
235 swayc_t *output = workspace->parent;
236 while (output && output->type != C_OUTPUT) {
237 output = output->parent;
238 }
239 if (output) {
240 if (output->children->length == 1) {
241 return NULL;
242 }
243 }
244
209 if (workspace->children->length == 0) { 245 if (workspace->children->length == 0) {
210 sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); 246 sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
211 swayc_t *parent = workspace->parent; 247 swayc_t *parent = workspace->parent;
@@ -271,7 +307,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da
271} 307}
272 308
273void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 309void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
274 if (!container->children || !container->children->length) { 310 if (!container || !container->children || !container->children->length) {
275 return; 311 return;
276 } 312 }
277 int i; 313 int i;
@@ -280,6 +316,13 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
280 f(child, data); 316 f(child, data);
281 container_map(child, f, data); 317 container_map(child, f, data);
282 } 318 }
319 if (container->type == C_WORKSPACE) {
320 for (i = 0; i < container->floating->length; ++i) {
321 swayc_t *child = container->floating->items[i];
322 f(child, data);
323 container_map(child, f, data);
324 }
325 }
283} 326}
284 327
285void set_view_visibility(swayc_t *view, void *data) { 328void set_view_visibility(swayc_t *view, void *data) {