diff --git a/sway/container.c b/sway/container.c index e679e823..c83cd720 100644 --- a/sway/container.c +++ b/sway/container.c @@ -37,6 +37,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 +62,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; } @@ -206,6 +214,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; diff --git a/sway/focus.c b/sway/focus.c index 99cb2570..7e3af56c 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -16,7 +16,7 @@ static void update_focus(swayc_t *c) { switch (c->type) { case C_ROOT: return; case C_OUTPUT: - wlc_output_focus(c->parent->handle); + wlc_output_focus(c->handle); break; // switching workspaces case C_WORKSPACE: diff --git a/sway/workspace.c b/sway/workspace.c index bc0fa2c8..ed545804 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -174,6 +174,17 @@ void workspace_prev() { } void workspace_switch(swayc_t *workspace) { + if (!workspace) { + return; + } + sway_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); + + // Remove focus from current view + swayc_t *current = get_focused_view(&root_container); + if (current && current->type == C_VIEW) { + wlc_view_set_state(current->handle, WLC_BIT_ACTIVATED, false); + } + set_focused_container(workspace); active_workspace = workspace; }