Commit b02d3d4b authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

Move recolor state to the renderer


Signed-off-by: Sebastian Ramacher's avatarSebastian Ramacher <sebastian+dev@ramacher.at>
parent 10115db6
...@@ -488,10 +488,10 @@ cb_setting_recolor_change(girara_session_t* session, const char* name, ...@@ -488,10 +488,10 @@ cb_setting_recolor_change(girara_session_t* session, const char* name,
g_return_if_fail(name != NULL); g_return_if_fail(name != NULL);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
bool bool_value = *((bool*) value); const bool bool_value = *((bool*) value);
if (zathura->global.recolor != bool_value) { if (zathura->sync.render_thread != NULL && zathura_renderer_recolor_enabled(zathura->sync.render_thread) != bool_value) {
zathura->global.recolor = bool_value; zathura_renderer_enable_recolor(zathura->sync.render_thread, bool_value);
render_all(zathura); render_all(zathura);
} }
} }
...@@ -506,10 +506,10 @@ cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name, ...@@ -506,10 +506,10 @@ cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name,
g_return_if_fail(name != NULL); g_return_if_fail(name != NULL);
zathura_t* zathura = session->global.data; zathura_t* zathura = session->global.data;
bool bool_value = *((bool*) value); const bool bool_value = *((bool*) value);
if (zathura->global.recolor_keep_hue != bool_value) { if (zathura->sync.render_thread != NULL && zathura_renderer_recolor_hue_enabled(zathura->sync.render_thread) != bool_value) {
zathura->global.recolor_keep_hue = bool_value; zathura_renderer_enable_recolor_hue(zathura->sync.render_thread, bool_value);
render_all(zathura); render_all(zathura);
} }
} }
......
...@@ -57,9 +57,13 @@ cb_color_change(girara_session_t* session, const char* name, ...@@ -57,9 +57,13 @@ cb_color_change(girara_session_t* session, const char* name,
} else if (g_strcmp0(name, "highlight-active-color") == 0) { } else if (g_strcmp0(name, "highlight-active-color") == 0) {
gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color_active)); gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color_active));
} else if (g_strcmp0(name, "recolor-darkcolor") == 0) { } else if (g_strcmp0(name, "recolor-darkcolor") == 0) {
gdk_color_parse(string_value, &(zathura->ui.colors.recolor_dark_color)); if (zathura->sync.render_thread != NULL) {
zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, NULL, string_value);
}
} else if (g_strcmp0(name, "recolor-lightcolor") == 0) { } else if (g_strcmp0(name, "recolor-lightcolor") == 0) {
gdk_color_parse(string_value, &(zathura->ui.colors.recolor_light_color)); if (zathura->sync.render_thread != NULL) {
zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread, string_value, NULL);
}
} else if (g_strcmp0(name, "render-loading-bg") == 0) { } else if (g_strcmp0(name, "render-loading-bg") == 0) {
gdk_color_parse(string_value, &(zathura->ui.colors.render_loading_bg)); gdk_color_parse(string_value, &(zathura->ui.colors.render_loading_bg));
} else if (g_strcmp0(name, "render-loading-fg") == 0) { } else if (g_strcmp0(name, "render-loading-fg") == 0) {
...@@ -168,10 +172,8 @@ config_load_default(zathura_t* zathura) ...@@ -168,10 +172,8 @@ config_load_default(zathura_t* zathura)
int_value = 2000; int_value = 2000;
girara_setting_add(gsession, "jumplist-size", &int_value, INT, false, _("Number of positions to remember in the jumplist"), cb_jumplist_change, NULL); girara_setting_add(gsession, "jumplist-size", &int_value, INT, false, _("Number of positions to remember in the jumplist"), cb_jumplist_change, NULL);
girara_setting_add(gsession, "recolor-darkcolor", NULL, STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL); girara_setting_add(gsession, "recolor-darkcolor", "#FFFFFF", STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
girara_setting_set(gsession, "recolor-darkcolor", "#FFFFFF"); girara_setting_add(gsession, "recolor-lightcolor", "#000000", STRING, false, _("Recoloring (light color)"), cb_color_change, NULL);
girara_setting_add(gsession, "recolor-lightcolor", NULL, STRING, false, _("Recoloring (light color)"), cb_color_change, NULL);
girara_setting_set(gsession, "recolor-lightcolor", "#000000");
girara_setting_add(gsession, "highlight-color", NULL, STRING, false, _("Color for highlighting"), cb_color_change, 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_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_add(gsession, "highlight-active-color", NULL, STRING, false, _("Color for highlighting (active)"), cb_color_change, NULL);
......
...@@ -466,8 +466,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) ...@@ -466,8 +466,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
} }
} else { } else {
/* set background color */ /* set background color */
if (priv->zathura->global.recolor == true) { if (zathura_renderer_recolor_enabled(priv->zathura->sync.render_thread) == true) {
GdkColor color = priv->zathura->ui.colors.recolor_light_color; GdkColor color;
zathura_renderer_get_recolor_colors(priv->zathura->sync.render_thread, &color, NULL);
cairo_set_source_rgb(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0); cairo_set_source_rgb(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0);
} else { } else {
GdkColor color = priv->zathura->ui.colors.render_loading_bg; GdkColor color = priv->zathura->ui.colors.render_loading_bg;
...@@ -481,8 +482,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo) ...@@ -481,8 +482,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
/* write text */ /* write text */
if (render_loading == true) { if (render_loading == true) {
if (priv->zathura->global.recolor == true) { if (zathura_renderer_recolor_enabled(priv->zathura->sync.render_thread) == true) {
GdkColor color = priv->zathura->ui.colors.recolor_dark_color; GdkColor color;
zathura_renderer_get_recolor_colors(priv->zathura->sync.render_thread, NULL, &color);
cairo_set_source_rgb(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0); cairo_set_source_rgb(cairo, color.red/65535.0, color.green/65535.0, color.blue/65535.0);
} else { } else {
GdkColor color = priv->zathura->ui.colors.render_loading_fg; GdkColor color = priv->zathura->ui.colors.render_loading_fg;
......
...@@ -25,7 +25,7 @@ static void zathura_render_request_finalize(GObject* object); ...@@ -25,7 +25,7 @@ static void zathura_render_request_finalize(GObject* object);
static void render_job(void* data, void* user_data); static void render_job(void* data, void* user_data);
static bool render(ZathuraRenderRequest* request, ZathuraRenderer* renderer); static bool render(ZathuraRenderRequest* request, ZathuraRenderer* renderer);
static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data); static gint render_thread_sort(gconstpointer a, gconstpointer b, gpointer data);
static void color2double(GdkColor* col, double* v); static void color2double(const GdkColor* col, double* v);
/* private data for ZathuraRenderer */ /* private data for ZathuraRenderer */
...@@ -40,7 +40,9 @@ typedef struct private_s { ...@@ -40,7 +40,9 @@ typedef struct private_s {
bool hue; bool hue;
double light[3]; double light[3];
GdkColor light_gdk;
double dark[3]; double dark[3];
GdkColor dark_gdk;
} recolor; } recolor;
} private_t; } private_t;
...@@ -69,8 +71,6 @@ zathura_renderer_class_init(ZathuraRendererClass* class) ...@@ -69,8 +71,6 @@ zathura_renderer_class_init(ZathuraRendererClass* class)
/* overwrite methods */ /* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class); GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = zathura_renderer_finalize; object_class->finalize = zathura_renderer_finalize;
// object_class->set_property = zathura_page_widget_set_property;
// object_class->get_property = zathura_page_widget_get_property;
} }
static void static void
...@@ -84,8 +84,8 @@ zathura_renderer_init(ZathuraRenderer* renderer) ...@@ -84,8 +84,8 @@ zathura_renderer_init(ZathuraRenderer* renderer)
priv->recolor.enabled = false; priv->recolor.enabled = false;
priv->recolor.hue = true; priv->recolor.hue = true;
priv->recolor.light[0] = priv->recolor.light[1] = priv->recolor.light[2] = 1;
priv->recolor.dark[0] = priv->recolor.dark[1] = priv->recolor.dark[2] = 1; zathura_renderer_set_recolor_colors_str(renderer, "#000000", "#FFFFFF");
} }
ZathuraRenderer* ZathuraRenderer*
...@@ -127,8 +127,6 @@ zathura_render_request_class_init(ZathuraRenderRequestClass* class) ...@@ -127,8 +127,6 @@ zathura_render_request_class_init(ZathuraRenderRequestClass* class)
/* overwrite methods */ /* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class); GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = zathura_render_request_finalize; object_class->finalize = zathura_render_request_finalize;
// object_class->set_property = zathura_page_widget_set_property;
// object_class->get_property = zathura_page_widget_get_property;
request_signals[REQUEST_COMPLETED] = g_signal_new("completed", request_signals[REQUEST_COMPLETED] = g_signal_new("completed",
ZATHURA_TYPE_RENDER_REQUEST, ZATHURA_TYPE_RENDER_REQUEST,
...@@ -216,15 +214,64 @@ zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, bool enable) ...@@ -216,15 +214,64 @@ zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, bool enable)
GET_PRIVATE(renderer)->recolor.hue = enable; GET_PRIVATE(renderer)->recolor.hue = enable;
} }
void zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer, void
zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer,
const GdkColor* light, const GdkColor* dark)
{
g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
private_t* priv = GET_PRIVATE(renderer);
if (light != NULL) {
priv->recolor.light_gdk.red = light->red;
priv->recolor.light_gdk.blue = light->blue;
priv->recolor.light_gdk.green = light->green;
color2double(light, priv->recolor.light);
}
if (dark != NULL) {
priv->recolor.dark_gdk.red = dark->red;
priv->recolor.dark_gdk.blue = dark->blue;
priv->recolor.dark_gdk.green = dark->green;
color2double(dark, priv->recolor.dark);
}
}
void
zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer,
const char* light, const char* dark)
{
g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
if (dark != NULL) {
GdkColor color;
gdk_color_parse(dark, &color);
zathura_renderer_set_recolor_colors(renderer, NULL, &color);
}
if (light != NULL) {
GdkColor color;
gdk_color_parse(light, &color);
zathura_renderer_set_recolor_colors(renderer, &color, NULL);
}
}
void
zathura_renderer_get_recolor_colors(ZathuraRenderer* renderer,
GdkColor* light, GdkColor* dark) GdkColor* light, GdkColor* dark)
{ {
g_return_if_fail(ZATHURA_IS_RENDERER(renderer)); g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
g_return_if_fail(light != NULL && dark != NULL);
private_t* priv = GET_PRIVATE(renderer); private_t* priv = GET_PRIVATE(renderer);
if (light != NULL) {
light->red = priv->recolor.light_gdk.red;
light->blue = priv->recolor.light_gdk.blue;
light->green = priv->recolor.light_gdk.green;
color2double(light, priv->recolor.light); color2double(light, priv->recolor.light);
}
if (dark != NULL) {
dark->red = priv->recolor.dark_gdk.red;
dark->blue = priv->recolor.dark_gdk.blue;
dark->green = priv->recolor.dark_gdk.green;
color2double(dark, priv->recolor.dark); color2double(dark, priv->recolor.dark);
}
} }
void void
...@@ -307,7 +354,7 @@ render_job(void* data, void* user_data) ...@@ -307,7 +354,7 @@ render_job(void* data, void* user_data)
static void static void
color2double(GdkColor* col, double* v) color2double(const GdkColor* col, double* v)
{ {
v[0] = (double) col->red / 65535.; v[0] = (double) col->red / 65535.;
v[1] = (double) col->green / 65535.; v[1] = (double) col->green / 65535.;
...@@ -525,7 +572,7 @@ render_all(zathura_t* zathura) ...@@ -525,7 +572,7 @@ render_all(zathura_t* zathura)
} }
static gint static gint
render_thread_sort(gconstpointer a, gconstpointer b, gpointer data) render_thread_sort(gconstpointer a, gconstpointer b, gpointer UNUSED(data))
{ {
if (a == NULL || b == NULL) { if (a == NULL || b == NULL) {
return 0; return 0;
......
...@@ -52,6 +52,10 @@ bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer); ...@@ -52,6 +52,10 @@ bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer);
void zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, void zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer,
bool enable); bool enable);
void zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer, void zathura_renderer_set_recolor_colors(ZathuraRenderer* renderer,
const GdkColor* light, const GdkColor* dark);
void zathura_renderer_set_recolor_colors_str(ZathuraRenderer* renderer,
const char* light, const char* dark);
void zathura_renderer_get_recolor_colors(ZathuraRenderer* renderer,
GdkColor* light, GdkColor* dark); GdkColor* light, GdkColor* dark);
void zathura_renderer_stop(ZathuraRenderer* renderer); void zathura_renderer_stop(ZathuraRenderer* renderer);
......
...@@ -68,7 +68,6 @@ zathura_create(void) ...@@ -68,7 +68,6 @@ zathura_create(void)
zathura_t* zathura = g_malloc0(sizeof(zathura_t)); zathura_t* zathura = g_malloc0(sizeof(zathura_t));
/* global settings */ /* global settings */
zathura->global.recolor = false;
zathura->global.update_page_number = true; zathura->global.update_page_number = true;
zathura->global.search_direction = FORWARD; zathura->global.search_direction = FORWARD;
...@@ -718,6 +717,15 @@ document_open(zathura_t* zathura, const char* path, const char* password, ...@@ -718,6 +717,15 @@ document_open(zathura_t* zathura, const char* path, const char* password,
goto error_free; goto error_free;
} }
char* recolor_dark = NULL;
char* recolor_light = NULL;
girara_setting_get(zathura->ui.session, "recolor-darkcolor", &recolor_dark);
girara_setting_get(zathura->ui.session, "recolor-lightcolor", &recolor_light);
zathura_renderer_set_recolor_colors_str(zathura->sync.render_thread,
recolor_light, recolor_dark);
g_free(recolor_dark);
g_free(recolor_light);
/* create blank pages */ /* create blank pages */
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*)); zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
if (zathura->pages == NULL) { if (zathura->pages == NULL) {
......
...@@ -56,8 +56,6 @@ struct zathura_s ...@@ -56,8 +56,6 @@ struct zathura_s
struct struct
{ {
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; /**< Color for highlighting */
GdkColor highlight_color_active; /** Color for highlighting */ GdkColor highlight_color_active; /** Color for highlighting */
GdkColor render_loading_bg; /**< Background color for render "Loading..." */ GdkColor render_loading_bg; /**< Background color for render "Loading..." */
...@@ -102,8 +100,6 @@ struct zathura_s ...@@ -102,8 +100,6 @@ struct zathura_s
struct struct
{ {
bool recolor_keep_hue; /**< Keep hue when recoloring */
bool recolor; /**< Recoloring mode switch */
bool update_page_number; /**< Update current page number */ bool update_page_number; /**< Update current page number */
int search_direction; /**< Current search direction (FORWARD or BACKWARD) */ int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
girara_list_t* marks; /**< Marker */ girara_list_t* marks; /**< Marker */
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment