aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/output
diff options
context:
space:
mode:
authorMoelf <jerryling315@gmail.com>2019-05-10 23:57:53 -0700
committerBrian Ashworth <bosrsf04@gmail.com>2019-05-14 00:11:04 -0400
commited2e553b8d0dff3e74eeaa80a2586458271b2565 (patch)
tree3b48f4efad369798686611f21a380330e4c930dc /sway/commands/output
parent18ce0eec608d066565dda3a9a6454f67007116e5 (diff)
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.c37
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 @@
+#include "sway/commands.h"
+#include "sway/config.h"
+#include "sway/output.h"
+
+struct cmd_results *output_cmd_toggle(int argc, char **argv) {
+ if (!config->handler_context.output_config) {
+ return cmd_results_new(CMD_FAILURE, "Missing output config");
+ }
+
+ struct output_config *oc = config->handler_context.output_config;
+
+ if (strcmp(oc->name, "*") == 0) {
+ return cmd_results_new(CMD_INVALID,
+ "Cannot apply toggle to all outputs.");
+ }
+
+ struct sway_output *sway_output = all_output_by_name_or_id(oc->name);
+
+ if (sway_output == NULL) {
+ return cmd_results_new(CMD_FAILURE,
+ "Cannot apply toggle to unknown output %s", oc->name);
+ }
+
+ oc = find_output_config(sway_output);
+
+ if (!oc || oc->enabled != 0) {
+ config->handler_context.output_config->enabled = 0;
+ } else {
+ config->handler_context.output_config->enabled = 1;
+ }
+
+ free(oc);
+ config->handler_context.leftovers.argc = argc;
+ config->handler_context.leftovers.argv = argv;
+ return NULL;
+}
+