From 8fbafbfab5671d56dd469f2205b7906c4a7f7c7c Mon Sep 17 00:00:00 2001 From: Mattias Eriksson Date: Tue, 17 Apr 2018 09:54:02 +0200 Subject: Idle handling for dpms/lockscreen et al Swayidle handles idle events and allows for dpms and lockscreen handling. It also handles systemd sleep events, and can raise a lockscreen on sleep Fixes #541 --- sway/commands/output.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'sway/commands/output.c') diff --git a/sway/commands/output.c b/sway/commands/output.c index f7e3372c..e8881f77 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -20,6 +20,25 @@ static char *bg_options[] = { "tile", }; +static struct cmd_results *cmd_output_dpms(struct output_config *output, + int *i, int argc, char **argv) { + + if (++*i >= argc) { + return cmd_results_new(CMD_INVALID, "output", "Missing dpms argument."); + } + + char *value = argv[*i]; + if (strcmp(value, "on") == 0) { + output->dpms_state = DPMS_ON; + } else if (strcmp(value, "off") == 0) { + output->dpms_state = DPMS_OFF; + } else { + return cmd_results_new(CMD_INVALID, "output", + "Invalid dpms state, valid states are on/off."); + } + return NULL; +} + static struct cmd_results *cmd_output_mode(struct output_config *output, int *i, int argc, char **argv) { if (++*i >= argc) { @@ -263,6 +282,8 @@ struct cmd_results *cmd_output(int argc, char **argv) { } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { error = cmd_output_background(output, &i, argc, argv); + } else if (strcasecmp(command, "dpms") == 0) { + error = cmd_output_dpms(output, &i, argc, argv); } else { error = cmd_results_new(CMD_INVALID, "output", "Invalid output subcommand: %s.", command); @@ -285,10 +306,10 @@ struct cmd_results *cmd_output(int argc, char **argv) { } wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " - "position %d,%d scale %f transform %d) (bg %s %s)", + "position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)", output->name, output->enabled, output->width, output->height, output->refresh_rate, output->x, output->y, output->scale, - output->transform, output->background, output->background_option); + output->transform, output->background, output->background_option, output->dpms_state); // Try to find the output container and apply configuration now. If // this is during startup then there will be no container and config -- cgit v1.2.3