diff options
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | sway/commands/output.c | 1 | ||||
-rw-r--r-- | sway/commands/output/dpms.c | 45 | ||||
-rw-r--r-- | sway/commands/output/power.c | 43 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-output.5.scd | 12 |
6 files changed, 60 insertions, 43 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index 5f71a79d..013a7b82 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -287,6 +287,7 @@ sway_cmd output_cmd_max_render_time; | |||
287 | sway_cmd output_cmd_mode; | 287 | sway_cmd output_cmd_mode; |
288 | sway_cmd output_cmd_modeline; | 288 | sway_cmd output_cmd_modeline; |
289 | sway_cmd output_cmd_position; | 289 | sway_cmd output_cmd_position; |
290 | sway_cmd output_cmd_power; | ||
290 | sway_cmd output_cmd_render_bit_depth; | 291 | sway_cmd output_cmd_render_bit_depth; |
291 | sway_cmd output_cmd_scale; | 292 | sway_cmd output_cmd_scale; |
292 | sway_cmd output_cmd_scale_filter; | 293 | sway_cmd output_cmd_scale_filter; |
diff --git a/sway/commands/output.c b/sway/commands/output.c index 125df5a7..c102344d 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -18,6 +18,7 @@ static const struct cmd_handler output_handlers[] = { | |||
18 | { "modeline", output_cmd_modeline }, | 18 | { "modeline", output_cmd_modeline }, |
19 | { "pos", output_cmd_position }, | 19 | { "pos", output_cmd_position }, |
20 | { "position", output_cmd_position }, | 20 | { "position", output_cmd_position }, |
21 | { "power", output_cmd_power }, | ||
21 | { "render_bit_depth", output_cmd_render_bit_depth }, | 22 | { "render_bit_depth", output_cmd_render_bit_depth }, |
22 | { "res", output_cmd_mode }, | 23 | { "res", output_cmd_mode }, |
23 | { "resolution", output_cmd_mode }, | 24 | { "resolution", output_cmd_mode }, |
diff --git a/sway/commands/output/dpms.c b/sway/commands/output/dpms.c index 638c0ade..c7adbd58 100644 --- a/sway/commands/output/dpms.c +++ b/sway/commands/output/dpms.c | |||
@@ -1,45 +1,8 @@ | |||
1 | #include "log.h" | ||
1 | #include "sway/commands.h" | 2 | #include "sway/commands.h" |
2 | #include "sway/config.h" | ||
3 | #include "sway/output.h" | ||
4 | #include "util.h" | ||
5 | #include <strings.h> | ||
6 | 3 | ||
7 | struct cmd_results *output_cmd_dpms(int argc, char **argv) { | 4 | struct cmd_results *output_cmd_dpms(int argc, char **argv) { |
8 | if (!config->handler_context.output_config) { | 5 | sway_log(SWAY_INFO, "The \"output dpms\" command is deprecated, " |
9 | return cmd_results_new(CMD_FAILURE, "Missing output config"); | 6 | "use \"output power\" instead"); |
10 | } | 7 | return output_cmd_power(argc, argv); |
11 | if (!argc) { | ||
12 | return cmd_results_new(CMD_INVALID, "Missing dpms argument."); | ||
13 | } | ||
14 | |||
15 | enum config_dpms current_dpms = DPMS_ON; | ||
16 | |||
17 | if (strcasecmp(argv[0], "toggle") == 0) { | ||
18 | |||
19 | const char *oc_name = config->handler_context.output_config->name; | ||
20 | if (strcmp(oc_name, "*") == 0) { | ||
21 | return cmd_results_new(CMD_INVALID, | ||
22 | "Cannot apply toggle to all outputs."); | ||
23 | } | ||
24 | |||
25 | struct sway_output *sway_output = all_output_by_name_or_id(oc_name); | ||
26 | if (!sway_output || !sway_output->wlr_output) { | ||
27 | return cmd_results_new(CMD_FAILURE, | ||
28 | "Cannot apply toggle to unknown output %s", oc_name); | ||
29 | } | ||
30 | |||
31 | if (sway_output->enabled && !sway_output->wlr_output->enabled) { | ||
32 | current_dpms = DPMS_OFF; | ||
33 | } | ||
34 | } | ||
35 | |||
36 | if (parse_boolean(argv[0], current_dpms == DPMS_ON)) { | ||
37 | config->handler_context.output_config->dpms_state = DPMS_ON; | ||
38 | } else { | ||
39 | config->handler_context.output_config->dpms_state = DPMS_OFF; | ||
40 | } | ||
41 | |||
42 | config->handler_context.leftovers.argc = argc - 1; | ||
43 | config->handler_context.leftovers.argv = argv + 1; | ||
44 | return NULL; | ||
45 | } | 8 | } |
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 | |||
7 | struct 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 | } | ||
diff --git a/sway/meson.build b/sway/meson.build index 47c59dd5..ced7419c 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -191,6 +191,7 @@ sway_sources = files( | |||
191 | 'commands/output/max_render_time.c', | 191 | 'commands/output/max_render_time.c', |
192 | 'commands/output/mode.c', | 192 | 'commands/output/mode.c', |
193 | 'commands/output/position.c', | 193 | 'commands/output/position.c', |
194 | 'commands/output/power.c', | ||
194 | 'commands/output/render_bit_depth.c', | 195 | 'commands/output/render_bit_depth.c', |
195 | 'commands/output/scale.c', | 196 | 'commands/output/scale.c', |
196 | 'commands/output/scale_filter.c', | 197 | 'commands/output/scale_filter.c', |
diff --git a/sway/sway-output.5.scd b/sway/sway-output.5.scd index 4159a851..45429da2 100644 --- a/sway/sway-output.5.scd +++ b/sway/sway-output.5.scd | |||
@@ -119,12 +119,20 @@ must be separated by one space. For example: | |||
119 | Enables or disables the specified output (all outputs are enabled by | 119 | Enables or disables the specified output (all outputs are enabled by |
120 | default). | 120 | default). |
121 | 121 | ||
122 | As opposed to the _power_ command, the output will loose its current | ||
123 | workspace and windows. | ||
124 | |||
122 | *output* <name> toggle | 125 | *output* <name> toggle |
123 | Toggle the specified output. | 126 | Toggle the specified output. |
124 | 127 | ||
128 | *output* <name> power on|off|toggle | ||
129 | Turns on or off the specified output. | ||
130 | |||
131 | As opposed to the _enable_ and _disable_ commands, the output keeps its | ||
132 | current workspaces and windows. | ||
133 | |||
125 | *output* <name> dpms on|off|toggle | 134 | *output* <name> dpms on|off|toggle |
126 | Enables or disables the specified output via DPMS. To turn an output off | 135 | Deprecated. Alias for _power_. |
127 | (ie. blank the screen but keep workspaces as-is), one can set DPMS to off. | ||
128 | 136 | ||
129 | *output* <name> max_render_time off|<msec> | 137 | *output* <name> max_render_time off|<msec> |
130 | Controls when sway composites the output, as a positive number of | 138 | Controls when sway composites the output, as a positive number of |