summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-10-21 18:24:07 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-10-21 18:24:07 -0400
commit3e2579b22cb76e098e78aec62c3c40a4bde0e394 (patch)
treeadd4f0b2a97d46fc8ddbd34d61656b3474592083
parentMerge pull request #196 from sce/catch_empty_command (diff)
parentcommands: Allow changing resolution outside config load. (diff)
downloadsway-3e2579b22cb76e098e78aec62c3c40a4bde0e394.tar.gz
sway-3e2579b22cb76e098e78aec62c3c40a4bde0e394.tar.zst
sway-3e2579b22cb76e098e78aec62c3c40a4bde0e394.zip
Merge pull request #197 from sce/configure_outputs_during_reload_
Configure outputs during reload
-rw-r--r--include/config.h3
-rw-r--r--sway/commands.c17
-rw-r--r--sway/config.c29
-rw-r--r--sway/container.c32
4 files changed, 51 insertions, 30 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 eb77c172..7605a36b 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -561,7 +561,6 @@ static enum cmd_status cmd_orientation(int argc, char **argv) {
561} 561}
562 562
563static enum cmd_status cmd_output(int argc, char **argv) { 563static enum cmd_status cmd_output(int argc, char **argv) {
564 if (!config->reading) return CMD_FAILURE;
565 if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { 564 if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) {
566 return CMD_FAILURE; 565 return CMD_FAILURE;
567 } 566 }
@@ -619,9 +618,23 @@ static enum cmd_status cmd_output(int argc, char **argv) {
619 618
620 list_add(config->output_configs, output); 619 list_add(config->output_configs, output);
621 620
622 sway_log(L_DEBUG, "Configured output %s to %d x %d @ %d, %d", 621 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); 622 output->name, output->width, output->height, output->x, output->y);
624 623
624 if (output->name) {
625 // Try to find the output container and apply configuration now. If
626 // this is during startup then there will be no container and config
627 // will be applied during normal "new output" event from wlc.
628 swayc_t *cont = NULL;
629 for (int i = 0; i < root_container.children->length; ++i) {
630 cont = root_container.children->items[i];
631 if (cont->name && strcmp(cont->name, output->name) == 0) {
632 apply_output_config(output, cont);
633 break;
634 }
635 }
636 }
637
625 return CMD_SUCCESS; 638 return CMD_SUCCESS;
626} 639}
627 640
diff --git a/sway/config.c b/sway/config.c
index 46a26424..bce074b9 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 > 0 && oc->height > 0) {
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 4c523827..6c4206fb 100644
--- a/sway/container.c
+++ b/sway/container.c
@@ -70,7 +70,7 @@ swayc_t *new_output(wlc_handle handle) {
70 } 70 }
71 } 71 }
72 72
73 sway_log(L_DEBUG, "Added output %lu:%s", handle, name); 73 sway_log(L_DEBUG, "New output %lu:%s", handle, name);
74 74
75 struct output_config *oc = NULL; 75 struct output_config *oc = NULL;
76 int i; 76 int i;
@@ -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