aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/output/power.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/output/power.c')
-rw-r--r--sway/commands/output/power.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/sway/commands/output/power.c b/sway/commands/output/power.c
new file mode 100644
index 00000000..c783e69b
--- /dev/null
+++ b/sway/commands/output/power.c
@@ -0,0 +1,43 @@
1#include <strings.h>
2#include "sway/commands.h"
3#include "sway/config.h"
4#include "sway/output.h"
5#include "util.h"
6
7struct cmd_results *output_cmd_power(int argc, char **argv) {
8 if (!config->handler_context.output_config) {
9 return cmd_results_new(CMD_FAILURE, "Missing output config");
10 }
11 if (argc == 0) {
12 return cmd_results_new(CMD_INVALID, "Missing power argument");
13 }
14
15 enum config_dpms current_dpms = DPMS_ON;
16 if (strcasecmp(argv[0], "toggle") == 0) {
17 const char *oc_name = config->handler_context.output_config->name;
18 if (strcmp(oc_name, "*") == 0) {
19 return cmd_results_new(CMD_INVALID,
20 "Cannot apply toggle to all outputs");
21 }
22
23 struct sway_output *sway_output = all_output_by_name_or_id(oc_name);
24 if (!sway_output || !sway_output->wlr_output) {
25 return cmd_results_new(CMD_FAILURE,
26 "Cannot apply toggle to unknown output %s", oc_name);
27 }
28
29 if (sway_output->enabled && !sway_output->wlr_output->enabled) {
30 current_dpms = DPMS_OFF;
31 }
32 }
33
34 if (parse_boolean(argv[0], current_dpms == DPMS_ON)) {
35 config->handler_context.output_config->dpms_state = DPMS_ON;
36 } else {
37 config->handler_context.output_config->dpms_state = DPMS_OFF;
38 }
39
40 config->handler_context.leftovers.argc = argc - 1;
41 config->handler_context.leftovers.argv = argv + 1;
42 return NULL;
43}