diff options
Diffstat (limited to 'sway/tree/output.c')
-rw-r--r-- | sway/tree/output.c | 96 |
1 files changed, 59 insertions, 37 deletions
diff --git a/sway/tree/output.c b/sway/tree/output.c index 0509db23..6c7044a2 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c | |||
@@ -1,51 +1,73 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <string.h> | ||
1 | #include <strings.h> | 3 | #include <strings.h> |
2 | #include "sway/tree/container.h" | ||
3 | #include "sway/tree/layout.h" | ||
4 | #include "sway/output.h" | 4 | #include "sway/output.h" |
5 | #include "sway/tree/output.h" | ||
6 | #include "sway/tree/workspace.h" | ||
5 | #include "log.h" | 7 | #include "log.h" |
6 | 8 | ||
7 | struct sway_container *container_output_destroy(struct sway_container *output) { | 9 | struct sway_container *output_create( |
8 | if (!sway_assert(output, "cannot destroy null output")) { | 10 | struct sway_output *sway_output) { |
9 | return NULL; | 11 | struct wlr_box size; |
10 | } | 12 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
13 | &size.height); | ||
14 | |||
15 | const char *name = sway_output->wlr_output->name; | ||
16 | char identifier[128]; | ||
17 | output_get_identifier(identifier, sizeof(identifier), sway_output); | ||
18 | |||
19 | struct output_config *oc = NULL, *all = NULL; | ||
20 | for (int i = 0; i < config->output_configs->length; ++i) { | ||
21 | struct output_config *cur = config->output_configs->items[i]; | ||
11 | 22 | ||
12 | if (output->children->length > 0) { | 23 | if (strcasecmp(name, cur->name) == 0 || |
13 | // TODO save workspaces when there are no outputs. | 24 | strcasecmp(identifier, cur->name) == 0) { |
14 | // TODO also check if there will ever be no outputs except for exiting | 25 | wlr_log(L_DEBUG, "Matched output config for %s", name); |
15 | // program | 26 | oc = cur; |
16 | if (root_container.children->length > 1) { | ||
17 | int p = root_container.children->items[0] == output; | ||
18 | // Move workspace from this output to another output | ||
19 | while (output->children->length) { | ||
20 | struct sway_container *child = output->children->items[0]; | ||
21 | container_remove_child(child); | ||
22 | container_add_child(root_container.children->items[p], child); | ||
23 | } | ||
24 | container_sort_workspaces(root_container.children->items[p]); | ||
25 | arrange_windows(root_container.children->items[p], | ||
26 | -1, -1); | ||
27 | } | 27 | } |
28 | if (strcasecmp("*", cur->name) == 0) { | ||
29 | wlr_log(L_DEBUG, "Matched wildcard output config for %s", name); | ||
30 | all = cur; | ||
31 | } | ||
32 | |||
33 | if (oc && all) { | ||
34 | break; | ||
35 | } | ||
36 | } | ||
37 | if (!oc) { | ||
38 | oc = all; | ||
28 | } | 39 | } |
29 | 40 | ||
30 | wl_list_remove(&output->sway_output->destroy.link); | 41 | if (oc && !oc->enabled) { |
31 | wl_list_remove(&output->sway_output->mode.link); | 42 | return NULL; |
32 | wl_list_remove(&output->sway_output->transform.link); | 43 | } |
33 | wl_list_remove(&output->sway_output->scale.link); | ||
34 | 44 | ||
35 | wl_list_remove(&output->sway_output->damage_destroy.link); | 45 | struct sway_container *output = container_create(C_OUTPUT); |
36 | wl_list_remove(&output->sway_output->damage_frame.link); | 46 | output->sway_output = sway_output; |
47 | output->name = strdup(name); | ||
48 | if (output->name == NULL) { | ||
49 | container_destroy(output); | ||
50 | return NULL; | ||
51 | } | ||
37 | 52 | ||
38 | wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | 53 | apply_output_config(oc, output); |
39 | container_destroy(output); | 54 | container_add_child(&root_container, output); |
40 | return &root_container; | 55 | load_swaybars(); |
41 | } | ||
42 | 56 | ||
43 | struct sway_container *output_by_name(const char *name) { | 57 | // Create workspace |
44 | for (int i = 0; i < root_container.children->length; ++i) { | 58 | char *ws_name = workspace_next_name(output->name); |
45 | struct sway_container *output = root_container.children->items[i]; | 59 | wlr_log(L_DEBUG, "Creating default workspace %s", ws_name); |
46 | if (strcasecmp(output->name, name) == 0){ | 60 | struct sway_container *ws = workspace_create(output, ws_name); |
47 | return output; | 61 | // Set each seat's focus if not already set |
62 | struct sway_seat *seat = NULL; | ||
63 | wl_list_for_each(seat, &input_manager->seats, link) { | ||
64 | if (!seat->has_focus) { | ||
65 | seat_set_focus(seat, ws); | ||
48 | } | 66 | } |
49 | } | 67 | } |
50 | return NULL; | 68 | |
69 | free(ws_name); | ||
70 | container_create_notify(output); | ||
71 | return output; | ||
51 | } | 72 | } |
73 | |||