Skip to content

Commit

Permalink
Merge pull request #1412 from bynect/notice
Browse files Browse the repository at this point in the history
Add backward compatibility for height + notice
  • Loading branch information
bynect authored Dec 10, 2024
2 parents dd51cbf + f753e67 commit d318dde
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/option_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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: */
3 changes: 3 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: */

0 comments on commit d318dde

Please sign in to comment.