diff options
Diffstat (limited to 'sway/commands/output')
-rw-r--r-- | sway/commands/output/toggle.c | 37 |
1 files changed, 37 insertions, 0 deletions
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 | |||