mirror of
https://github.com/swaywm/sway.git
synced 2025-11-05 13:29:51 -05:00
Implement output toggle
discussed in #4136, this can't handle wildcard but won't crash.
This commit is contained in:
parent
18ce0eec60
commit
ed2e553b8d
7 changed files with 60 additions and 0 deletions
|
|
@ -19,6 +19,7 @@ static struct cmd_handler output_handlers[] = {
|
|||
{ "resolution", output_cmd_mode },
|
||||
{ "scale", output_cmd_scale },
|
||||
{ "subpixel", output_cmd_subpixel },
|
||||
{ "toggle", output_cmd_toggle },
|
||||
{ "transform", output_cmd_transform },
|
||||
};
|
||||
|
||||
|
|
|
|||
37
sway/commands/output/toggle.c
Normal file
37
sway/commands/output/toggle.c
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#include "sway/commands.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/output.h"
|
||||
|
||||
struct cmd_results *output_cmd_toggle(int argc, char **argv) {
|
||||
if (!config->handler_context.output_config) {
|
||||
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.");
|
||||
}
|
||||
|
||||
struct sway_output *sway_output = all_output_by_name_or_id(oc->name);
|
||||
|
||||
if (sway_output == NULL) {
|
||||
return cmd_results_new(CMD_FAILURE,
|
||||
"Cannot apply toggle to unknown output %s", oc->name);
|
||||
}
|
||||
|
||||
oc = find_output_config(sway_output);
|
||||
|
||||
if (!oc || oc->enabled != 0) {
|
||||
config->handler_context.output_config->enabled = 0;
|
||||
} else {
|
||||
config->handler_context.output_config->enabled = 1;
|
||||
}
|
||||
|
||||
free(oc);
|
||||
config->handler_context.leftovers.argc = argc;
|
||||
config->handler_context.leftovers.argv = argv;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue