aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-12-20 13:02:45 -0500
committeremersion <contact@emersion.fr>2018-12-20 19:55:29 +0100
commit88d96bc41ff638bdc767e30bf6ccbbd530258420 (patch)
tree5d822da99812aab4e849e566c53d3a6ba87ba496 /sway/tree
parent477bca5e288cc3155c536265272490b413328778 (diff)
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/tree')
-rw-r--r--sway/tree/view.c2
-rw-r--r--sway/tree/workspace.c25
2 files changed, 12 insertions, 15 deletions
diff --git a/sway/tree/view.c b/sway/tree/view.c
index e890f4f3..deb20676 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -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;
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 4f1c4a64..7f18046d 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -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;
}