mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01: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
|
@ -84,9 +84,7 @@ void output_damage_box(struct sway_output *output, struct wlr_box *box);
|
||||||
void output_damage_whole_container(struct sway_output *output,
|
void output_damage_whole_container(struct sway_output *output,
|
||||||
struct sway_container *con);
|
struct sway_container *con);
|
||||||
|
|
||||||
struct sway_output *output_by_name(const char *name);
|
struct sway_output *output_by_name_or_id(const char *name_or_id);
|
||||||
|
|
||||||
struct sway_output *output_by_identifier(const char *identifier);
|
|
||||||
|
|
||||||
void output_sort_workspaces(struct sway_output *output);
|
void output_sort_workspaces(struct sway_output *output);
|
||||||
|
|
||||||
|
|
|
@ -193,7 +193,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat,
|
||||||
"Expected 'focus output <direction|name>'");
|
"Expected 'focus output <direction|name>'");
|
||||||
}
|
}
|
||||||
char *identifier = join_args(argv, argc);
|
char *identifier = join_args(argv, argc);
|
||||||
struct sway_output *output = output_by_name(identifier);
|
struct sway_output *output = output_by_name_or_id(identifier);
|
||||||
|
|
||||||
if (!output) {
|
if (!output) {
|
||||||
enum wlr_direction direction;
|
enum wlr_direction direction;
|
||||||
|
|
|
@ -64,7 +64,7 @@ static struct sway_output *output_in_direction(const char *direction_string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output_by_name(direction_string);
|
return output_by_name_or_id(direction_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_parallel(enum sway_container_layout layout,
|
static bool is_parallel(enum sway_container_layout layout,
|
||||||
|
|
|
@ -45,7 +45,7 @@ struct cmd_results *output_cmd_transform(int argc, char **argv) {
|
||||||
return cmd_results_new(CMD_INVALID, "output",
|
return cmd_results_new(CMD_INVALID, "output",
|
||||||
"Cannot apply relative transform to all outputs.");
|
"Cannot apply relative transform to all outputs.");
|
||||||
}
|
}
|
||||||
struct sway_output *s_output = output_by_name(output->name);
|
struct sway_output *s_output = output_by_name_or_id(output->name);
|
||||||
if (s_output == NULL) {
|
if (s_output == NULL) {
|
||||||
return cmd_results_new(CMD_INVALID, "output",
|
return cmd_results_new(CMD_INVALID, "output",
|
||||||
"Cannot apply relative transform to unknown output %s", output->name);
|
"Cannot apply relative transform to unknown output %s", output->name);
|
||||||
|
|
|
@ -29,23 +29,13 @@
|
||||||
#include "sway/tree/view.h"
|
#include "sway/tree/view.h"
|
||||||
#include "sway/tree/workspace.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) {
|
for (int i = 0; i < root->outputs->length; ++i) {
|
||||||
struct sway_output *output = root->outputs->items[i];
|
struct sway_output *output = root->outputs->items[i];
|
||||||
if (strcasecmp(output->wlr_output->name, name) == 0) {
|
char identifier[128];
|
||||||
return output;
|
output_get_identifier(identifier, sizeof(identifier), output);
|
||||||
}
|
if (strcasecmp(identifier, name_or_id) == 0
|
||||||
}
|
|| strcasecmp(output->wlr_output->name, name_or_id) == 0) {
|
||||||
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) {
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -428,7 +428,7 @@ static void seat_apply_input_config(struct sway_seat *seat,
|
||||||
if (mapped_to_output != NULL) {
|
if (mapped_to_output != NULL) {
|
||||||
wlr_log(WLR_DEBUG, "Mapping input device %s to output %s",
|
wlr_log(WLR_DEBUG, "Mapping input device %s to output %s",
|
||||||
sway_device->input_device->identifier, mapped_to_output);
|
sway_device->input_device->identifier, mapped_to_output);
|
||||||
struct sway_output *output = output_by_name(mapped_to_output);
|
struct sway_output *output = output_by_name_or_id(mapped_to_output);
|
||||||
if (output) {
|
if (output) {
|
||||||
wlr_cursor_map_input_to_output(seat->cursor->cursor,
|
wlr_cursor_map_input_to_output(seat->cursor->cursor,
|
||||||
sway_device->input_device->wlr_device, output->wlr_output);
|
sway_device->input_device->wlr_device, output->wlr_output);
|
||||||
|
|
|
@ -459,7 +459,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
|
||||||
for (int i = 0; i < criterias->length; ++i) {
|
for (int i = 0; i < criterias->length; ++i) {
|
||||||
struct criteria *criteria = criterias->items[i];
|
struct criteria *criteria = criterias->items[i];
|
||||||
if (criteria->type == CT_ASSIGN_OUTPUT) {
|
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) {
|
if (output) {
|
||||||
ws = output_get_active_workspace(output);
|
ws = output_get_active_workspace(output);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -35,10 +35,8 @@ struct sway_output *workspace_get_initial_output(const char *name) {
|
||||||
struct workspace_config *wsc = workspace_find_config(name);
|
struct workspace_config *wsc = workspace_find_config(name);
|
||||||
if (wsc) {
|
if (wsc) {
|
||||||
for (int i = 0; i < wsc->outputs->length; i++) {
|
for (int i = 0; i < wsc->outputs->length; i++) {
|
||||||
struct sway_output *output = output_by_name(wsc->outputs->items[i]);
|
struct sway_output *output =
|
||||||
if (!output) {
|
output_by_name_or_id(wsc->outputs->items[i]);
|
||||||
output = output_by_identifier(wsc->outputs->items[i]);
|
|
||||||
}
|
|
||||||
if (output) {
|
if (output) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -185,11 +183,11 @@ static bool workspace_valid_on_output(const char *output_name,
|
||||||
const char *ws_name) {
|
const char *ws_name) {
|
||||||
struct workspace_config *wsc = workspace_find_config(ws_name);
|
struct workspace_config *wsc = workspace_find_config(ws_name);
|
||||||
char identifier[128];
|
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) {
|
if (!output) {
|
||||||
output = output_by_identifier(output_name);
|
return false;
|
||||||
output_name = output->wlr_output->name;
|
|
||||||
}
|
}
|
||||||
|
output_name = output->wlr_output->name;
|
||||||
output_get_identifier(identifier, sizeof(identifier), output);
|
output_get_identifier(identifier, sizeof(identifier), output);
|
||||||
|
|
||||||
if (!wsc) {
|
if (!wsc) {
|
||||||
|
@ -295,7 +293,11 @@ char *workspace_next_name(const char *output_name) {
|
||||||
struct sway_mode *mode = config->current_mode;
|
struct sway_mode *mode = config->current_mode;
|
||||||
|
|
||||||
char identifier[128];
|
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);
|
output_get_identifier(identifier, sizeof(identifier), output);
|
||||||
|
|
||||||
int order = INT_MAX;
|
int order = INT_MAX;
|
||||||
|
@ -551,12 +553,7 @@ struct sway_output *workspace_output_get_highest_available(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sway_output *output = output_by_name(name);
|
struct sway_output *output = output_by_name_or_id(name);
|
||||||
if (output) {
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
output = output_by_identifier(name);
|
|
||||||
if (output) {
|
if (output) {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue