Toggle all outputs

This commit is contained in:
Celio Grand 2024-01-02 13:49:33 +08:00
parent 0aceff7469
commit e239a9aee9
2 changed files with 30 additions and 22 deletions

View file

@ -16,8 +16,14 @@ struct cmd_results *output_cmd_power(int argc, char **argv) {
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");
for (int i = 0; i < config->output_configs->length; i++) {
struct output_config *oc = config->output_configs->items[i];
oc->power = !oc->power;
}
config->handler_context.leftovers.argc = argc - 1;
config->handler_context.leftovers.argv = argv + 1;
return NULL;
}
struct sway_output *sway_output = all_output_by_name_or_id(oc_name);

View file

@ -7,13 +7,13 @@ struct cmd_results *output_cmd_toggle(int argc, char **argv) {
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.");
if (strcmp(config->handler_context.output_config->name, "*") == 0) {
for (int i = 0; i < config->output_configs->length; i++) {
struct output_config *oc = config->output_configs->items[i];
oc->enabled = !oc->enabled;
}
} else {
struct output_config *oc = config->handler_context.output_config;
struct sway_output *sway_output = all_output_by_name_or_id(oc->name);
if (sway_output == NULL) {
@ -30,6 +30,8 @@ struct cmd_results *output_cmd_toggle(int argc, char **argv) {
}
free(oc);
}
config->handler_context.leftovers.argc = argc;
config->handler_context.leftovers.argv = argv;
return NULL;