From 74614739183fda11e9ba0b8d1ea2c7cec1c6350a Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Wed, 6 Jan 2021 00:48:19 +0000 Subject: [PATCH 1/2] cmd: fix input/output unstripped definition quotes With the following config: set $abc "wayland wayland " set $def "0:0:wayland-seat0" The following command would fail to be executed: swaymsg -- output '$abc' scale 2 swaymsg -- input '$def' repeat_rate 2 The definition `$abc` is replaced with its content, including the quotes, which fails to match real output names. Same for `$def` We now strip quotes early in the output command. The behaviour was inconsistent between config_command() and execute_command(). * config_command() strips quotes before do_var_replacement() and also after, under some conditions. * execute_command() strips them only before. execute_command() is run after receiving swaymsg command hence the failing example mentioned above. Since we now strip quotes in cmd_output and cmd_input we prevent config_command() from stripping them twice. --- sway/commands.c | 2 ++ sway/commands/input.c | 7 +++++++ sway/commands/output.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index fe1e98b53..0cc16f775 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -403,6 +403,8 @@ struct cmd_results *config_command(char *exec, char **new_block) { && handler->handle != cmd_bindswitch && handler->handle != cmd_set && handler->handle != cmd_for_window + && handler->handle != cmd_output + && handler->handle != cmd_input && (*argv[i] == '\"' || *argv[i] == '\'')) { strip_quotes(argv[i]); } diff --git a/sway/commands/input.c b/sway/commands/input.c index c9bb8e06a..f0414bc66 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -51,6 +51,13 @@ struct cmd_results *cmd_input(int argc, char **argv) { return error; } + // Commands from config_command() & execute_command() don't handle quotes the same way + for (int i = 0; i < argc; ++i) { + if (*argv[i] == '\"' || *argv[i] == '\'') { + strip_quotes(argv[i]); + } + } + sway_log(SWAY_DEBUG, "entering input block: %s", argv[0]); config->handler_context.input_config = new_input_config(argv[0]); diff --git a/sway/commands/output.c b/sway/commands/output.c index 5186a2ba1..d28387a0c 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c @@ -2,6 +2,7 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/output.h" +#include "stringop.h" #include "list.h" #include "log.h" @@ -39,6 +40,13 @@ struct cmd_results *cmd_output(int argc, char **argv) { "Refusing to configure the no op output"); } + // Commands from config_command() & execute_command() don't handle quotes the same way + for (int i = 0; i < argc; ++i) { + if (*argv[i] == '\"' || *argv[i] == '\'') { + strip_quotes(argv[i]); + } + } + struct output_config *output = NULL; if (strcmp(argv[0], "-") == 0 || strcmp(argv[0], "--") == 0) { if (config->reading) { From 289e5e793adce2f8161c3b4158458be5f0a22d82 Mon Sep 17 00:00:00 2001 From: Paul Riou Date: Fri, 15 Jan 2021 00:13:27 +0000 Subject: [PATCH 2/2] config: Use output_name_cmp instead of strcmp Might as well use that function in case it needs handling special cases in the future. --- sway/config/output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/config/output.c b/sway/config/output.c index b59cabd4e..d4d0a6cd8 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -615,7 +615,7 @@ void apply_output_config_to_outputs(struct output_config *oc) { wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) { char *name = sway_output->wlr_output->name; output_get_identifier(id, sizeof(id), sway_output); - if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { + if (wildcard || !output_name_cmp(oc, name) || !output_name_cmp(oc, id)) { struct output_config *current = get_output_config(id, sway_output); if (!current) { // No stored output config matched, apply oc directly