summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-21 16:34:12 +0200
committerLibravatar S. Christoffer Eliesen <christoffer@eliesen.no>2015-10-21 23:24:06 +0200
commitca862a5bd45ef094d0f0de5a0765224524b74c48 (patch)
treeea2b673e5929de337b7444614b0d976bc07c3460
parentcommands,container: Tweak debug output to better reflect reality. (diff)
downloadsway-ca862a5bd45ef094d0f0de5a0765224524b74c48.tar.gz
sway-ca862a5bd45ef094d0f0de5a0765224524b74c48.tar.zst
sway-ca862a5bd45ef094d0f0de5a0765224524b74c48.zip
config: Apply output config also during config reload.
-rw-r--r--include/config.h3
-rw-r--r--sway/commands.c14
-rw-r--r--sway/config.c29
-rw-r--r--sway/container.c30
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
10struct sway_variable { 11struct sway_variable {
11 char *name; 12 char *name;
@@ -62,6 +63,8 @@ struct sway_config {
62bool load_config(const char *file); 63bool load_config(const char *file);
63bool read_config(FILE *file, bool is_active); 64bool read_config(FILE *file, bool is_active);
64char *do_var_replacement(char *str); 65char *do_var_replacement(char *str);
66// Setup output container by applying given config
67void apply_output_config(struct output_config *oc, swayc_t *output);
65 68
66extern struct sway_config *config; 69extern 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
286void 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
286char *do_var_replacement(char *str) { 315char *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