diff options
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 64 | ||||
-rw-r--r-- | sway/tree/layout.c | 37 |
2 files changed, 93 insertions, 8 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index e205fbcf..5df10bcb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -2,10 +2,13 @@ | |||
2 | #include <stdint.h> | 2 | #include <stdint.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <strings.h> | ||
5 | #include <wlr/types/wlr_output_layout.h> | 6 | #include <wlr/types/wlr_output_layout.h> |
7 | #include "sway/config.h" | ||
6 | #include "sway/container.h" | 8 | #include "sway/container.h" |
7 | #include "sway/layout.h" | 9 | #include "sway/layout.h" |
8 | #include "sway/output.h" | 10 | #include "sway/output.h" |
11 | #include "sway/server.h" | ||
9 | #include "sway/view.h" | 12 | #include "sway/view.h" |
10 | #include "sway/workspace.h" | 13 | #include "sway/workspace.h" |
11 | #include "log.h" | 14 | #include "log.h" |
@@ -44,19 +47,38 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
44 | 47 | ||
45 | swayc_t *new_output(struct sway_output *sway_output) { | 48 | swayc_t *new_output(struct sway_output *sway_output) { |
46 | struct wlr_box size; | 49 | struct wlr_box size; |
47 | wlr_output_effective_resolution( | 50 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
48 | sway_output->wlr_output, &size.width, &size.height); | 51 | &size.height); |
49 | const char *name = sway_output->wlr_output->name; | 52 | const char *name = sway_output->wlr_output->name; |
50 | 53 | ||
54 | struct output_config *oc = NULL, *all = NULL; | ||
55 | for (int i = 0; i < config->output_configs->length; ++i) { | ||
56 | struct output_config *cur = config->output_configs->items[i]; | ||
57 | if (strcasecmp(name, cur->name) == 0) { | ||
58 | sway_log(L_DEBUG, "Matched output config for %s", name); | ||
59 | oc = cur; | ||
60 | } | ||
61 | if (strcasecmp("*", cur->name) == 0) { | ||
62 | sway_log(L_DEBUG, "Matched wildcard output config for %s", name); | ||
63 | all = cur; | ||
64 | } | ||
65 | |||
66 | if (oc && all) { | ||
67 | break; | ||
68 | } | ||
69 | } | ||
70 | if (!oc) { | ||
71 | oc = all; | ||
72 | } | ||
73 | if (oc && !oc->enabled) { | ||
74 | return NULL; | ||
75 | } | ||
76 | |||
51 | swayc_t *output = new_swayc(C_OUTPUT); | 77 | swayc_t *output = new_swayc(C_OUTPUT); |
52 | output->sway_output = sway_output; | 78 | output->sway_output = sway_output; |
53 | output->name = name ? strdup(name) : NULL; | 79 | output->name = name ? strdup(name) : NULL; |
54 | output->width = size.width; | ||
55 | output->height = size.width; | ||
56 | 80 | ||
57 | // TODO configure output layout position | 81 | apply_output_config(oc, output); |
58 | wlr_output_layout_add_auto(root_container.output_layout, | ||
59 | sway_output->wlr_output); | ||
60 | 82 | ||
61 | add_child(&root_container, output); | 83 | add_child(&root_container, output); |
62 | 84 | ||
@@ -139,6 +161,34 @@ static void free_swayc(swayc_t *cont) { | |||
139 | free(cont); | 161 | free(cont); |
140 | } | 162 | } |
141 | 163 | ||
164 | swayc_t *destroy_output(swayc_t *output) { | ||
165 | if (!sway_assert(output, "null output passed to destroy_output")) { | ||
166 | return NULL; | ||
167 | } | ||
168 | |||
169 | if (output->children->length > 0) { | ||
170 | // TODO save workspaces when there are no outputs. | ||
171 | // TODO also check if there will ever be no outputs except for exiting | ||
172 | // program | ||
173 | if (root_container.children->length > 1) { | ||
174 | int p = root_container.children->items[0] == output; | ||
175 | // Move workspace from this output to another output | ||
176 | while (output->children->length) { | ||
177 | swayc_t *child = output->children->items[0]; | ||
178 | remove_child(child); | ||
179 | add_child(root_container.children->items[p], child); | ||
180 | } | ||
181 | sort_workspaces(root_container.children->items[p]); | ||
182 | arrange_windows(root_container.children->items[p], -1, -1); | ||
183 | } | ||
184 | } | ||
185 | |||
186 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | ||
187 | free_swayc(output); | ||
188 | |||
189 | return &root_container; | ||
190 | } | ||
191 | |||
142 | swayc_t *destroy_view(swayc_t *view) { | 192 | swayc_t *destroy_view(swayc_t *view) { |
143 | if (!sway_assert(view, "null view passed to destroy_view")) { | 193 | if (!sway_assert(view, "null view passed to destroy_view")) { |
144 | return NULL; | 194 | return NULL; |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index cb39a361..4bcf0e2f 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
9 | #include "sway/container.h" | 9 | #include "sway/container.h" |
10 | #include "sway/layout.h" | ||
10 | #include "sway/output.h" | 11 | #include "sway/output.h" |
11 | #include "sway/view.h" | 12 | #include "sway/view.h" |
12 | #include "list.h" | 13 | #include "list.h" |
@@ -14,13 +15,47 @@ | |||
14 | 15 | ||
15 | swayc_t root_container; | 16 | swayc_t root_container; |
16 | 17 | ||
18 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { | ||
19 | struct wlr_box *layout_box = wlr_output_layout_get_box( | ||
20 | root_container.sway_root->output_layout, NULL); | ||
21 | root_container.width = layout_box->width; | ||
22 | root_container.height = layout_box->height; | ||
23 | |||
24 | for (int i = 0 ; i < root_container.children->length; ++i) { | ||
25 | swayc_t *output_container = root_container.children->items[i]; | ||
26 | if (output_container->type != C_OUTPUT) { | ||
27 | continue; | ||
28 | } | ||
29 | struct sway_output *output = output_container->sway_output; | ||
30 | |||
31 | struct wlr_box *output_box = wlr_output_layout_get_box( | ||
32 | root_container.sway_root->output_layout, output->wlr_output); | ||
33 | if (!output_box) { | ||
34 | continue; | ||
35 | } | ||
36 | output_container->x = output_box->x; | ||
37 | output_container->y = output_box->y; | ||
38 | output_container->width = output_box->width; | ||
39 | output_container->height = output_box->height; | ||
40 | } | ||
41 | |||
42 | arrange_windows(&root_container, -1, -1); | ||
43 | } | ||
44 | |||
17 | void init_layout(void) { | 45 | void init_layout(void) { |
18 | root_container.id = 0; // normally assigned in new_swayc() | 46 | root_container.id = 0; // normally assigned in new_swayc() |
19 | root_container.type = C_ROOT; | 47 | root_container.type = C_ROOT; |
20 | root_container.layout = L_NONE; | 48 | root_container.layout = L_NONE; |
21 | root_container.name = strdup("root"); | 49 | root_container.name = strdup("root"); |
22 | root_container.children = create_list(); | 50 | root_container.children = create_list(); |
23 | root_container.output_layout = wlr_output_layout_create(); | 51 | |
52 | root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); | ||
53 | root_container.sway_root->output_layout = wlr_output_layout_create(); | ||
54 | |||
55 | root_container.sway_root->output_layout_change.notify = | ||
56 | output_layout_change_notify; | ||
57 | wl_signal_add(&root_container.sway_root->output_layout->events.change, | ||
58 | &root_container.sway_root->output_layout_change); | ||
24 | } | 59 | } |
25 | 60 | ||
26 | void add_child(swayc_t *parent, swayc_t *child) { | 61 | void add_child(swayc_t *parent, swayc_t *child) { |