From 9265c9473a807b9f3c08903acf5f60253fbb1130 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Wed, 14 Mar 2012 17:33:35 +0100 Subject: [PATCH] Add 'recolor' setting --- callbacks.c | 18 ++++++++++++++++++ callbacks.h | 12 ++++++++++++ config.c | 3 ++- render.c | 2 +- shortcuts.c | 8 ++++---- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/callbacks.c b/callbacks.c index 2ceb8ba..27c014d 100644 --- a/callbacks.c +++ b/callbacks.c @@ -325,3 +325,21 @@ cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t* return false; } + +void +cb_setting_recolor_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; + + bool bool_value = *((bool*) value); + + if (zathura->global.recolor != bool_value) { + zathura->global.recolor = bool_value; + render_all(zathura); + } +} diff --git a/callbacks.h b/callbacks.h index f575bca..fc332f7 100644 --- a/callbacks.h +++ b/callbacks.h @@ -98,4 +98,16 @@ bool cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog) */ bool cb_view_resized(GtkWidget* widget, GtkAllocation* allocation, zathura_t* zathura); +/** + * Emitted when the 'recolor' setting is changed + * + * @param session Girara session + * @param name Name of the setting ("recolor") + * @param type Type of the setting (BOOLEAN) + * @param value New value + * @param data Custom data + */ +void cb_setting_recolor_change(girara_session_t* session, const char* name, + girara_setting_type_t type, void* value, void* data); + #endif // CALLBACKS_H diff --git a/config.c b/config.c index 6b117d6..f3c77c2 100644 --- a/config.c +++ b/config.c @@ -38,7 +38,6 @@ cb_color_change(girara_session_t* session, const char* name, girara_setting_type /* TODO: cause a redraw here? */ } - void config_load_default(zathura_t* zathura) { @@ -88,6 +87,8 @@ config_load_default(zathura_t* zathura) 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"); + bool_value = false; + girara_setting_add(gsession, "recolor", &bool_value, BOOLEAN, false, _("Recolor pages"), cb_setting_recolor_change, NULL); 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/render.c b/render.c index 221e8c3..fb3912a 100644 --- a/render.c +++ b/render.c @@ -132,7 +132,7 @@ render(zathura_t* zathura, zathura_page_t* page) unsigned char* image = cairo_image_surface_get_data(surface); /* recolor */ - if (zathura->global.recolor) { + if (zathura->global.recolor == true) { /* recolor code based on qimageblitz library flatten() function (http://sourceforge.net/projects/qimageblitz/) */ diff --git a/shortcuts.c b/shortcuts.c index 03db40c..cd6bbb9 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -359,11 +359,11 @@ sc_recolor(girara_session_t* session, girara_argument_t* UNUSED(argument), girara_event_t* UNUSED(event), unsigned int UNUSED(t)) { g_return_val_if_fail(session != NULL, false); - g_return_val_if_fail(session->global.data != NULL, false); - zathura_t* zathura = session->global.data; - zathura->global.recolor = !zathura->global.recolor; - render_all(zathura); + bool value = false; + girara_setting_get(session, "recolor", &value); + value = !value; + girara_setting_set(session, "recolor", &value); return false; }