2018-06-03 03:33:16 +02:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2021-03-15 17:06:46 +01:00
|
|
|
#include "sway/output.h"
|
2018-07-23 21:04:46 +02:00
|
|
|
#include "util.h"
|
2021-03-15 17:06:46 +01:00
|
|
|
#include <strings.h>
|
2018-06-03 03:33:16 +02:00
|
|
|
|
|
|
|
struct cmd_results *output_cmd_dpms(int argc, char **argv) {
|
|
|
|
if (!config->handler_context.output_config) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_FAILURE, "Missing output config");
|
2018-06-03 03:33:16 +02:00
|
|
|
}
|
|
|
|
if (!argc) {
|
2019-01-11 00:27:21 +01:00
|
|
|
return cmd_results_new(CMD_INVALID, "Missing dpms argument.");
|
2018-06-03 03:33:16 +02:00
|
|
|
}
|
|
|
|
|
2021-03-15 17:06:46 +01:00
|
|
|
enum config_dpms current_dpms = DPMS_ON;
|
|
|
|
|
|
|
|
if (strcasecmp(argv[0], "toggle") == 0) {
|
|
|
|
|
|
|
|
const char *oc_name = config->handler_context.output_config->name;
|
|
|
|
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 || !sway_output->wlr_output) {
|
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Cannot apply toggle to unknown output %s", oc_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sway_output->enabled && !sway_output->wlr_output->enabled) {
|
|
|
|
current_dpms = DPMS_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (parse_boolean(argv[0], current_dpms == DPMS_ON)) {
|
2018-06-03 03:33:16 +02:00
|
|
|
config->handler_context.output_config->dpms_state = DPMS_ON;
|
|
|
|
} else {
|
2018-07-23 21:04:46 +02:00
|
|
|
config->handler_context.output_config->dpms_state = DPMS_OFF;
|
2018-06-03 03:33:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
config->handler_context.leftovers.argc = argc - 1;
|
|
|
|
config->handler_context.leftovers.argv = argv + 1;
|
|
|
|
return NULL;
|
|
|
|
}
|