diff options
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/output.h | 4 | ||||
-rw-r--r-- | sway/commands/output.c | 1 | ||||
-rw-r--r-- | sway/commands/output/toggle.c | 37 | ||||
-rw-r--r-- | sway/desktop/output.c | 13 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-output.5.scd | 3 |
7 files changed, 60 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index cfe2aa07..c4903788 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -270,6 +270,7 @@ sway_cmd output_cmd_mode; | |||
270 | sway_cmd output_cmd_position; | 270 | sway_cmd output_cmd_position; |
271 | sway_cmd output_cmd_scale; | 271 | sway_cmd output_cmd_scale; |
272 | sway_cmd output_cmd_subpixel; | 272 | sway_cmd output_cmd_subpixel; |
273 | sway_cmd output_cmd_toggle; | ||
273 | sway_cmd output_cmd_transform; | 274 | sway_cmd output_cmd_transform; |
274 | 275 | ||
275 | sway_cmd seat_cmd_attach; | 276 | sway_cmd seat_cmd_attach; |
diff --git a/include/sway/output.h b/include/sway/output.h index cae77e2e..d4438c0e 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -82,8 +82,12 @@ void output_damage_box(struct sway_output *output, struct wlr_box *box); | |||
82 | void output_damage_whole_container(struct sway_output *output, | 82 | void output_damage_whole_container(struct sway_output *output, |
83 | struct sway_container *con); | 83 | struct sway_container *con); |
84 | 84 | ||
85 | // this ONLY includes the enabled outputs | ||
85 | struct sway_output *output_by_name_or_id(const char *name_or_id); | 86 | struct sway_output *output_by_name_or_id(const char *name_or_id); |
86 | 87 | ||
88 | // this includes all the outputs, including disabled ones | ||
89 | struct sway_output *all_output_by_name_or_id(const char *name_or_id); | ||
90 | |||
87 | void output_sort_workspaces(struct sway_output *output); | 91 | void output_sort_workspaces(struct sway_output *output); |
88 | 92 | ||
89 | void output_enable(struct sway_output *output, struct output_config *oc); | 93 | void output_enable(struct sway_output *output, struct output_config *oc); |
diff --git a/sway/commands/output.c b/sway/commands/output.c index 6b9eafdb..3903f10d 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -19,6 +19,7 @@ static struct cmd_handler output_handlers[] = { | |||
19 | { "resolution", output_cmd_mode }, | 19 | { "resolution", output_cmd_mode }, |
20 | { "scale", output_cmd_scale }, | 20 | { "scale", output_cmd_scale }, |
21 | { "subpixel", output_cmd_subpixel }, | 21 | { "subpixel", output_cmd_subpixel }, |
22 | { "toggle", output_cmd_toggle }, | ||
22 | { "transform", output_cmd_transform }, | 23 | { "transform", output_cmd_transform }, |
23 | }; | 24 | }; |
24 | 25 | ||
diff --git a/sway/commands/output/toggle.c b/sway/commands/output/toggle.c new file mode 100644 index 00000000..6342d526 --- /dev/null +++ b/sway/commands/output/toggle.c | |||
@@ -0,0 +1,37 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | #include "sway/output.h" | ||
4 | |||
5 | struct cmd_results *output_cmd_toggle(int argc, char **argv) { | ||
6 | if (!config->handler_context.output_config) { | ||
7 | return cmd_results_new(CMD_FAILURE, "Missing output config"); | ||
8 | } | ||
9 | |||
10 | struct output_config *oc = config->handler_context.output_config; | ||
11 | |||
12 | if (strcmp(oc->name, "*") == 0) { | ||
13 | return cmd_results_new(CMD_INVALID, | ||
14 | "Cannot apply toggle to all outputs."); | ||
15 | } | ||
16 | |||
17 | struct sway_output *sway_output = all_output_by_name_or_id(oc->name); | ||
18 | |||
19 | if (sway_output == NULL) { | ||
20 | return cmd_results_new(CMD_FAILURE, | ||
21 | "Cannot apply toggle to unknown output %s", oc->name); | ||
22 | } | ||
23 | |||
24 | oc = find_output_config(sway_output); | ||
25 | |||
26 | if (!oc || oc->enabled != 0) { | ||
27 | config->handler_context.output_config->enabled = 0; | ||
28 | } else { | ||
29 | config->handler_context.output_config->enabled = 1; | ||
30 | } | ||
31 | |||
32 | free(oc); | ||
33 | config->handler_context.leftovers.argc = argc; | ||
34 | config->handler_context.leftovers.argv = argv; | ||
35 | return NULL; | ||
36 | } | ||
37 | |||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0cc08525..1636a58b 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -42,6 +42,19 @@ struct sway_output *output_by_name_or_id(const char *name_or_id) { | |||
42 | return NULL; | 42 | return NULL; |
43 | } | 43 | } |
44 | 44 | ||
45 | struct sway_output *all_output_by_name_or_id(const char *name_or_id) { | ||
46 | struct sway_output *output; | ||
47 | wl_list_for_each(output, &root->all_outputs, link) { | ||
48 | char identifier[128]; | ||
49 | output_get_identifier(identifier, sizeof(identifier), output); | ||
50 | if (strcasecmp(identifier, name_or_id) == 0 | ||
51 | || strcasecmp(output->wlr_output->name, name_or_id) == 0) { | ||
52 | return output; | ||
53 | } | ||
54 | } | ||
55 | return NULL; | ||
56 | } | ||
57 | |||
45 | /** | 58 | /** |
46 | * Rotate a child's position relative to a parent. The parent size is (pw, ph), | 59 | * Rotate a child's position relative to a parent. The parent size is (pw, ph), |
47 | * the child position is (*sx, *sy) and its size is (sw, sh). | 60 | * the child position is (*sx, *sy) and its size is (sw, sh). |
diff --git a/sway/meson.build b/sway/meson.build index 0f943a1f..05cece7a 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -173,6 +173,7 @@ sway_sources = files( | |||
173 | 'commands/output/position.c', | 173 | 'commands/output/position.c', |
174 | 'commands/output/scale.c', | 174 | 'commands/output/scale.c', |
175 | 'commands/output/subpixel.c', | 175 | 'commands/output/subpixel.c', |
176 | 'commands/output/toggle.c', | ||
176 | 'commands/output/transform.c', | 177 | 'commands/output/transform.c', |
177 | 178 | ||
178 | 'tree/arrange.c', | 179 | 'tree/arrange.c', |
diff --git a/sway/sway-output.5.scd b/sway/sway-output.5.scd index 1efe2f7b..e20d0aba 100644 --- a/sway/sway-output.5.scd +++ b/sway/sway-output.5.scd | |||
@@ -94,6 +94,9 @@ must be separated by one space. For example: | |||
94 | Enables or disables the specified output (all outputs are enabled by | 94 | Enables or disables the specified output (all outputs are enabled by |
95 | default). | 95 | default). |
96 | 96 | ||
97 | *output* <name> toggle | ||
98 | Toggle the specified output. | ||
99 | |||
97 | *output* <name> dpms on|off | 100 | *output* <name> dpms on|off |
98 | Enables or disables the specified output via DPMS. To turn an output off | 101 | Enables or disables the specified output via DPMS. To turn an output off |
99 | (ie. blank the screen but keep workspaces as-is), one can set DPMS to off. | 102 | (ie. blank the screen but keep workspaces as-is), one can set DPMS to off. |