diff options
author | Tony Crisci <tony@dubstepdish.com> | 2018-04-03 13:08:45 -0400 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2018-04-03 13:08:45 -0400 |
commit | 5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc (patch) | |
tree | 75f4da71db52745ffd833e0bb7b110ff0044c084 /sway/tree/container.c | |
parent | move output code out of the tree (diff) | |
download | sway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.tar.gz sway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.tar.zst sway-5f4761c4f40f5d6ec550ccabaebe0f990b6e8bbc.zip |
unify workspace create functions
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index 1c41bf5d..7ccd43ea 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -110,7 +110,8 @@ struct sway_container *container_finish(struct sway_container *cont) { | |||
110 | return parent; | 110 | return parent; |
111 | } | 111 | } |
112 | 112 | ||
113 | static struct sway_container *container_output_destroy(struct sway_container *output) { | 113 | static struct sway_container *container_output_destroy( |
114 | struct sway_container *output) { | ||
114 | if (!sway_assert(output, "cannot destroy null output")) { | 115 | if (!sway_assert(output, "cannot destroy null output")) { |
115 | return NULL; | 116 | return NULL; |
116 | } | 117 | } |
@@ -245,7 +246,8 @@ struct sway_container *container_destroy(struct sway_container *con) { | |||
245 | break; | 246 | break; |
246 | case C_CONTAINER: | 247 | case C_CONTAINER: |
247 | if (con->children != NULL && con->children->length) { | 248 | if (con->children != NULL && con->children->length) { |
248 | assert(false && "dont destroy container containers with children"); | 249 | assert(false && |
250 | "dont destroy container containers with children"); | ||
249 | } | 251 | } |
250 | container_finish(con); | 252 | container_finish(con); |
251 | // TODO return parent to arrange maybe? | 253 | // TODO return parent to arrange maybe? |
@@ -271,7 +273,8 @@ static void container_close_func(struct sway_container *container, void *data) { | |||
271 | } | 273 | } |
272 | 274 | ||
273 | struct sway_container *container_close(struct sway_container *con) { | 275 | struct sway_container *container_close(struct sway_container *con) { |
274 | if (!sway_assert(con != NULL, "container_close called with a NULL container")) { | 276 | if (!sway_assert(con != NULL, |
277 | "container_close called with a NULL container")) { | ||
275 | return NULL; | 278 | return NULL; |
276 | } | 279 | } |
277 | 280 | ||
@@ -359,12 +362,39 @@ struct sway_container *container_output_create( | |||
359 | return output; | 362 | return output; |
360 | } | 363 | } |
361 | 364 | ||
362 | struct sway_container *container_workspace_create( | 365 | static struct sway_container *workspace_get_initial_output(const char *name) { |
363 | struct sway_container *output, const char *name) { | 366 | struct sway_container *parent; |
364 | if (!sway_assert(output, | 367 | // Search for workspace<->output pair |
365 | "container_workspace_create called with null output")) { | 368 | int i, e = config->workspace_outputs->length; |
366 | return NULL; | 369 | for (i = 0; i < e; ++i) { |
370 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
371 | if (strcasecmp(wso->workspace, name) == 0) { | ||
372 | // Find output to use if it exists | ||
373 | e = root_container.children->length; | ||
374 | for (i = 0; i < e; ++i) { | ||
375 | parent = root_container.children->items[i]; | ||
376 | if (strcmp(parent->name, wso->output) == 0) { | ||
377 | return parent; | ||
378 | } | ||
379 | } | ||
380 | break; | ||
381 | } | ||
367 | } | 382 | } |
383 | // Otherwise put it on the focused output | ||
384 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
385 | struct sway_container *focus = | ||
386 | seat_get_focus_inactive(seat, &root_container); | ||
387 | parent = focus; | ||
388 | parent = container_parent(parent, C_OUTPUT); | ||
389 | return parent; | ||
390 | } | ||
391 | |||
392 | struct sway_container *container_workspace_create(struct sway_container *output, | ||
393 | const char *name) { | ||
394 | if (output == NULL) { | ||
395 | output = workspace_get_initial_output(name); | ||
396 | } | ||
397 | |||
368 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | 398 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); |
369 | struct sway_container *workspace = container_create(C_WORKSPACE); | 399 | struct sway_container *workspace = container_create(C_WORKSPACE); |
370 | 400 | ||
@@ -380,6 +410,7 @@ struct sway_container *container_workspace_create( | |||
380 | container_add_child(output, workspace); | 410 | container_add_child(output, workspace); |
381 | container_sort_workspaces(output); | 411 | container_sort_workspaces(output); |
382 | notify_new_container(workspace); | 412 | notify_new_container(workspace); |
413 | |||
383 | return workspace; | 414 | return workspace; |
384 | } | 415 | } |
385 | 416 | ||