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.
This commit is contained in:
Brian Ashworth 2019-01-13 12:06:35 -05:00
parent d256182f49
commit 50d36ef238
3 changed files with 31 additions and 8 deletions

View file

@ -101,13 +101,17 @@ void tray_in(int fd, short mask, void *data) {
}
static int cmp_output(const void *item, const void *cmp_to) {
return strcmp(item, cmp_to);
const struct swaybar_output *output = cmp_to;
if (output->identifier && strcmp(item, output->identifier) == 0) {
return 0;
}
return strcmp(item, output->name);
}
uint32_t render_tray(cairo_t *cairo, struct swaybar_output *output, double *x) {
struct swaybar_config *config = output->bar->config;
if (config->tray_outputs) {
if (list_seq_find(config->tray_outputs, cmp_output, output->name) == -1) {
if (list_seq_find(config->tray_outputs, cmp_output, output) == -1) {
return 0;
}
} // else display on all