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 68511156..06111674 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);
@@ -60,6 +80,10 @@ swayc_t *new_output(wlc_handle handle) {
60 struct workspace_output *wso = config->workspace_outputs->items[i]; 80 struct workspace_output *wso = config->workspace_outputs->items[i];
61 if (strcasecmp(wso->output, name) == 0) { 81 if (strcasecmp(wso->output, name) == 0) {
62 sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); 82 sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
83 // Check if any other workspaces are using this name
84 if (find_container(&root_container, workspace_test, wso->workspace)) {
85 break;
86 }
63 ws_name = strdup(wso->workspace); 87 ws_name = strdup(wso->workspace);
64 break; 88 break;
65 } 89 }
@@ -192,7 +216,7 @@ swayc_t *new_floating_view(wlc_handle handle) {
192 list_add(active_workspace->floating, view); 216 list_add(active_workspace->floating, view);
193 view->parent = active_workspace; 217 view->parent = active_workspace;
194 if (active_workspace->focused == NULL) { 218 if (active_workspace->focused == NULL) {
195 active_workspace->focused = view; 219 set_focused_container_for(active_workspace, view);
196 } 220 }
197 return view; 221 return view;
198} 222}
@@ -212,6 +236,18 @@ swayc_t *destroy_workspace(swayc_t *workspace) {
212 // NOTE: This is called from elsewhere without checking children length 236 // NOTE: This is called from elsewhere without checking children length
213 // TODO move containers to other workspaces? 237 // TODO move containers to other workspaces?
214 // for now just dont delete 238 // for now just dont delete
239
240 // Do not destroy this if it's the last workspace on this output
241 swayc_t *output = workspace->parent;
242 while (output && output->type != C_OUTPUT) {
243 output = output->parent;
244 }
245 if (output) {
246 if (output->children->length == 1) {
247 return NULL;
248 }
249 }
250
215 if (workspace->children->length == 0) { 251 if (workspace->children->length == 0) {
216 sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); 252 sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name);
217 swayc_t *parent = workspace->parent; 253 swayc_t *parent = workspace->parent;
@@ -277,7 +313,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da
277} 313}
278 314
279void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 315void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) {
280 if (!container->children || !container->children->length) { 316 if (!container || !container->children || !container->children->length) {
281 return; 317 return;
282 } 318 }
283 int i; 319 int i;
@@ -286,6 +322,13 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi
286 f(child, data); 322 f(child, data);
287 container_map(child, f, data); 323 container_map(child, f, data);
288 } 324 }
325 if (container->type == C_WORKSPACE) {
326 for (i = 0; i < container->floating->length; ++i) {
327 swayc_t *child = container->floating->items[i];
328 f(child, data);
329 container_map(child, f, data);
330 }
331 }
289} 332}
290 333
291void set_view_visibility(swayc_t *view, void *data) { 334void set_view_visibility(swayc_t *view, void *data) {