diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-07-17 19:48:28 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-17 21:25:09 -0400 |
commit | 92b22ee9ea41ab236aae8d331781400ae2528995 (patch) | |
tree | 082390eef7ae9e0ecb930381b301e3ac47d65e27 | |
parent | input_cmd_xkb_*: cleanup includes (diff) | |
download | sway-92b22ee9ea41ab236aae8d331781400ae2528995.tar.gz sway-92b22ee9ea41ab236aae8d331781400ae2528995.tar.zst sway-92b22ee9ea41ab236aae8d331781400ae2528995.zip |
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.
-rw-r--r-- | sway/commands/output.c | 27 | ||||
-rw-r--r-- | sway/sway-output.5.scd | 4 |
2 files changed, 29 insertions, 2 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) { | |||
36 | "Refusing to configure the no op output"); | 36 | "Refusing to configure the no op output"); |
37 | } | 37 | } |
38 | 38 | ||
39 | struct output_config *output = new_output_config(argv[0]); | 39 | struct output_config *output = NULL; |
40 | if (strcmp(argv[0], "-") == 0 || strcmp(argv[0], "--") == 0) { | ||
41 | if (config->reading) { | ||
42 | return cmd_results_new(CMD_FAILURE, | ||
43 | "Current output alias (%s) cannot be used in the config", | ||
44 | argv[0]); | ||
45 | } | ||
46 | struct sway_output *sway_output = config->handler_context.node ? | ||
47 | node_get_output(config->handler_context.node) : NULL; | ||
48 | if (!sway_output) { | ||
49 | return cmd_results_new(CMD_FAILURE, "Unknown output"); | ||
50 | } | ||
51 | if (sway_output == root->noop_output) { | ||
52 | return cmd_results_new(CMD_FAILURE, | ||
53 | "Refusing to configure the no op output"); | ||
54 | } | ||
55 | if (strcmp(argv[0], "-") == 0) { | ||
56 | output = new_output_config(sway_output->wlr_output->name); | ||
57 | } else { | ||
58 | char identifier[128]; | ||
59 | output_get_identifier(identifier, 128, sway_output); | ||
60 | output = new_output_config(identifier); | ||
61 | } | ||
62 | } else { | ||
63 | output = new_output_config(argv[0]); | ||
64 | } | ||
40 | if (!output) { | 65 | if (!output) { |
41 | sway_log(SWAY_ERROR, "Failed to allocate output config"); | 66 | sway_log(SWAY_ERROR, "Failed to allocate output config"); |
42 | return NULL; | 67 | 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: | |||
11 | output HDMI-A-1 mode 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch | 11 | output HDMI-A-1 mode 1920x1080 pos 1920,0 bg ~/wallpaper.png stretch |
12 | 12 | ||
13 | You can get a list of output names with *swaymsg -t get_outputs*. You may also | 13 | You can get a list of output names with *swaymsg -t get_outputs*. You may also |
14 | match any output by using the output name "\*". | 14 | match any output by using the output name "\*". Additionally, "-" can be used |
15 | to match the focused output by name and "--" can be used to match the focused | ||
16 | output by its identifier. | ||
15 | 17 | ||
16 | Some outputs may have different names when disconnecting and reconnecting. To | 18 | Some outputs may have different names when disconnecting and reconnecting. To |
17 | identify these, the name can be substituted for a string consisting of the make, | 19 | identify these, the name can be substituted for a string consisting of the make, |