diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-12-20 13:02:45 -0500 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-12-20 19:55:29 +0100 |
commit | 88d96bc41ff638bdc767e30bf6ccbbd530258420 (patch) | |
tree | 5d822da99812aab4e849e566c53d3a6ba87ba496 | |
parent | Terminate swaybg in output_disable (diff) | |
download | sway-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.
-rw-r--r-- | include/sway/output.h | 4 | ||||
-rw-r--r-- | sway/commands/focus.c | 2 | ||||
-rw-r--r-- | sway/commands/move.c | 2 | ||||
-rw-r--r-- | sway/commands/output/transform.c | 2 | ||||
-rw-r--r-- | sway/desktop/output.c | 20 | ||||
-rw-r--r-- | sway/input/seat.c | 2 | ||||
-rw-r--r-- | sway/tree/view.c | 2 | ||||
-rw-r--r-- | sway/tree/workspace.c | 25 |
8 files changed, 22 insertions, 37 deletions
diff --git a/include/sway/output.h b/include/sway/output.h index 43c1ab96..f7c5ceba 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -84,9 +84,7 @@ void output_damage_box(struct sway_output *output, struct wlr_box *box); | |||
84 | void output_damage_whole_container(struct sway_output *output, | 84 | void output_damage_whole_container(struct sway_output *output, |
85 | struct sway_container *con); | 85 | struct sway_container *con); |
86 | 86 | ||
87 | struct sway_output *output_by_name(const char *name); | 87 | struct sway_output *output_by_name_or_id(const char *name_or_id); |
88 | |||
89 | struct sway_output *output_by_identifier(const char *identifier); | ||
90 | 88 | ||
91 | void output_sort_workspaces(struct sway_output *output); | 89 | void output_sort_workspaces(struct sway_output *output); |
92 | 90 | ||
diff --git a/sway/commands/focus.c b/sway/commands/focus.c index 689edfec..97ffe91c 100644 --- a/sway/commands/focus.c +++ b/sway/commands/focus.c | |||
@@ -193,7 +193,7 @@ static struct cmd_results *focus_output(struct sway_seat *seat, | |||
193 | "Expected 'focus output <direction|name>'"); | 193 | "Expected 'focus output <direction|name>'"); |
194 | } | 194 | } |
195 | char *identifier = join_args(argv, argc); | 195 | char *identifier = join_args(argv, argc); |
196 | struct sway_output *output = output_by_name(identifier); | 196 | struct sway_output *output = output_by_name_or_id(identifier); |
197 | 197 | ||
198 | if (!output) { | 198 | if (!output) { |
199 | enum wlr_direction direction; | 199 | enum wlr_direction direction; |
diff --git a/sway/commands/move.c b/sway/commands/move.c index 4dc547db..09f19c3f 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -64,7 +64,7 @@ static struct sway_output *output_in_direction(const char *direction_string, | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | return output_by_name(direction_string); | 67 | return output_by_name_or_id(direction_string); |
68 | } | 68 | } |
69 | 69 | ||
70 | static bool is_parallel(enum sway_container_layout layout, | 70 | static bool is_parallel(enum sway_container_layout layout, |
diff --git a/sway/commands/output/transform.c b/sway/commands/output/transform.c index c1555323..ca6f73a4 100644 --- a/sway/commands/output/transform.c +++ b/sway/commands/output/transform.c | |||
@@ -45,7 +45,7 @@ struct cmd_results *output_cmd_transform(int argc, char **argv) { | |||
45 | return cmd_results_new(CMD_INVALID, "output", | 45 | return cmd_results_new(CMD_INVALID, "output", |
46 | "Cannot apply relative transform to all outputs."); | 46 | "Cannot apply relative transform to all outputs."); |
47 | } | 47 | } |
48 | struct sway_output *s_output = output_by_name(output->name); | 48 | struct sway_output *s_output = output_by_name_or_id(output->name); |
49 | if (s_output == NULL) { | 49 | if (s_output == NULL) { |
50 | return cmd_results_new(CMD_INVALID, "output", | 50 | return cmd_results_new(CMD_INVALID, "output", |
51 | "Cannot apply relative transform to unknown output %s", output->name); | 51 | "Cannot apply relative transform to unknown output %s", output->name); |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 246f4438..96ceea86 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -29,23 +29,13 @@ | |||
29 | #include "sway/tree/view.h" | 29 | #include "sway/tree/view.h" |
30 | #include "sway/tree/workspace.h" | 30 | #include "sway/tree/workspace.h" |
31 | 31 | ||
32 | struct sway_output *output_by_name(const char *name) { | 32 | struct sway_output *output_by_name_or_id(const char *name_or_id) { |
33 | for (int i = 0; i < root->outputs->length; ++i) { | 33 | for (int i = 0; i < root->outputs->length; ++i) { |
34 | struct sway_output *output = root->outputs->items[i]; | 34 | struct sway_output *output = root->outputs->items[i]; |
35 | if (strcasecmp(output->wlr_output->name, name) == 0) { | 35 | char identifier[128]; |
36 | return output; | 36 | output_get_identifier(identifier, sizeof(identifier), output); |
37 | } | 37 | if (strcasecmp(identifier, name_or_id) == 0 |
38 | } | 38 | || strcasecmp(output->wlr_output->name, name_or_id) == 0) { |
39 | return NULL; | ||
40 | } | ||
41 | |||
42 | struct sway_output *output_by_identifier(const char *identifier) { | ||
43 | for (int i = 0; i < root->outputs->length; ++i) { | ||
44 | struct sway_output *output = root->outputs->items[i]; | ||
45 | char output_identifier[128]; | ||
46 | snprintf(output_identifier, sizeof(output_identifier), "%s %s %s", output->wlr_output->make, | ||
47 | output->wlr_output->model, output->wlr_output->serial); | ||
48 | if (strcasecmp(output_identifier, identifier) == 0) { | ||
49 | return output; | 39 | return output; |
50 | } | 40 | } |
51 | } | 41 | } |
diff --git a/sway/input/seat.c b/sway/input/seat.c index 776d5766..e0f0db1d 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c | |||
@@ -428,7 +428,7 @@ static void seat_apply_input_config(struct sway_seat *seat, | |||
428 | if (mapped_to_output != NULL) { | 428 | if (mapped_to_output != NULL) { |
429 | wlr_log(WLR_DEBUG, "Mapping input device %s to output %s", | 429 | wlr_log(WLR_DEBUG, "Mapping input device %s to output %s", |
430 | sway_device->input_device->identifier, mapped_to_output); | 430 | sway_device->input_device->identifier, mapped_to_output); |
431 | struct sway_output *output = output_by_name(mapped_to_output); | 431 | struct sway_output *output = output_by_name_or_id(mapped_to_output); |
432 | if (output) { | 432 | if (output) { |
433 | wlr_cursor_map_input_to_output(seat->cursor->cursor, | 433 | wlr_cursor_map_input_to_output(seat->cursor->cursor, |
434 | sway_device->input_device->wlr_device, output->wlr_output); | 434 | sway_device->input_device->wlr_device, output->wlr_output); |
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) { | |||
459 | for (int i = 0; i < criterias->length; ++i) { | 459 | for (int i = 0; i < criterias->length; ++i) { |
460 | struct criteria *criteria = criterias->items[i]; | 460 | struct criteria *criteria = criterias->items[i]; |
461 | if (criteria->type == CT_ASSIGN_OUTPUT) { | 461 | if (criteria->type == CT_ASSIGN_OUTPUT) { |
462 | struct sway_output *output = output_by_name(criteria->target); | 462 | struct sway_output *output = output_by_name_or_id(criteria->target); |
463 | if (output) { | 463 | if (output) { |
464 | ws = output_get_active_workspace(output); | 464 | ws = output_get_active_workspace(output); |
465 | break; | 465 | 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) { | |||
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 | } |