diff --git a/sway/commands.c b/sway/commands.c index c2c12ee65..7cb1816ca 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -303,12 +303,14 @@ list_t *execute_command(char *_exec, struct sway_seat *seat, cmd_results_new(CMD_FAILURE, "No matching node.")); } else { struct cmd_results *fail_res = NULL; + bool has_success = false; for (int i = 0; i < containers->length; ++i) { struct sway_container *container = containers->items[i]; set_config_node(&container->node, true); struct cmd_results *res = handler->handle(argc-1, argv+1); if (res->status == CMD_SUCCESS) { free_cmd_results(res); + has_success = true; } else { // last failure will take precedence if (fail_res) { @@ -322,6 +324,18 @@ list_t *execute_command(char *_exec, struct sway_seat *seat, } } } + if(handler->handle == cmd_scratchpad) { + if (fail_res) { + free_cmd_results(fail_res); + fail_res = NULL; + } + if(!has_success) { + fail_res = cmd_results_new(CMD_INVALID, "Container is not in scratchpad."); + list_add(res_list, fail_res); + free_argv(argc, argv); + goto cleanup; + } + } list_add(res_list, fail_res ? fail_res : cmd_results_new(CMD_SUCCESS, NULL)); } diff --git a/sway/commands/scratchpad.c b/sway/commands/scratchpad.c index 8a63740c3..1827b791e 100644 --- a/sway/commands/scratchpad.c +++ b/sway/commands/scratchpad.c @@ -121,7 +121,7 @@ struct cmd_results *cmd_scratchpad(int argc, char **argv) { // we'll return an error. The same is true if the // overridden node is not a container. if (!con || !con->scratchpad) { - return cmd_results_new(CMD_INVALID, "Container is not in scratchpad."); + return cmd_results_new(CMD_FAILURE, NULL); } scratchpad_toggle_container(con); } else {