aboutsummaryrefslogtreecommitdiff
path: root/sway/container.c
diff options
context:
space:
mode:
authorZandr Martin <zandrmartin+git@gmail.com>2016-05-28 18:18:46 -0500
committerZandr Martin <zandrmartin+git@gmail.com>2016-05-28 18:18:46 -0500
commitd291a29f305efdf0b739d48a23170bf6057ac3a6 (patch)
tree129d1b66f8be0afc1a486096bb31cd9ac458e87f /sway/container.c
parenta0315dc849aacd6e20cf57cb0cbb9ea1d91dce79 (diff)
enforce workspace output assignents
when creating a new output, move to that output all extant workspaces that are assigned to that output. (unrelated) remove comment that was no longer applicable, fix spacing in an assignment
Diffstat (limited to 'sway/container.c')
-rw-r--r--sway/container.c33
1 files changed, 20 insertions, 13 deletions
diff --git a/sway/container.c b/sway/container.c
index 20b7905b..4883a648 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -134,32 +134,39 @@ swayc_t *new_output(wlc_handle handle) {
// Create workspace
char *ws_name = NULL;
+ swayc_t *ws = NULL;
+
if (name) {
for (i = 0; i < config->workspace_outputs->length; ++i) {
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 (workspace_by_name(wso->workspace)) {
- sway_log(L_DEBUG, "But it's already taken");
- break;
+ if ((ws = workspace_by_name(wso->workspace))) {
+ // if yes, move those to this output, because they should be here
+ move_workspace_to(ws, output);
+ } else if (!ws_name) {
+ // set a workspace name in case we need to create a default one
+ ws_name = strdup(wso->workspace);
}
- sway_log(L_DEBUG, "So we're going to use it");
- ws_name = strdup(wso->workspace);
- break;
}
}
}
- if (!ws_name) {
- ws_name = workspace_next_name(output->name);
- }
- // create and initialize default workspace
- swayc_t *ws = new_workspace(output, ws_name);
- ws->is_focused = true;
+ if (output->children->length == 0) {
+ if (!ws_name) {
+ ws_name = workspace_next_name(output->name);
+ }
+ // create and initialize default workspace
+ sway_log(L_DEBUG, "Creating default workspace %s", ws_name);
+ ws = new_workspace(output, ws_name);
+ ws->is_focused = true;
+ } else {
+ sort_workspaces(output);
+ set_focused_container(output->children->items[0]);
+ }
free(ws_name);
-
return output;
}