Skip to content

Commit f753e67

Browse files
committed
Add backward compatibility for height + notice
1 parent 162fc27 commit f753e67

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/option_parser.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ int string_parse_color(const char *s, struct color *ret)
237237

238238
int string_parse_gradient(const char *s, struct gradient **ret)
239239
{
240-
struct color colors[10];
240+
struct color colors[16];
241241
size_t length = 0;
242242

243243
gchar **strs = g_strsplit(s, ",", -1);
244244
for (int i = 0; strs[i] != NULL; i++) {
245-
if (i > 10) {
245+
if (i > 16) {
246246
LOG_W("Do you really need so many colors? ;)");
247247
break;
248248
}
@@ -255,7 +255,8 @@ int string_parse_gradient(const char *s, struct gradient **ret)
255255

256256
g_strfreev(strs);
257257
if (length == 0) {
258-
DIE("Unreachable");
258+
LOG_W("Provide at least one color");
259+
return false;
259260
}
260261

261262
*ret = gradient_alloc(length);
@@ -431,6 +432,21 @@ bool set_from_string(void *target, struct setting setting, const char *value) {
431432
LOG_M("Using legacy offset syntax NxN, you should switch to the new syntax (N, N)");
432433
return true;
433434
}
435+
436+
// Keep compatibility with old height semantics
437+
if (STR_EQ(setting.name, "height") && string_is_int(value)) {
438+
LOG_M("Setting 'height' has changed behaviour after dunst 1.12.0, see https://dunst-project.org/release/#v1.12.0.");
439+
LOG_M("Legacy height support may be dropped in the future. If you want to hide this message transition to");
440+
LOG_M("'height = (0, X)' for dynamic height (old behaviour equivalent) or to 'height = (X, X)' for a fixed height.");
441+
442+
int height;
443+
if (!safe_string_to_int(&height, value))
444+
return false;
445+
446+
((struct length *)target)->min = 0;
447+
((struct length *)target)->max = height;
448+
return true;
449+
}
434450
return string_parse_length(target, value);
435451
case TYPE_COLOR:
436452
return string_parse_color(value, target);
@@ -525,7 +541,8 @@ void save_settings(struct ini *ini) {
525541
}
526542
} else {
527543
// set as a regular setting
528-
set_setting(curr_setting, curr_entry.value);
544+
char *value = g_strstrip(curr_entry.value);
545+
set_setting(curr_setting, value);
529546
}
530547
} else {
531548
// interpret this section as a rule

src/utils.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,14 @@ void add_paths_from_env(GPtrArray *arr, char *env_name, char *subdir, char *alte
479479
g_strfreev(xdg_data_dirs_arr);
480480
}
481481

482+
bool string_is_int(const char *str) {
483+
if (str != NULL) {
484+
while (isspace(*str)) str++;
485+
while (isdigit(*str)) str++;
486+
while (isspace(*str)) str++;
487+
return *str == '\0';
488+
}
489+
return true;
490+
}
491+
482492
/* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */

src/utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,8 @@ FILE * fopen_verbose(const char * const path);
253253
* when the environment variable doesn't exits.
254254
*/
255255
void add_paths_from_env(GPtrArray *arr, char *env_name, char *subdir, char *alternative);
256+
257+
bool string_is_int(const char *str);
258+
256259
#endif
257260
/* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */

0 commit comments

Comments
 (0)