From f753e67a1b90ede35caa0dc5411c5b1d958ff92e Mon Sep 17 00:00:00 2001 From: bynect <68197565+bynect@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:42:38 +0100 Subject: [PATCH] Add backward compatibility for height + notice --- src/option_parser.c | 25 +++++++++++++++++++++---- src/utils.c | 10 ++++++++++ src/utils.h | 3 +++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/option_parser.c b/src/option_parser.c index 92f6dd62f..89ca92577 100644 --- a/src/option_parser.c +++ b/src/option_parser.c @@ -237,12 +237,12 @@ int string_parse_color(const char *s, struct color *ret) int string_parse_gradient(const char *s, struct gradient **ret) { - struct color colors[10]; + struct color colors[16]; size_t length = 0; gchar **strs = g_strsplit(s, ",", -1); for (int i = 0; strs[i] != NULL; i++) { - if (i > 10) { + if (i > 16) { LOG_W("Do you really need so many colors? ;)"); break; } @@ -255,7 +255,8 @@ int string_parse_gradient(const char *s, struct gradient **ret) g_strfreev(strs); if (length == 0) { - DIE("Unreachable"); + LOG_W("Provide at least one color"); + return false; } *ret = gradient_alloc(length); @@ -431,6 +432,21 @@ bool set_from_string(void *target, struct setting setting, const char *value) { LOG_M("Using legacy offset syntax NxN, you should switch to the new syntax (N, N)"); return true; } + + // Keep compatibility with old height semantics + if (STR_EQ(setting.name, "height") && string_is_int(value)) { + LOG_M("Setting 'height' has changed behaviour after dunst 1.12.0, see https://dunst-project.org/release/#v1.12.0."); + LOG_M("Legacy height support may be dropped in the future. If you want to hide this message transition to"); + LOG_M("'height = (0, X)' for dynamic height (old behaviour equivalent) or to 'height = (X, X)' for a fixed height."); + + int height; + if (!safe_string_to_int(&height, value)) + return false; + + ((struct length *)target)->min = 0; + ((struct length *)target)->max = height; + return true; + } return string_parse_length(target, value); case TYPE_COLOR: return string_parse_color(value, target); @@ -525,7 +541,8 @@ void save_settings(struct ini *ini) { } } else { // set as a regular setting - set_setting(curr_setting, curr_entry.value); + char *value = g_strstrip(curr_entry.value); + set_setting(curr_setting, value); } } else { // interpret this section as a rule diff --git a/src/utils.c b/src/utils.c index e47945717..1642f22ed 100644 --- a/src/utils.c +++ b/src/utils.c @@ -479,4 +479,14 @@ void add_paths_from_env(GPtrArray *arr, char *env_name, char *subdir, char *alte g_strfreev(xdg_data_dirs_arr); } +bool string_is_int(const char *str) { + if (str != NULL) { + while (isspace(*str)) str++; + while (isdigit(*str)) str++; + while (isspace(*str)) str++; + return *str == '\0'; + } + return true; +} + /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */ diff --git a/src/utils.h b/src/utils.h index d10a6451b..ea712cd9b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -253,5 +253,8 @@ FILE * fopen_verbose(const char * const path); * when the environment variable doesn't exits. */ void add_paths_from_env(GPtrArray *arr, char *env_name, char *subdir, char *alternative); + +bool string_is_int(const char *str); + #endif /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */