aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2017-12-29 19:04:16 +0100
committerLibravatar emersion <contact@emersion.fr>2017-12-29 19:04:16 +0100
commitead3f1e676923b0457cef77b0b482e76cac50307 (patch)
tree6a4c75b23de360d4eadbf4e1aa647a0d93c81eb2
parentMerge pull request #1542 from emersion/swaymsg-output (diff)
downloadsway-ead3f1e676923b0457cef77b0b482e76cac50307.tar.gz
sway-ead3f1e676923b0457cef77b0b482e76cac50307.tar.zst
sway-ead3f1e676923b0457cef77b0b482e76cac50307.zip
Allow to configure outputs by their identifier
-rw-r--r--include/sway/config.h2
-rw-r--r--sway/commands/output.c46
-rw-r--r--sway/config/output.c8
-rw-r--r--sway/tree/container.c70
4 files changed, 75 insertions, 51 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 045359ca..eecdde3a 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -397,6 +397,8 @@ struct seat_attachment_config *seat_config_get_attachment(
397void apply_seat_config(struct seat_config *seat); 397void apply_seat_config(struct seat_config *seat);
398 398
399int output_name_cmp(const void *item, const void *data); 399int output_name_cmp(const void *item, const void *data);
400void output_get_identifier(char *identifier, size_t len,
401 struct sway_output *output);
400struct output_config *new_output_config(const char *name); 402struct output_config *new_output_config(const char *name);
401void merge_output_config(struct output_config *dst, struct output_config *src); 403void merge_output_config(struct output_config *dst, struct output_config *src);
402void apply_output_config(struct output_config *oc, swayc_t *output); 404void apply_output_config(struct output_config *oc, swayc_t *output);
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 8cc74bcc..8c0fa63c 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -231,8 +231,8 @@ static struct cmd_results *cmd_output_background(struct output_config *output,
231} 231}
232 232
233struct cmd_results *cmd_output(int argc, char **argv) { 233struct cmd_results *cmd_output(int argc, char **argv) {
234 struct cmd_results *error = NULL; 234 struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1);
235 if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { 235 if (error != NULL) {
236 return error; 236 return error;
237 } 237 }
238 238
@@ -275,11 +275,11 @@ struct cmd_results *cmd_output(int argc, char **argv) {
275 275
276 int i = list_seq_find(config->output_configs, output_name_cmp, output->name); 276 int i = list_seq_find(config->output_configs, output_name_cmp, output->name);
277 if (i >= 0) { 277 if (i >= 0) {
278 // merge existing config 278 // Merge existing config
279 struct output_config *oc = config->output_configs->items[i]; 279 struct output_config *current = config->output_configs->items[i];
280 merge_output_config(oc, output); 280 merge_output_config(current, output);
281 free_output_config(output); 281 free_output_config(output);
282 output = oc; 282 output = current;
283 } else { 283 } else {
284 list_add(config->output_configs, output); 284 list_add(config->output_configs, output);
285 } 285 }
@@ -290,22 +290,26 @@ struct cmd_results *cmd_output(int argc, char **argv) {
290 output->refresh_rate, output->x, output->y, output->scale, 290 output->refresh_rate, output->x, output->y, output->scale,
291 output->transform, output->background, output->background_option); 291 output->transform, output->background, output->background_option);
292 292
293 if (output->name) { 293 // Try to find the output container and apply configuration now. If
294 // Try to find the output container and apply configuration now. If 294 // this is during startup then there will be no container and config
295 // this is during startup then there will be no container and config 295 // will be applied during normal "new output" event from wlroots.
296 // will be applied during normal "new output" event from wlroots. 296 char identifier[128];
297 swayc_t *cont = NULL; 297 bool all = strcmp(output->name, "*") == 0;
298 for (int i = 0; i < root_container.children->length; ++i) { 298 for (int i = 0; i < root_container.children->length; ++i) {
299 cont = root_container.children->items[i]; 299 swayc_t *cont = root_container.children->items[i];
300 if (cont->name && ((strcmp(cont->name, output->name) == 0) || 300 if (cont->type != C_OUTPUT) {
301 (strcmp(output->name, "*") == 0))) { 301 continue;
302 apply_output_config(output, cont); 302 }
303 303
304 if (strcmp(output->name, "*") != 0) { 304 output_get_identifier(identifier, sizeof(identifier), cont->sway_output);
305 // Stop looking if the output config isn't applicable to all 305 if (all || strcmp(cont->name, output->name) == 0 ||
306 // outputs 306 strcmp(identifier, output->name) == 0) {
307 break; 307 apply_output_config(output, cont);
308 } 308
309 if (!all) {
310 // Stop looking if the output config isn't applicable to all
311 // outputs
312 break;
309 } 313 }
310 } 314 }
311 } 315 }
diff --git a/sway/config/output.c b/sway/config/output.c
index f336c949..e798a20e 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -1,4 +1,5 @@
1#define _XOPEN_SOURCE 700 1#define _XOPEN_SOURCE 700
2#include <stdbool.h>
2#include <string.h> 3#include <string.h>
3#include <assert.h> 4#include <assert.h>
4#include <wlr/types/wlr_output.h> 5#include <wlr/types/wlr_output.h>
@@ -14,6 +15,13 @@ int output_name_cmp(const void *item, const void *data) {
14 return strcmp(output->name, name); 15 return strcmp(output->name, name);
15} 16}
16 17
18void output_get_identifier(char *identifier, size_t len,
19 struct sway_output *output) {
20 struct wlr_output *wlr_output = output->wlr_output;
21 snprintf(identifier, len, "%s %s %s", wlr_output->make, wlr_output->model,
22 wlr_output->serial);
23}
24
17struct output_config *new_output_config(const char *name) { 25struct output_config *new_output_config(const char *name) {
18 struct output_config *oc = calloc(1, sizeof(struct output_config)); 26 struct output_config *oc = calloc(1, sizeof(struct output_config));
19 if (oc == NULL) { 27 if (oc == NULL) {
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 6f2a3abf..c5574275 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -49,16 +49,49 @@ static swayc_t *new_swayc(enum swayc_types type) {
49 return c; 49 return c;
50} 50}
51 51
52static void free_swayc(swayc_t *cont) {
53 if (!sway_assert(cont, "free_swayc passed NULL")) {
54 return;
55 }
56
57 wl_signal_emit(&cont->events.destroy, cont);
58
59 if (cont->children) {
60 // remove children until there are no more, free_swayc calls
61 // remove_child, which removes child from this container
62 while (cont->children->length) {
63 free_swayc(cont->children->items[0]);
64 }
65 list_free(cont->children);
66 }
67 if (cont->marks) {
68 list_foreach(cont->marks, free);
69 list_free(cont->marks);
70 }
71 if (cont->parent) {
72 remove_child(cont);
73 }
74 if (cont->name) {
75 free(cont->name);
76 }
77 free(cont);
78}
79
52swayc_t *new_output(struct sway_output *sway_output) { 80swayc_t *new_output(struct sway_output *sway_output) {
53 struct wlr_box size; 81 struct wlr_box size;
54 wlr_output_effective_resolution(sway_output->wlr_output, &size.width, 82 wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
55 &size.height); 83 &size.height);
84
56 const char *name = sway_output->wlr_output->name; 85 const char *name = sway_output->wlr_output->name;
86 char identifier[128];
87 output_get_identifier(identifier, sizeof(identifier), sway_output);
57 88
58 struct output_config *oc = NULL, *all = NULL; 89 struct output_config *oc = NULL, *all = NULL;
59 for (int i = 0; i < config->output_configs->length; ++i) { 90 for (int i = 0; i < config->output_configs->length; ++i) {
60 struct output_config *cur = config->output_configs->items[i]; 91 struct output_config *cur = config->output_configs->items[i];
61 if (strcasecmp(name, cur->name) == 0) { 92
93 if (strcasecmp(name, cur->name) == 0 ||
94 strcasecmp(identifier, cur->name) == 0) {
62 sway_log(L_DEBUG, "Matched output config for %s", name); 95 sway_log(L_DEBUG, "Matched output config for %s", name);
63 oc = cur; 96 oc = cur;
64 } 97 }
@@ -74,13 +107,18 @@ swayc_t *new_output(struct sway_output *sway_output) {
74 if (!oc) { 107 if (!oc) {
75 oc = all; 108 oc = all;
76 } 109 }
110
77 if (oc && !oc->enabled) { 111 if (oc && !oc->enabled) {
78 return NULL; 112 return NULL;
79 } 113 }
80 114
81 swayc_t *output = new_swayc(C_OUTPUT); 115 swayc_t *output = new_swayc(C_OUTPUT);
82 output->sway_output = sway_output; 116 output->sway_output = sway_output;
83 output->name = name ? strdup(name) : NULL; 117 output->name = strdup(name);
118 if (output->name == NULL) {
119 free_swayc(output);
120 return NULL;
121 }
84 122
85 apply_output_config(oc, output); 123 apply_output_config(oc, output);
86 124
@@ -140,34 +178,6 @@ swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view) {
140 return swayc; 178 return swayc;
141} 179}
142 180
143static void free_swayc(swayc_t *cont) {
144 if (!sway_assert(cont, "free_swayc passed NULL")) {
145 return;
146 }
147
148 wl_signal_emit(&cont->events.destroy, cont);
149
150 if (cont->children) {
151 // remove children until there are no more, free_swayc calls
152 // remove_child, which removes child from this container
153 while (cont->children->length) {
154 free_swayc(cont->children->items[0]);
155 }
156 list_free(cont->children);
157 }
158 if (cont->marks) {
159 list_foreach(cont->marks, free);
160 list_free(cont->marks);
161 }
162 if (cont->parent) {
163 remove_child(cont);
164 }
165 if (cont->name) {
166 free(cont->name);
167 }
168 free(cont);
169}
170
171swayc_t *destroy_output(swayc_t *output) { 181swayc_t *destroy_output(swayc_t *output) {
172 if (!sway_assert(output, "null output passed to destroy_output")) { 182 if (!sway_assert(output, "null output passed to destroy_output")) {
173 return NULL; 183 return NULL;