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 | |
parent | Fix old style function definitions (diff) | |
download | sway-8d95638df6450ef9aa726e7d058b10182f584dc9.tar.gz sway-8d95638df6450ef9aa726e7d058b10182f584dc9.tar.zst sway-8d95638df6450ef9aa726e7d058b10182f584dc9.zip |
Introduce output_match_name_or_id()
Reduces code duplication.
-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 @@ | |||
36 | #include <wlr/types/wlr_drm_lease_v1.h> | 36 | #include <wlr/types/wlr_drm_lease_v1.h> |
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | static bool output_match_name_or_id(struct sway_output *output, | ||
40 | const char *name_or_id) { | ||
41 | char identifier[128]; | ||
42 | output_get_identifier(identifier, sizeof(identifier), output); | ||
43 | return strcasecmp(identifier, name_or_id) == 0 | ||
44 | || strcasecmp(output->wlr_output->name, name_or_id) == 0; | ||
45 | } | ||
46 | |||
39 | struct sway_output *output_by_name_or_id(const char *name_or_id) { | 47 | struct sway_output *output_by_name_or_id(const char *name_or_id) { |
40 | for (int i = 0; i < root->outputs->length; ++i) { | 48 | for (int i = 0; i < root->outputs->length; ++i) { |
41 | struct sway_output *output = root->outputs->items[i]; | 49 | struct sway_output *output = root->outputs->items[i]; |
42 | char identifier[128]; | 50 | if (output_match_name_or_id(output, name_or_id)) { |
43 | output_get_identifier(identifier, sizeof(identifier), output); | ||
44 | if (strcasecmp(identifier, name_or_id) == 0 | ||
45 | || strcasecmp(output->wlr_output->name, name_or_id) == 0) { | ||
46 | return output; | 51 | return output; |
47 | } | 52 | } |
48 | } | 53 | } |
@@ -52,10 +57,7 @@ struct sway_output *output_by_name_or_id(const char *name_or_id) { | |||
52 | struct sway_output *all_output_by_name_or_id(const char *name_or_id) { | 57 | struct sway_output *all_output_by_name_or_id(const char *name_or_id) { |
53 | struct sway_output *output; | 58 | struct sway_output *output; |
54 | wl_list_for_each(output, &root->all_outputs, link) { | 59 | wl_list_for_each(output, &root->all_outputs, link) { |
55 | char identifier[128]; | 60 | if (output_match_name_or_id(output, name_or_id)) { |
56 | output_get_identifier(identifier, sizeof(identifier), output); | ||
57 | if (strcasecmp(identifier, name_or_id) == 0 | ||
58 | || strcasecmp(output->wlr_output->name, name_or_id) == 0) { | ||
59 | return output; | 61 | return output; |
60 | } | 62 | } |
61 | } | 63 | } |