From 09c3c33081a8b8c941cbc1eeab0e5a70e54d04ff Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 8 Oct 2018 09:56:34 -0400 Subject: [PATCH] Allow swaynag to be disabled --- sway/commands/swaynag_command.c | 15 ++++++++++----- sway/config.c | 3 ++- sway/sway.5.scd | 3 +++ sway/swaynag.c | 8 ++++++++ 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/sway/commands/swaynag_command.c b/sway/commands/swaynag_command.c index c57a80a64..6c86f1a76 100644 --- a/sway/commands/swaynag_command.c +++ b/sway/commands/swaynag_command.c @@ -9,12 +9,17 @@ struct cmd_results *cmd_swaynag_command(int argc, char **argv) { return error; } - if (config->swaynag_command) { - free(config->swaynag_command); + free(config->swaynag_command); + config->swaynag_command = NULL; + + char *new_command = join_args(argv, argc); + if (strcmp(new_command, "-") != 0) { + config->swaybg_command = new_command; + wlr_log(WLR_DEBUG, "Using custom swaynag command: %s", + config->swaynag_command); + } else { + free(new_command); } - config->swaynag_command = join_args(argv, argc); - wlr_log(WLR_DEBUG, "Using custom swaynag command: %s", - config->swaynag_command); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index 7f29347a5..e95c7b357 100644 --- a/sway/config.c +++ b/sway/config.c @@ -137,6 +137,7 @@ void free_config(struct sway_config *config) { free(config->floating_scroll_right_cmd); free(config->font); free(config->swaybg_command); + free(config->swaynag_command); free((char *)config->current_config_path); free((char *)config->current_config); free(config); @@ -167,7 +168,7 @@ static void set_color(float dest[static 4], uint32_t color) { } static void config_defaults(struct sway_config *config) { - config->swaynag_command = strdup("swaynag"); + if (!(config->swaynag_command = strdup("swaynag"))) goto cleanup; config->swaynag_config_errors = (struct swaynag_instance){ .args = "--type error " "--message 'There are errors in your config file' " diff --git a/sway/sway.5.scd b/sway/sway.5.scd index c7d20b17c..43f0e1322 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -81,6 +81,9 @@ The following commands may only be used in the configuration file. arguments. This should be placed at the top of the config for the best results. + It can be disabled by setting the command to a single dash: + _swaynag\_command -_ + The following commands cannot be used directly in the configuration file. They are expected to be used with *bindsym* or at runtime through *swaymsg*(1). diff --git a/sway/swaynag.c b/sway/swaynag.c index d905db2b8..38e74b881 100644 --- a/sway/swaynag.c +++ b/sway/swaynag.c @@ -11,6 +11,10 @@ bool swaynag_spawn(const char *swaynag_command, struct swaynag_instance *swaynag) { + if (!swaynag_command) { + return true; + } + if (swaynag->detailed) { if (pipe(swaynag->fd) != 0) { wlr_log(WLR_ERROR, "Failed to create pipe for swaynag"); @@ -58,6 +62,10 @@ void swaynag_kill(struct swaynag_instance *swaynag) { void swaynag_log(const char *swaynag_command, struct swaynag_instance *swaynag, const char *fmt, ...) { + if (!swaynag_command) { + return; + } + if (!swaynag->detailed) { wlr_log(WLR_ERROR, "Attempting to write to non-detailed swaynag inst"); return;