aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-07-17 19:48:28 -0400
committerDrew DeVault <sir@cmpwn.com>2019-07-17 21:25:09 -0400
commit92b22ee9ea41ab236aae8d331781400ae2528995 (patch)
tree082390eef7ae9e0ecb930381b301e3ac47d65e27 /sway/commands
parent37308f65495feebcef5480ad28a9e1f936f7e807 (diff)
cmd_output: support current output alias
Similar to seat command, this provides an alias for the current output. Instead of the output name or identifier, `-` can be used to operate on the focused output by name and `--` can be used to operate on the focused output by its identifier. This will prevent operating on the no-op output when using either alias.
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/output.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index 3903f10d..59bc598c 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -36,7 +36,32 @@ struct cmd_results *cmd_output(int argc, char **argv) {
"Refusing to configure the no op output");
}
- struct output_config *output = new_output_config(argv[0]);
+ struct output_config *output = NULL;
+ if (strcmp(argv[0], "-") == 0 || strcmp(argv[0], "--") == 0) {
+ if (config->reading) {
+ return cmd_results_new(CMD_FAILURE,
+ "Current output alias (%s) cannot be used in the config",
+ argv[0]);
+ }
+ struct sway_output *sway_output = config->handler_context.node ?
+ node_get_output(config->handler_context.node) : NULL;
+ if (!sway_output) {
+ return cmd_results_new(CMD_FAILURE, "Unknown output");
+ }
+ if (sway_output == root->noop_output) {
+ return cmd_results_new(CMD_FAILURE,
+ "Refusing to configure the no op output");
+ }
+ if (strcmp(argv[0], "-") == 0) {
+ output = new_output_config(sway_output->wlr_output->name);
+ } else {
+ char identifier[128];
+ output_get_identifier(identifier, 128, sway_output);
+ output = new_output_config(identifier);
+ }
+ } else {
+ output = new_output_config(argv[0]);
+ }
if (!output) {
sway_log(SWAY_ERROR, "Failed to allocate output config");
return NULL;