diff options
author | Moelf <jerryling315@gmail.com> | 2019-05-10 23:57:53 -0700 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2019-05-14 00:11:04 -0400 |
commit | ed2e553b8d0dff3e74eeaa80a2586458271b2565 (patch) | |
tree | 3b48f4efad369798686611f21a380330e4c930dc /sway/commands/output | |
parent | Spawn swaybar as a wayland client (diff) | |
download | sway-ed2e553b8d0dff3e74eeaa80a2586458271b2565.tar.gz sway-ed2e553b8d0dff3e74eeaa80a2586458271b2565.tar.zst sway-ed2e553b8d0dff3e74eeaa80a2586458271b2565.zip |
Implement output toggle
discussed in #4136, this can't handle wildcard but won't crash.
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 | |||