diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-12-20 13:02:45 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-12-20 19:55:29 +0100 |
commit | 88d96bc41ff638bdc767e30bf6ccbbd530258420 (patch) | |
tree | 5d822da99812aab4e849e566c53d3a6ba87ba496 /sway/desktop | |
parent | Terminate swaybg in output_disable (diff) | |
download | sway-88d96bc41ff638bdc767e30bf6ccbbd530258420.tar.gz sway-88d96bc41ff638bdc767e30bf6ccbbd530258420.tar.zst sway-88d96bc41ff638bdc767e30bf6ccbbd530258420.zip |
Combine output_by_name and output_by_identifier
This combines `output_by_name` and `output_by_identifier` into a single
function called `output_by_name_or_id`. This allows for output
identifiers to be used in all commands, simplifies the logic of the
callers, and is more efficient since worst case is a single pass through
the output list.
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/output.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 246f4438..96ceea86 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -29,23 +29,13 @@ | |||
29 | #include "sway/tree/view.h" | 29 | #include "sway/tree/view.h" |
30 | #include "sway/tree/workspace.h" | 30 | #include "sway/tree/workspace.h" |
31 | 31 | ||
32 | struct sway_output *output_by_name(const char *name) { | 32 | struct sway_output *output_by_name_or_id(const char *name_or_id) { |
33 | for (int i = 0; i < root->outputs->length; ++i) { | 33 | for (int i = 0; i < root->outputs->length; ++i) { |
34 | struct sway_output *output = root->outputs->items[i]; | 34 | struct sway_output *output = root->outputs->items[i]; |
35 | if (strcasecmp(output->wlr_output->name, name) == 0) { | 35 | char identifier[128]; |
36 | return output; | 36 | output_get_identifier(identifier, sizeof(identifier), output); |
37 | } | 37 | if (strcasecmp(identifier, name_or_id) == 0 |
38 | } | 38 | || strcasecmp(output->wlr_output->name, name_or_id) == 0) { |
39 | return NULL; | ||
40 | } | ||
41 | |||
42 | struct sway_output *output_by_identifier(const char *identifier) { | ||
43 | for (int i = 0; i < root->outputs->length; ++i) { | ||
44 | struct sway_output *output = root->outputs->items[i]; | ||
45 | char output_identifier[128]; | ||
46 | snprintf(output_identifier, sizeof(output_identifier), "%s %s %s", output->wlr_output->make, | ||
47 | output->wlr_output->model, output->wlr_output->serial); | ||
48 | if (strcasecmp(output_identifier, identifier) == 0) { | ||
49 | return output; | 39 | return output; |
50 | } | 40 | } |
51 | } | 41 | } |