aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-20 13:02:45 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-20 19:55:29 +0100
commit88d96bc41ff638bdc767e30bf6ccbbd530258420 (patch)
tree5d822da99812aab4e849e566c53d3a6ba87ba496 /sway/tree/workspace.c
parentTerminate swaybg in output_disable (diff)
downloadsway-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/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c25
1 files changed, 11 insertions, 14 deletions
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) {
35 struct workspace_config *wsc = workspace_find_config(name); 35 struct workspace_config *wsc = workspace_find_config(name);
36 if (wsc) { 36 if (wsc) {
37 for (int i = 0; i < wsc->outputs->length; i++) { 37 for (int i = 0; i < wsc->outputs->length; i++) {
38 struct sway_output *output = output_by_name(wsc->outputs->items[i]); 38 struct sway_output *output =
39 if (!output) { 39 output_by_name_or_id(wsc->outputs->items[i]);
40 output = output_by_identifier(wsc->outputs->items[i]);
41 }
42 if (output) { 40 if (output) {
43 return output; 41 return output;
44 } 42 }
@@ -185,11 +183,11 @@ static bool workspace_valid_on_output(const char *output_name,
185 const char *ws_name) { 183 const char *ws_name) {
186 struct workspace_config *wsc = workspace_find_config(ws_name); 184 struct workspace_config *wsc = workspace_find_config(ws_name);
187 char identifier[128]; 185 char identifier[128];
188 struct sway_output *output = output_by_name(output_name); 186 struct sway_output *output = output_by_name_or_id(output_name);
189 if (!output) { 187 if (!output) {
190 output = output_by_identifier(output_name); 188 return false;
191 output_name = output->wlr_output->name;
192 } 189 }
190 output_name = output->wlr_output->name;
193 output_get_identifier(identifier, sizeof(identifier), output); 191 output_get_identifier(identifier, sizeof(identifier), output);
194 192
195 if (!wsc) { 193 if (!wsc) {
@@ -295,7 +293,11 @@ char *workspace_next_name(const char *output_name) {
295 struct sway_mode *mode = config->current_mode; 293 struct sway_mode *mode = config->current_mode;
296 294
297 char identifier[128]; 295 char identifier[128];
298 struct sway_output *output = output_by_name(output_name); 296 struct sway_output *output = output_by_name_or_id(output_name);
297 if (!output) {
298 return NULL;
299 }
300 output_name = output->wlr_output->name;
299 output_get_identifier(identifier, sizeof(identifier), output); 301 output_get_identifier(identifier, sizeof(identifier), output);
300 302
301 int order = INT_MAX; 303 int order = INT_MAX;
@@ -551,12 +553,7 @@ struct sway_output *workspace_output_get_highest_available(
551 continue; 553 continue;
552 } 554 }
553 555
554 struct sway_output *output = output_by_name(name); 556 struct sway_output *output = output_by_name_or_id(name);
555 if (output) {
556 return output;
557 }
558
559 output = output_by_identifier(name);
560 if (output) { 557 if (output) {
561 return output; 558 return output;
562 } 559 }