diff options
author | Half-Shot <half-shot@molrams.com> | 2015-08-18 21:42:28 +0100 |
---|---|---|
committer | Half-Shot <half-shot@molrams.com> | 2015-08-18 21:42:28 +0100 |
commit | f314d951039031fd7f0bd8772b6916587ebb0846 (patch) | |
tree | 7287a3f02593906ae23aec234fbe6e2ca1b06d1d /sway/container.c | |
parent | d6ab5e481be2faa0e911d0b3109ae01fe79eb25f (diff) | |
parent | feb0195341b4caabfc3338bb29acf027b1e53780 (diff) |
Merge branch 'master' of https://github.com/SirCmpwn/sway
Diffstat (limited to 'sway/container.c')
-rw-r--r-- | sway/container.c | 51 |
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 @@ #include "config.h" #include "container.h" #include "workspace.h" +#include "focus.h" #include "layout.h" #include "log.h" @@ -21,11 +22,26 @@ static swayc_t *new_swayc(enum swayc_types type) { } static void free_swayc(swayc_t *c) { - //TODO does not properly handle containers with children, - //TODO but functions that call this usually check for that + // TODO does not properly handle containers with children, + // TODO but functions that call this usually check for that if (c->children) { + if (c->children->length) { + int i; + for (i = 0; i < c->children->length; ++i) { + free_swayc(c->children->items[i]); + } + } list_free(c->children); } + if (c->floating) { + if (c->floating->length) { + int i; + for (i = 0; i < c->floating->length; ++i) { + free_swayc(c->floating->items[i]); + } + } + list_free(c->floating); + } if (c->parent) { remove_child(c); } @@ -37,6 +53,10 @@ static void free_swayc(swayc_t *c) { /* New containers */ +static bool workspace_test(swayc_t *view, void *name) { + return strcasecmp(view->name, (char *)name); +} + swayc_t *new_output(wlc_handle handle) { const struct wlc_size* size = wlc_output_get_resolution(handle); const char *name = wlc_output_get_name(handle); @@ -58,6 +78,10 @@ swayc_t *new_output(wlc_handle handle) { struct workspace_output *wso = config->workspace_outputs->items[i]; if (strcasecmp(wso->output, name) == 0) { sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output); + // Check if any other workspaces are using this name + if (find_container(&root_container, workspace_test, wso->workspace)) { + break; + } ws_name = strdup(wso->workspace); break; } @@ -186,7 +210,7 @@ swayc_t *new_floating_view(wlc_handle handle) { list_add(active_workspace->floating, view); view->parent = active_workspace; if (active_workspace->focused == NULL) { - active_workspace->focused = view; + set_focused_container_for(active_workspace, view); } return view; } @@ -206,6 +230,18 @@ swayc_t *destroy_workspace(swayc_t *workspace) { // NOTE: This is called from elsewhere without checking children length // TODO move containers to other workspaces? // for now just dont delete + + // Do not destroy this if it's the last workspace on this output + swayc_t *output = workspace->parent; + while (output && output->type != C_OUTPUT) { + output = output->parent; + } + if (output) { + if (output->children->length == 1) { + return NULL; + } + } + if (workspace->children->length == 0) { sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); swayc_t *parent = workspace->parent; @@ -271,7 +307,7 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da } void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { - if (!container->children || !container->children->length) { + if (!container || !container->children || !container->children->length) { return; } int i; @@ -280,6 +316,13 @@ void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), voi f(child, data); container_map(child, f, data); } + if (container->type == C_WORKSPACE) { + for (i = 0; i < container->floating->length; ++i) { + swayc_t *child = container->floating->items[i]; + f(child, data); + container_map(child, f, data); + } + } } void set_view_visibility(swayc_t *view, void *data) { |