From 9d04a7bfcf9d58352a126ee925f0c1e6aaf01e20 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 14 Feb 2012 14:46:19 +0100 Subject: [PATCH] make highlight colors configurable during runtime --- config.c | 27 +++++++++++++++++++++++++-- page_widget.c | 5 +++-- zathura.c | 7 ------- zathura.h | 1 + 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/config.c b/config.c index 3be28b2..8606441 100644 --- a/config.c +++ b/config.c @@ -14,6 +14,26 @@ #include #include +static void +cb_color_change(girara_session_t* session, const char* name, girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data)) +{ + g_return_if_fail(value != NULL); + g_return_if_fail(session != NULL); + g_return_if_fail(session->global.data != NULL); + g_return_if_fail(name != NULL); + zathura_t* zathura = session->global.data; + + char* string_value = (char*) value; + if (g_strcmp0(name, "highlight-color") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color)); + } else if (g_strcmp0(name, "highlight-active-active") == 0) { + gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color_active)); + } + + /* TODO: cause a redraw here? */ +} + + void config_load_default(zathura_t* zathura) { @@ -59,8 +79,11 @@ config_load_default(zathura_t* zathura) string_value = "#000000"; girara_setting_add(gsession, "recolor-lightcolor", string_value, STRING, false, "Recoloring (light color)", NULL, NULL); - string_value = "#9FBC00"; - girara_setting_add(gsession, "highlight-color", string_value, STRING, false, "Color for highlighting", NULL, NULL); + girara_setting_add(gsession, "highlight-color", NULL, STRING, false, "Color for highlighting", cb_color_change, NULL); + girara_setting_set(gsession, "highlight-color", "#9FBC00"); + girara_setting_add(gsession, "highlight-active-color", NULL, STRING, false, "Color for highlighting (active)", cb_color_change, NULL); + girara_setting_set(gsession, "highlight-active-color", "#00BC00"); + float_value = 0.5; girara_setting_add(gsession, "highlight-transparency", &float_value, FLOAT, false, "Transparency for highlighting", NULL, NULL); bool_value = true; diff --git a/page_widget.c b/page_widget.c index e3ee81b..40cdd0b 100644 --- a/page_widget.c +++ b/page_widget.c @@ -325,10 +325,11 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect); /* draw position */ - GdkColor color = priv->zathura->ui.colors.highlight_color; if (idx == priv->search_current) { - cairo_set_source_rgba(cairo, 0, color.green, color.blue, transparency); + GdkColor color = priv->zathura->ui.colors.highlight_color_active; + cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency); } else { + GdkColor color = priv->zathura->ui.colors.highlight_color; cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency); } cairo_rectangle(cairo, rectangle.x1, rectangle.y1, diff --git a/zathura.c b/zathura.c index d195fca..dadc00d 100644 --- a/zathura.c +++ b/zathura.c @@ -244,13 +244,6 @@ zathura_init(int argc, char* argv[]) g_free(string_value); } - string_value = NULL; - girara_setting_get(zathura->ui.session, "highlight-color", &string_value); - if (string_value != NULL) { - gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color)); - g_free(string_value); - } - /* database */ zathura->database = zathura_db_init(zathura->config.data_dir); if (zathura->database == NULL) { diff --git a/zathura.h b/zathura.h index c769474..2c27467 100644 --- a/zathura.h +++ b/zathura.h @@ -50,6 +50,7 @@ typedef struct zathura_s GdkColor recolor_dark_color; /**< Dark color for recoloring */ GdkColor recolor_light_color; /**< Light color for recoloring */ GdkColor highlight_color; /**< Color for highlighting */ + GdkColor highlight_color_active; /** Color for highlighting */ } colors; GtkWidget *page_widget_alignment;