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; diff --git a/sway/sway-output.5.scd b/sway/sway-output.5.scd index e20d0aba..806054fc 100644 --- a/sway/sway-output.5.scd +++ b/sway/sway-output.5.scd @@ -11,7 +11,9 @@ You may combine output commands into one, like so: output HDMI-A-1 mode 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch You can get a list of output names with *swaymsg -t get_outputs*. You may also -match any output by using the output name "\*". +match any output by using the output name "\*". Additionally, "-" can be used +to match the focused output by name and "--" can be used to match the focused +output by its identifier. Some outputs may have different names when disconnecting and reconnecting. To identify these, the name can be substituted for a string consisting of the make,