diff options
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 14 | ||||
-rw-r--r-- | sway/config.c | 29 | ||||
-rw-r--r-- | sway/container.c | 30 |
4 files changed, 49 insertions, 27 deletions
diff --git a/include/config.h b/include/config.h index 676218c8..2a8e36fa 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <xkbcommon/xkbcommon.h> | 6 | #include <xkbcommon/xkbcommon.h> |
7 | #include "list.h" | 7 | #include "list.h" |
8 | #include "layout.h" | 8 | #include "layout.h" |
9 | #include "container.h" | ||
9 | 10 | ||
10 | struct sway_variable { | 11 | struct sway_variable { |
11 | char *name; | 12 | char *name; |
@@ -62,6 +63,8 @@ struct sway_config { | |||
62 | bool load_config(const char *file); | 63 | bool load_config(const char *file); |
63 | bool read_config(FILE *file, bool is_active); | 64 | bool read_config(FILE *file, bool is_active); |
64 | char *do_var_replacement(char *str); | 65 | char *do_var_replacement(char *str); |
66 | // Setup output container by applying given config | ||
67 | void apply_output_config(struct output_config *oc, swayc_t *output); | ||
65 | 68 | ||
66 | extern struct sway_config *config; | 69 | extern struct sway_config *config; |
67 | 70 | ||
diff --git a/sway/commands.c b/sway/commands.c index 7b026fd2..9eb0928e 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -622,6 +622,20 @@ static enum cmd_status cmd_output(int argc, char **argv) { | |||
622 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d)", | 622 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d)", |
623 | output->name, output->width, output->height, output->x, output->y); | 623 | output->name, output->width, output->height, output->x, output->y); |
624 | 624 | ||
625 | if (output->name) { | ||
626 | // Try to find the output container and apply configuration now. If | ||
627 | // this is during startup then there will be no container and config | ||
628 | // will be applied during normal "new output" event from wlc. | ||
629 | swayc_t *cont = NULL; | ||
630 | for (int i = 0; i < root_container.children->length; ++i) { | ||
631 | cont = root_container.children->items[i]; | ||
632 | if (cont->name && strcmp(cont->name, output->name) == 0) { | ||
633 | apply_output_config(output, cont); | ||
634 | break; | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | |||
625 | return CMD_SUCCESS; | 639 | return CMD_SUCCESS; |
626 | } | 640 | } |
627 | 641 | ||
diff --git a/sway/config.c b/sway/config.c index 46a26424..b5d442c5 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -283,6 +283,35 @@ bool read_config(FILE *file, bool is_active) { | |||
283 | return success; | 283 | return success; |
284 | } | 284 | } |
285 | 285 | ||
286 | void apply_output_config(struct output_config *oc, swayc_t *output) { | ||
287 | if (oc && oc->width != -1 && oc->height != -1) { | ||
288 | output->width = oc->width; | ||
289 | output->height = oc->height; | ||
290 | |||
291 | sway_log(L_DEBUG, "Set %s size to %ix%i", oc->name, oc->width, oc->height); | ||
292 | struct wlc_size new_size = { .w = oc->width, .h = oc->height }; | ||
293 | wlc_output_set_resolution(output->handle, &new_size); | ||
294 | } | ||
295 | |||
296 | // Find position for it | ||
297 | if (oc && oc->x != -1 && oc->y != -1) { | ||
298 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); | ||
299 | output->x = oc->x; | ||
300 | output->y = oc->y; | ||
301 | } else { | ||
302 | int x = 0; | ||
303 | for (int i = 0; i < root_container.children->length; ++i) { | ||
304 | swayc_t *c = root_container.children->items[i]; | ||
305 | if (c->type == C_OUTPUT) { | ||
306 | if (c->width + c->x > x) { | ||
307 | x = c->width + c->x; | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | output->x = x; | ||
312 | } | ||
313 | } | ||
314 | |||
286 | char *do_var_replacement(char *str) { | 315 | char *do_var_replacement(char *str) { |
287 | int i; | 316 | int i; |
288 | char *find = str; | 317 | char *find = str; |
diff --git a/sway/container.c b/sway/container.c index b8ff7150..6c4206fb 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -88,36 +88,12 @@ swayc_t *new_output(wlc_handle handle) { | |||
88 | } | 88 | } |
89 | 89 | ||
90 | swayc_t *output = new_swayc(C_OUTPUT); | 90 | swayc_t *output = new_swayc(C_OUTPUT); |
91 | if (oc && oc->width != -1 && oc->height != -1) { | ||
92 | output->width = oc->width; | ||
93 | output->height = oc->height; | ||
94 | struct wlc_size new_size = { .w = oc->width, .h = oc->height }; | ||
95 | wlc_output_set_resolution(handle, &new_size); | ||
96 | } else { | ||
97 | output->width = size->w; | ||
98 | output->height = size->h; | ||
99 | } | ||
100 | output->handle = handle; | 91 | output->handle = handle; |
101 | output->name = name ? strdup(name) : NULL; | 92 | output->name = name ? strdup(name) : NULL; |
102 | 93 | output->width = size->w; | |
103 | // Find position for it | 94 | output->height = size->h; |
104 | if (oc && oc->x != -1 && oc->y != -1) { | ||
105 | sway_log(L_DEBUG, "Set %s position to %d, %d", name, oc->x, oc->y); | ||
106 | output->x = oc->x; | ||
107 | output->y = oc->y; | ||
108 | } else { | ||
109 | int x = 0; | ||
110 | for (i = 0; i < root_container.children->length; ++i) { | ||
111 | swayc_t *c = root_container.children->items[i]; | ||
112 | if (c->type == C_OUTPUT) { | ||
113 | if (c->width + c->x > x) { | ||
114 | x = c->width + c->x; | ||
115 | } | ||
116 | } | ||
117 | } | ||
118 | output->x = x; | ||
119 | } | ||
120 | 95 | ||
96 | apply_output_config(oc, output); | ||
121 | add_child(&root_container, output); | 97 | add_child(&root_container, output); |
122 | 98 | ||
123 | // Create workspace | 99 | // Create workspace |