aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-20 12:32:29 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-20 12:32:29 -0400
commit9605ab45f1c863076bd68acfb1d2e5d25c1b285d (patch)
tree51d76189b5a38150001c16d520ad72ed4876874f /sway/commands/output.c
parentMerge pull request #2313 from minus7/swaybar-hotspot-input-fix (diff)
downloadsway-9605ab45f1c863076bd68acfb1d2e5d25c1b285d.tar.gz
sway-9605ab45f1c863076bd68acfb1d2e5d25c1b285d.tar.zst
sway-9605ab45f1c863076bd68acfb1d2e5d25c1b285d.zip
Fix output wildcard handling
Diffstat (limited to 'sway/commands/output.c')
-rw-r--r--sway/commands/output.c104
1 files changed, 56 insertions, 48 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 15bbd687..4d98162b 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -21,6 +21,60 @@ static struct cmd_handler output_handlers[] = {
21 { "transform", output_cmd_transform }, 21 { "transform", output_cmd_transform },
22}; 22};
23 23
24static struct output_config *get_output_config(char *name, char *identifier) {
25 int i = list_seq_find(config->output_configs, output_name_cmp, name);
26 if (i >= 0) {
27 return config->output_configs->items[i];
28 }
29
30 i = list_seq_find(config->output_configs, output_name_cmp, identifier);
31 if (i >= 0) {
32 return config->output_configs->items[i];
33 }
34
35 return NULL;
36}
37
38static void apply_output_config_to_outputs(struct output_config *oc) {
39 // Try to find the output container and apply configuration now. If
40 // this is during startup then there will be no container and config
41 // will be applied during normal "new output" event from wlroots.
42 bool wildcard = strcmp(oc->name, "*") == 0;
43 char id[128];
44 struct sway_output *sway_output;
45 wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
46 char *name = sway_output->wlr_output->name;
47 output_get_identifier(id, sizeof(id), sway_output);
48 if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) {
49 if (!sway_output->swayc) {
50 if (!oc->enabled) {
51 if (!wildcard) {
52 break;
53 }
54 continue;
55 }
56
57 output_enable(sway_output);
58 }
59
60 struct output_config *current = oc;
61 if (wildcard) {
62 struct output_config *tmp = get_output_config(name, id);
63 if (tmp) {
64 current = tmp;
65 }
66 }
67 apply_output_config(current, sway_output->swayc);
68
69 if (!wildcard) {
70 // Stop looking if the output config isn't applicable to all
71 // outputs
72 break;
73 }
74 }
75 }
76}
77
24struct cmd_results *cmd_output(int argc, char **argv) { 78struct cmd_results *cmd_output(int argc, char **argv) {
25 struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1); 79 struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1);
26 if (error != NULL) { 80 if (error != NULL) {
@@ -60,54 +114,8 @@ struct cmd_results *cmd_output(int argc, char **argv) {
60 config->handler_context.leftovers.argc = 0; 114 config->handler_context.leftovers.argc = 0;
61 config->handler_context.leftovers.argv = NULL; 115 config->handler_context.leftovers.argv = NULL;
62 116
63 int i = list_seq_find(config->output_configs, output_name_cmp, output->name); 117 output = store_output_config(output);
64 if (i >= 0) { 118 apply_output_config_to_outputs(output);
65 // Merge existing config
66 struct output_config *current = config->output_configs->items[i];
67 merge_output_config(current, output);
68 free_output_config(output);
69 output = current;
70 } else {
71 list_add(config->output_configs, output);
72 }
73
74 wlr_log(WLR_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
75 "position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
76 output->name, output->enabled, output->width, output->height,
77 output->refresh_rate, output->x, output->y, output->scale,
78 output->transform, output->background, output->background_option, output->dpms_state);
79
80 // Try to find the output container and apply configuration now. If
81 // this is during startup then there will be no container and config
82 // will be applied during normal "new output" event from wlroots.
83 char identifier[128];
84 bool all = strcmp(output->name, "*") == 0;
85 struct sway_output *sway_output;
86 wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) {
87 output_get_identifier(identifier, sizeof(identifier), sway_output);
88 wlr_log(WLR_DEBUG, "Checking identifier %s", identifier);
89 if (all || strcmp(sway_output->wlr_output->name, output->name) == 0
90 || strcmp(identifier, output->name) == 0) {
91 if (!sway_output->swayc) {
92 if (!output->enabled) {
93 if (!all) {
94 break;
95 }
96 continue;
97 }
98
99 output_enable(sway_output);
100 }
101
102 apply_output_config(output, sway_output->swayc);
103
104 if (!all) {
105 // Stop looking if the output config isn't applicable to all
106 // outputs
107 break;
108 }
109 }
110 }
111 119
112 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 120 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
113 121