diff options
author | emersion <contact@emersion.fr> | 2017-12-29 19:04:16 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-12-29 19:04:16 +0100 |
commit | ead3f1e676923b0457cef77b0b482e76cac50307 (patch) | |
tree | 6a4c75b23de360d4eadbf4e1aa647a0d93c81eb2 /sway/tree/container.c | |
parent | Merge pull request #1542 from emersion/swaymsg-output (diff) | |
download | sway-ead3f1e676923b0457cef77b0b482e76cac50307.tar.gz sway-ead3f1e676923b0457cef77b0b482e76cac50307.tar.zst sway-ead3f1e676923b0457cef77b0b482e76cac50307.zip |
Allow to configure outputs by their identifier
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r-- | sway/tree/container.c | 70 |
1 files changed, 40 insertions, 30 deletions
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 | ||
52 | static 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 | |||
52 | swayc_t *new_output(struct sway_output *sway_output) { | 80 | swayc_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 | ||
143 | static 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 | |||
171 | swayc_t *destroy_output(swayc_t *output) { | 181 | swayc_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; |