diff options
-rw-r--r-- | include/sway/tree/container.h | 8 | ||||
-rw-r--r-- | sway/commands/move.c | 2 | ||||
-rw-r--r-- | sway/commands/workspace.c | 6 | ||||
-rw-r--r-- | sway/desktop/output.c | 2 | ||||
-rw-r--r-- | sway/tree/container.c | 62 | ||||
-rw-r--r-- | sway/tree/layout.c | 2 | ||||
-rw-r--r-- | sway/tree/workspace.c | 54 |
7 files changed, 69 insertions, 67 deletions
diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index f36b4bd1..277165ea 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h | |||
@@ -95,7 +95,7 @@ struct sway_container *container_create(enum sway_container_type type); | |||
95 | 95 | ||
96 | const char *container_type_to_str(enum sway_container_type type); | 96 | const char *container_type_to_str(enum sway_container_type type); |
97 | 97 | ||
98 | struct sway_container *container_output_create( | 98 | struct sway_container *output_create( |
99 | struct sway_output *sway_output); | 99 | struct sway_output *sway_output); |
100 | 100 | ||
101 | /** | 101 | /** |
@@ -108,13 +108,13 @@ struct sway_container *container_container_create(); | |||
108 | * Create a new output. Outputs are children of the root container and have no | 108 | * Create a new output. Outputs are children of the root container and have no |
109 | * order in the tree structure. | 109 | * order in the tree structure. |
110 | */ | 110 | */ |
111 | struct sway_container *container_output_create(struct sway_output *sway_output); | 111 | struct sway_container *output_create(struct sway_output *sway_output); |
112 | 112 | ||
113 | /** | 113 | /** |
114 | * Create a new workspace container. Workspaces are children of an output | 114 | * Create a new workspace container. Workspaces are children of an output |
115 | * container and are ordered alphabetically by name. | 115 | * container and are ordered alphabetically by name. |
116 | */ | 116 | */ |
117 | struct sway_container *container_workspace_create(struct sway_container *output, const char *name); | 117 | struct sway_container *workspace_create(struct sway_container *output, const char *name); |
118 | 118 | ||
119 | /* | 119 | /* |
120 | * Create a new view container. A view can be a child of a workspace container | 120 | * Create a new view container. A view can be a child of a workspace container |
@@ -178,4 +178,6 @@ bool container_has_anscestor(struct sway_container *container, | |||
178 | bool container_has_child(struct sway_container *con, | 178 | bool container_has_child(struct sway_container *con, |
179 | struct sway_container *child); | 179 | struct sway_container *child); |
180 | 180 | ||
181 | void container_create_notify(struct sway_container *container); | ||
182 | |||
181 | #endif | 183 | #endif |
diff --git a/sway/commands/move.c b/sway/commands/move.c index 7ac5f009..c954ab94 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -74,7 +74,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
74 | ws = workspace_by_name(ws_name); | 74 | ws = workspace_by_name(ws_name); |
75 | } | 75 | } |
76 | if (!ws) { | 76 | if (!ws) { |
77 | ws = container_workspace_create(NULL, ws_name ? ws_name : num_name); | 77 | ws = workspace_create(NULL, ws_name ? ws_name : num_name); |
78 | } | 78 | } |
79 | free(ws_name); | 79 | free(ws_name); |
80 | struct sway_container *old_parent = current->parent; | 80 | struct sway_container *old_parent = current->parent; |
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index a3702803..958b3222 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -61,7 +61,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
61 | if (strcasecmp(argv[0], "number") == 0) { | 61 | if (strcasecmp(argv[0], "number") == 0) { |
62 | if (!(ws = workspace_by_number(argv[1]))) { | 62 | if (!(ws = workspace_by_number(argv[1]))) { |
63 | char *name = join_args(argv + 1, argc - 1); | 63 | char *name = join_args(argv + 1, argc - 1); |
64 | ws = container_workspace_create(NULL, name); | 64 | ws = workspace_create(NULL, name); |
65 | free(name); | 65 | free(name); |
66 | } | 66 | } |
67 | } else if (strcasecmp(argv[0], "next") == 0) { | 67 | } else if (strcasecmp(argv[0], "next") == 0) { |
@@ -80,12 +80,12 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
80 | ws = old_workspace; | 80 | ws = old_workspace; |
81 | } else if (prev_workspace_name | 81 | } else if (prev_workspace_name |
82 | && !(ws = workspace_by_name(prev_workspace_name))) { | 82 | && !(ws = workspace_by_name(prev_workspace_name))) { |
83 | ws = container_workspace_create(NULL, prev_workspace_name); | 83 | ws = workspace_create(NULL, prev_workspace_name); |
84 | } | 84 | } |
85 | } else { | 85 | } else { |
86 | char *name = join_args(argv, argc); | 86 | char *name = join_args(argv, argc); |
87 | if (!(ws = workspace_by_name(name))) { | 87 | if (!(ws = workspace_by_name(name))) { |
88 | ws = container_workspace_create(NULL, name); | 88 | ws = workspace_create(NULL, name); |
89 | } | 89 | } |
90 | free(name); | 90 | free(name); |
91 | } | 91 | } |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index de5076d8..96f23291 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -396,7 +396,7 @@ void handle_new_output(struct wl_listener *listener, void *data) { | |||
396 | 396 | ||
397 | output->damage = wlr_output_damage_create(wlr_output); | 397 | output->damage = wlr_output_damage_create(wlr_output); |
398 | 398 | ||
399 | output->swayc = container_output_create(output); | 399 | output->swayc = output_create(output); |
400 | if (!output->swayc) { | 400 | if (!output->swayc) { |
401 | free(output); | 401 | free(output); |
402 | return; | 402 | return; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index fdbb2922..8ed30b44 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -51,7 +51,7 @@ const char *container_type_to_str(enum sway_container_type type) { | |||
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | static void notify_new_container(struct sway_container *container) { | 54 | void container_create_notify(struct sway_container *container) { |
55 | wl_signal_emit(&root_container.sway_root->events.new_container, container); | 55 | wl_signal_emit(&root_container.sway_root->events.new_container, container); |
56 | ipc_event_window(container, "new"); | 56 | ipc_event_window(container, "new"); |
57 | } | 57 | } |
@@ -312,7 +312,7 @@ struct sway_container *container_close(struct sway_container *con) { | |||
312 | return parent; | 312 | return parent; |
313 | } | 313 | } |
314 | 314 | ||
315 | struct sway_container *container_output_create( | 315 | struct sway_container *output_create( |
316 | struct sway_output *sway_output) { | 316 | struct sway_output *sway_output) { |
317 | struct wlr_box size; | 317 | struct wlr_box size; |
318 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, | 318 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
@@ -363,7 +363,7 @@ struct sway_container *container_output_create( | |||
363 | // Create workspace | 363 | // Create workspace |
364 | char *ws_name = workspace_next_name(output->name); | 364 | char *ws_name = workspace_next_name(output->name); |
365 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); | 365 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
366 | struct sway_container *ws = container_workspace_create(output, ws_name); | 366 | struct sway_container *ws = workspace_create(output, ws_name); |
367 | // Set each seat's focus if not already set | 367 | // Set each seat's focus if not already set |
368 | struct sway_seat *seat = NULL; | 368 | struct sway_seat *seat = NULL; |
369 | wl_list_for_each(seat, &input_manager->seats, link) { | 369 | wl_list_for_each(seat, &input_manager->seats, link) { |
@@ -373,62 +373,10 @@ struct sway_container *container_output_create( | |||
373 | } | 373 | } |
374 | 374 | ||
375 | free(ws_name); | 375 | free(ws_name); |
376 | notify_new_container(output); | 376 | container_create_notify(output); |
377 | return output; | 377 | return output; |
378 | } | 378 | } |
379 | 379 | ||
380 | static struct sway_container *get_workspace_initial_output(const char *name) { | ||
381 | struct sway_container *parent; | ||
382 | // Search for workspace<->output pair | ||
383 | int e = config->workspace_outputs->length; | ||
384 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | ||
385 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
386 | if (strcasecmp(wso->workspace, name) == 0) { | ||
387 | // Find output to use if it exists | ||
388 | e = root_container.children->length; | ||
389 | for (i = 0; i < e; ++i) { | ||
390 | parent = root_container.children->items[i]; | ||
391 | if (strcmp(parent->name, wso->output) == 0) { | ||
392 | return parent; | ||
393 | } | ||
394 | } | ||
395 | break; | ||
396 | } | ||
397 | } | ||
398 | // Otherwise put it on the focused output | ||
399 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
400 | struct sway_container *focus = | ||
401 | seat_get_focus_inactive(seat, &root_container); | ||
402 | parent = focus; | ||
403 | parent = container_parent(parent, C_OUTPUT); | ||
404 | return parent; | ||
405 | } | ||
406 | |||
407 | struct sway_container *container_workspace_create(struct sway_container *output, | ||
408 | const char *name) { | ||
409 | if (output == NULL) { | ||
410 | output = get_workspace_initial_output(name); | ||
411 | } | ||
412 | |||
413 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | ||
414 | struct sway_container *workspace = container_create(C_WORKSPACE); | ||
415 | |||
416 | workspace->x = output->x; | ||
417 | workspace->y = output->y; | ||
418 | workspace->width = output->width; | ||
419 | workspace->height = output->height; | ||
420 | workspace->name = !name ? NULL : strdup(name); | ||
421 | workspace->prev_layout = L_NONE; | ||
422 | workspace->layout = container_get_default_layout(output); | ||
423 | workspace->workspace_layout = workspace->layout; | ||
424 | |||
425 | container_add_child(output, workspace); | ||
426 | container_sort_workspaces(output); | ||
427 | notify_new_container(workspace); | ||
428 | |||
429 | return workspace; | ||
430 | } | ||
431 | |||
432 | struct sway_container *container_view_create(struct sway_container *sibling, | 380 | struct sway_container *container_view_create(struct sway_container *sibling, |
433 | struct sway_view *sway_view) { | 381 | struct sway_view *sway_view) { |
434 | if (!sway_assert(sibling, | 382 | if (!sway_assert(sibling, |
@@ -452,7 +400,7 @@ struct sway_container *container_view_create(struct sway_container *sibling, | |||
452 | // Regular case, create as sibling of current container | 400 | // Regular case, create as sibling of current container |
453 | container_add_sibling(sibling, swayc); | 401 | container_add_sibling(sibling, swayc); |
454 | } | 402 | } |
455 | notify_new_container(swayc); | 403 | container_create_notify(swayc); |
456 | return swayc; | 404 | return swayc; |
457 | } | 405 | } |
458 | 406 | ||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 3cbbf3b4..a46359bd 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -149,7 +149,7 @@ void container_move_to(struct sway_container *container, | |||
149 | if (old_parent->children->length == 0) { | 149 | if (old_parent->children->length == 0) { |
150 | char *ws_name = workspace_next_name(old_parent->name); | 150 | char *ws_name = workspace_next_name(old_parent->name); |
151 | struct sway_container *ws = | 151 | struct sway_container *ws = |
152 | container_workspace_create(old_parent, ws_name); | 152 | workspace_create(old_parent, ws_name); |
153 | free(ws_name); | 153 | free(ws_name); |
154 | seat_set_focus(seat, ws); | 154 | seat_set_focus(seat, ws); |
155 | } | 155 | } |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d5a16410..6ba3d973 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -14,6 +14,58 @@ | |||
14 | #include "log.h" | 14 | #include "log.h" |
15 | #include "util.h" | 15 | #include "util.h" |
16 | 16 | ||
17 | static struct sway_container *get_workspace_initial_output(const char *name) { | ||
18 | struct sway_container *parent; | ||
19 | // Search for workspace<->output pair | ||
20 | int e = config->workspace_outputs->length; | ||
21 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | ||
22 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
23 | if (strcasecmp(wso->workspace, name) == 0) { | ||
24 | // Find output to use if it exists | ||
25 | e = root_container.children->length; | ||
26 | for (i = 0; i < e; ++i) { | ||
27 | parent = root_container.children->items[i]; | ||
28 | if (strcmp(parent->name, wso->output) == 0) { | ||
29 | return parent; | ||
30 | } | ||
31 | } | ||
32 | break; | ||
33 | } | ||
34 | } | ||
35 | // Otherwise put it on the focused output | ||
36 | struct sway_seat *seat = input_manager_current_seat(input_manager); | ||
37 | struct sway_container *focus = | ||
38 | seat_get_focus_inactive(seat, &root_container); | ||
39 | parent = focus; | ||
40 | parent = container_parent(parent, C_OUTPUT); | ||
41 | return parent; | ||
42 | } | ||
43 | |||
44 | struct sway_container *workspace_create(struct sway_container *output, | ||
45 | const char *name) { | ||
46 | if (output == NULL) { | ||
47 | output = get_workspace_initial_output(name); | ||
48 | } | ||
49 | |||
50 | wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name); | ||
51 | struct sway_container *workspace = container_create(C_WORKSPACE); | ||
52 | |||
53 | workspace->x = output->x; | ||
54 | workspace->y = output->y; | ||
55 | workspace->width = output->width; | ||
56 | workspace->height = output->height; | ||
57 | workspace->name = !name ? NULL : strdup(name); | ||
58 | workspace->prev_layout = L_NONE; | ||
59 | workspace->layout = container_get_default_layout(output); | ||
60 | workspace->workspace_layout = workspace->layout; | ||
61 | |||
62 | container_add_child(output, workspace); | ||
63 | container_sort_workspaces(output); | ||
64 | container_create_notify(workspace); | ||
65 | |||
66 | return workspace; | ||
67 | } | ||
68 | |||
17 | char *prev_workspace_name = NULL; | 69 | char *prev_workspace_name = NULL; |
18 | struct workspace_by_number_data { | 70 | struct workspace_by_number_data { |
19 | int len; | 71 | int len; |
@@ -292,7 +344,7 @@ bool workspace_switch(struct sway_container *workspace) { | |||
292 | struct sway_container *new_ws = workspace_by_name(prev_workspace_name); | 344 | struct sway_container *new_ws = workspace_by_name(prev_workspace_name); |
293 | workspace = new_ws ? | 345 | workspace = new_ws ? |
294 | new_ws : | 346 | new_ws : |
295 | container_workspace_create(NULL, prev_workspace_name); | 347 | workspace_create(NULL, prev_workspace_name); |
296 | } | 348 | } |
297 | 349 | ||
298 | if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name) | 350 | if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name) |