aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/bar.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-13 12:06:35 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-01-13 12:06:35 -0500
commit50d36ef238182c33bca8dfc01dd56957e31ff6bd (patch)
tree9eaac98af416b7a0a46e70a254561bdb968dfe25 /swaybar/bar.c
parentMerge pull request #3411 from RedSoxFan/fix-brace-detect-seeking (diff)
downloadsway-50d36ef238182c33bca8dfc01dd56957e31ff6bd.tar.gz
sway-50d36ef238182c33bca8dfc01dd56957e31ff6bd.tar.zst
sway-50d36ef238182c33bca8dfc01dd56957e31ff6bd.zip
swaybar: allow identifiers for output and tray
This allows `bar output` and `bar tray_output` to specify an output identifier. Output names should still work as well. This parses the output identifier from the xdg_output description, which wlroots currently sets to `make model serial (name)`. Since this could change in the future, all identifier comparisons are guarded by NULL-checks in case the description cannot be parsed to an identifier.
Diffstat (limited to 'swaybar/bar.c')
-rw-r--r--swaybar/bar.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index 7aed4dca..d36367fc 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -59,6 +59,7 @@ static void swaybar_output_free(struct swaybar_output *output) {
59 free_workspaces(&output->workspaces); 59 free_workspaces(&output->workspaces);
60 wl_list_remove(&output->link); 60 wl_list_remove(&output->link);
61 free(output->name); 61 free(output->name);
62 free(output->identifier);
62 free(output); 63 free(output);
63} 64}
64 65
@@ -166,13 +167,15 @@ bool determine_bar_visibility(struct swaybar *bar, bool moving_layer) {
166 return visible; 167 return visible;
167} 168}
168 169
169static bool bar_uses_output(struct swaybar *bar, const char *name) { 170static bool bar_uses_output(struct swaybar_output *output) {
170 if (bar->config->all_outputs) { 171 if (output->bar->config->all_outputs) {
171 return true; 172 return true;
172 } 173 }
174 char *identifier = output->identifier;
173 struct config_output *coutput; 175 struct config_output *coutput;
174 wl_list_for_each(coutput, &bar->config->outputs, link) { 176 wl_list_for_each(coutput, &output->bar->config->outputs, link) {
175 if (strcmp(coutput->name, name) == 0) { 177 if (strcmp(coutput->name, output->name) == 0 ||
178 (identifier && strcmp(coutput->name, identifier) == 0)) {
176 return true; 179 return true;
177 } 180 }
178 } 181 }
@@ -233,7 +236,7 @@ static void xdg_output_handle_done(void *data,
233 struct swaybar *bar = output->bar; 236 struct swaybar *bar = output->bar;
234 237
235 assert(output->name != NULL); 238 assert(output->name != NULL);
236 if (!bar_uses_output(bar, output->name)) { 239 if (!bar_uses_output(output)) {
237 swaybar_output_free(output); 240 swaybar_output_free(output);
238 return; 241 return;
239 } 242 }
@@ -258,7 +261,22 @@ static void xdg_output_handle_name(void *data,
258 261
259static void xdg_output_handle_description(void *data, 262static void xdg_output_handle_description(void *data,
260 struct zxdg_output_v1 *xdg_output, const char *description) { 263 struct zxdg_output_v1 *xdg_output, const char *description) {
261 // Who cares 264 // wlroots currently sets the description to `make model serial (name)`
265 // If this changes in the future, this will need to be modified.
266 struct swaybar_output *output = data;
267 free(output->identifier);
268 output->identifier = NULL;
269 char *paren = strrchr(description, '(');
270 if (paren) {
271 size_t length = paren - description;
272 output->identifier = malloc(length);
273 if (!output->identifier) {
274 wlr_log(WLR_ERROR, "Failed to allocate output identifier");
275 return;
276 }
277 strncpy(output->identifier, description, length);
278 output->identifier[length - 1] = '\0';
279 }
262} 280}
263 281
264struct zxdg_output_v1_listener xdg_output_listener = { 282struct zxdg_output_v1_listener xdg_output_listener = {