mirror of
https://github.com/swaywm/sway.git
synced 2025-11-18 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
|
|
@ -459,7 +459,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
|
|||
for (int i = 0; i < criterias->length; ++i) {
|
||||
struct criteria *criteria = criterias->items[i];
|
||||
if (criteria->type == CT_ASSIGN_OUTPUT) {
|
||||
struct sway_output *output = output_by_name(criteria->target);
|
||||
struct sway_output *output = output_by_name_or_id(criteria->target);
|
||||
if (output) {
|
||||
ws = output_get_active_workspace(output);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -35,10 +35,8 @@ struct sway_output *workspace_get_initial_output(const char *name) {
|
|||
struct workspace_config *wsc = workspace_find_config(name);
|
||||
if (wsc) {
|
||||
for (int i = 0; i < wsc->outputs->length; i++) {
|
||||
struct sway_output *output = output_by_name(wsc->outputs->items[i]);
|
||||
if (!output) {
|
||||
output = output_by_identifier(wsc->outputs->items[i]);
|
||||
}
|
||||
struct sway_output *output =
|
||||
output_by_name_or_id(wsc->outputs->items[i]);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
|
|
@ -185,11 +183,11 @@ static bool workspace_valid_on_output(const char *output_name,
|
|||
const char *ws_name) {
|
||||
struct workspace_config *wsc = workspace_find_config(ws_name);
|
||||
char identifier[128];
|
||||
struct sway_output *output = output_by_name(output_name);
|
||||
struct sway_output *output = output_by_name_or_id(output_name);
|
||||
if (!output) {
|
||||
output = output_by_identifier(output_name);
|
||||
output_name = output->wlr_output->name;
|
||||
return false;
|
||||
}
|
||||
output_name = output->wlr_output->name;
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
if (!wsc) {
|
||||
|
|
@ -295,7 +293,11 @@ char *workspace_next_name(const char *output_name) {
|
|||
struct sway_mode *mode = config->current_mode;
|
||||
|
||||
char identifier[128];
|
||||
struct sway_output *output = output_by_name(output_name);
|
||||
struct sway_output *output = output_by_name_or_id(output_name);
|
||||
if (!output) {
|
||||
return NULL;
|
||||
}
|
||||
output_name = output->wlr_output->name;
|
||||
output_get_identifier(identifier, sizeof(identifier), output);
|
||||
|
||||
int order = INT_MAX;
|
||||
|
|
@ -551,12 +553,7 @@ struct sway_output *workspace_output_get_highest_available(
|
|||
continue;
|
||||
}
|
||||
|
||||
struct sway_output *output = output_by_name(name);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
|
||||
output = output_by_identifier(name);
|
||||
struct sway_output *output = output_by_name_or_id(name);
|
||||
if (output) {
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue