diff options
author | Simon Ser <contact@emersion.fr> | 2023-02-28 12:47:12 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-04-14 18:34:54 +0200 |
commit | 8d95638df6450ef9aa726e7d058b10182f584dc9 (patch) | |
tree | bd5f1995e80f41d169163002ffe06718aa36361f /sway/desktop | |
parent | 63f9bdf00126d4505235c533693c297722be57c8 (diff) |
Introduce output_match_name_or_id()
Reduces code duplication.
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 17bce123..fe3cdaf1 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -36,13 +36,18 @@ #include <wlr/types/wlr_drm_lease_v1.h> #endif +static bool output_match_name_or_id(struct sway_output *output, + const char *name_or_id) { + char identifier[128]; + output_get_identifier(identifier, sizeof(identifier), output); + return strcasecmp(identifier, name_or_id) == 0 + || strcasecmp(output->wlr_output->name, name_or_id) == 0; +} + struct sway_output *output_by_name_or_id(const char *name_or_id) { for (int i = 0; i < root->outputs->length; ++i) { struct sway_output *output = root->outputs->items[i]; - char identifier[128]; - output_get_identifier(identifier, sizeof(identifier), output); - if (strcasecmp(identifier, name_or_id) == 0 - || strcasecmp(output->wlr_output->name, name_or_id) == 0) { + if (output_match_name_or_id(output, name_or_id)) { return output; } } @@ -52,10 +57,7 @@ struct sway_output *output_by_name_or_id(const char *name_or_id) { struct sway_output *all_output_by_name_or_id(const char *name_or_id) { struct sway_output *output; wl_list_for_each(output, &root->all_outputs, link) { - char identifier[128]; - output_get_identifier(identifier, sizeof(identifier), output); - if (strcasecmp(identifier, name_or_id) == 0 - || strcasecmp(output->wlr_output->name, name_or_id) == 0) { + if (output_match_name_or_id(output, name_or_id)) { return output; } } |