mirror of
https://github.com/swaywm/sway.git
synced 2025-11-25 06:59:48 -05:00
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.
This commit is contained in:
parent
477bca5e28
commit
88d96bc41f
8 changed files with 22 additions and 37 deletions
|
|
@ -29,23 +29,13 @@
|
|||
#include "sway/tree/view.h"
|
||||
#include "sway/tree/workspace.h"
|
||||
|
||||
struct sway_output *output_by_name(const char *name) {
|
||||
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];
|
||||
if (strcasecmp(output->wlr_output->name, name) == 0) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct sway_output *output_by_identifier(const char *identifier) {
|
||||
for (int i = 0; i < root->outputs->length; ++i) {
|
||||
struct sway_output *output = root->outputs->items[i];
|
||||
char output_identifier[128];
|
||||
snprintf(output_identifier, sizeof(output_identifier), "%s %s %s", output->wlr_output->make,
|
||||
output->wlr_output->model, output->wlr_output->serial);
|
||||
if (strcasecmp(output_identifier, identifier) == 0) {
|
||||
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) {
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue