diff --git a/zathura/config.c b/zathura/config.c index d3fe43a..fcbff3f 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -56,9 +56,9 @@ cb_color_change(girara_session_t* session, const char* name, const char* string_value = (const char*) value; if (g_strcmp0(name, "highlight-color") == 0) { - gdk_rgba_parse(&(zathura->ui.colors.highlight_color), string_value); + parse_color(&zathura->ui.colors.highlight_color, string_value); } else if (g_strcmp0(name, "highlight-active-color") == 0) { - gdk_rgba_parse(&(zathura->ui.colors.highlight_color_active), string_value); + parse_color(&zathura->ui.colors.highlight_color_active, string_value); } else if (g_strcmp0(name, "recolor-darkcolor") == 0) { if (zathura->sync.render_thread != NULL) { zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, NULL, string_value); @@ -68,9 +68,9 @@ cb_color_change(girara_session_t* session, const char* name, zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, string_value, NULL); } } else if (g_strcmp0(name, "render-loading-bg") == 0) { - gdk_rgba_parse(&(zathura->ui.colors.render_loading_bg), string_value); + parse_color(&zathura->ui.colors.render_loading_bg, string_value); } else if (g_strcmp0(name, "render-loading-fg") == 0) { - gdk_rgba_parse(&(zathura->ui.colors.render_loading_fg), string_value); + parse_color(&zathura->ui.colors.render_loading_fg, string_value); } render_all(zathura); diff --git a/zathura/render.c b/zathura/render.c index 4199485..5953de0 100644 --- a/zathura/render.c +++ b/zathura/render.c @@ -375,13 +375,15 @@ zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer, if (dark != NULL) { GdkRGBA color; - gdk_rgba_parse(&color, dark); - zathura_renderer_set_recolor_colors(renderer, NULL, &color); + if (parse_color(&color, dark) == true) { + zathura_renderer_set_recolor_colors(renderer, NULL, &color); + } } if (light != NULL) { GdkRGBA color; - gdk_rgba_parse(&color, light); - zathura_renderer_set_recolor_colors(renderer, &color, NULL); + if (parse_color(&color, light) == true) { + zathura_renderer_set_recolor_colors(renderer, &color, NULL); + } } } diff --git a/zathura/utils.c b/zathura/utils.c index 90e8268..9aeaff3 100644 --- a/zathura/utils.c +++ b/zathura/utils.c @@ -280,3 +280,13 @@ find_first_page_column(const char* first_page_column_list, return first_page_column; } + +bool +parse_color(GdkRGBA* color, const char* str) +{ + if (gdk_rgba_parse(color, str) == FALSE) { + girara_warning("Failed to parse color string '%s'.", str); + return false; + } + return true; +} diff --git a/zathura/utils.h b/zathura/utils.h index c30d3f9..135eb2e 100644 --- a/zathura/utils.h +++ b/zathura/utils.h @@ -120,4 +120,14 @@ double zathura_correct_scale_value(girara_session_t* session, const double unsigned int find_first_page_column(const char* first_page_column_list, const unsigned int pages_per_row); +/** + * Parse color string and print warning if color cannot be parsed. + * + * @param[out] color The color + * @param[in] str Color string + * + * @return True if color string can be parsed, false otherwise. + */ +bool parse_color(GdkRGBA* color, const char* str); + #endif // UTILS_H diff --git a/zathura/zathura.c b/zathura/zathura.c index d61877c..94609bf 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -245,7 +245,7 @@ init_css(zathura_t* zathura) GdkRGBA rgba = {0, 0, 0, 0}; girara_setting_get(zathura->ui.session, index_settings[s], &tmp_value); if (tmp_value != NULL) { - gdk_rgba_parse(&rgba, tmp_value); + parse_color(&rgba, tmp_value); g_free(tmp_value); }