Move recolor state to the renderer

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2013-08-24 00:07:32 +02:00
parent 10115db62f
commit b02d3d4b8f
7 changed files with 95 additions and 36 deletions

View File

@ -488,11 +488,11 @@ cb_setting_recolor_change(girara_session_t* session, const char* name,
g_return_if_fail(name != NULL);
zathura_t* zathura = session->global.data;
bool bool_value = *((bool*) value);
const bool bool_value = *((bool*) value);
if (zathura->global.recolor != bool_value) {
zathura->global.recolor = bool_value;
render_all(zathura);
if (zathura->sync.render_thread != NULL && zathura_renderer_recolor_enabled(zathura->sync.render_thread) != bool_value) {
zathura_renderer_enable_recolor(zathura->sync.render_thread, bool_value);
render_all(zathura);
}
}
@ -506,11 +506,11 @@ cb_setting_recolor_keep_hue_change(girara_session_t* session, const char* name,
g_return_if_fail(name != NULL);
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) {
zathura->global.recolor_keep_hue = bool_value;
render_all(zathura);
if (zathura->sync.render_thread != NULL && zathura_renderer_recolor_hue_enabled(zathura->sync.render_thread) != bool_value) {
zathura_renderer_enable_recolor_hue(zathura->sync.render_thread, bool_value);
render_all(zathura);
}
}

View File

@ -57,9 +57,13 @@ cb_color_change(girara_session_t* session, const char* name,
} else if (g_strcmp0(name, "highlight-active-color") == 0) {
gdk_color_parse(string_value, &(zathura->ui.colors.highlight_color_active));
} 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) {
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) {
gdk_color_parse(string_value, &(zathura->ui.colors.render_loading_bg));
} else if (g_strcmp0(name, "render-loading-fg") == 0) {
@ -168,10 +172,8 @@ config_load_default(zathura_t* zathura)
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, "recolor-darkcolor", NULL, STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
girara_setting_set(gsession, "recolor-darkcolor", "#FFFFFF");
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, "recolor-darkcolor", "#FFFFFF", STRING, false, _("Recoloring (dark color)"), cb_color_change, NULL);
girara_setting_add(gsession, "recolor-lightcolor", "#000000", STRING, false, _("Recoloring (light color)"), 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_add(gsession, "highlight-active-color", NULL, STRING, false, _("Color for highlighting (active)"), cb_color_change, NULL);

View File

@ -466,8 +466,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
}
} else {
/* set background color */
if (priv->zathura->global.recolor == true) {
GdkColor color = priv->zathura->ui.colors.recolor_light_color;
if (zathura_renderer_recolor_enabled(priv->zathura->sync.render_thread) == true) {
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);
} else {
GdkColor color = priv->zathura->ui.colors.render_loading_bg;
@ -481,8 +482,9 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
/* write text */
if (render_loading == true) {
if (priv->zathura->global.recolor == true) {
GdkColor color = priv->zathura->ui.colors.recolor_dark_color;
if (zathura_renderer_recolor_enabled(priv->zathura->sync.render_thread) == true) {
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);
} else {
GdkColor color = priv->zathura->ui.colors.render_loading_fg;

View File

@ -25,7 +25,7 @@ static void zathura_render_request_finalize(GObject* object);
static void render_job(void* data, void* user_data);
static bool render(ZathuraRenderRequest* request, ZathuraRenderer* renderer);
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 */
@ -40,7 +40,9 @@ typedef struct private_s {
bool hue;
double light[3];
GdkColor light_gdk;
double dark[3];
GdkColor dark_gdk;
} recolor;
} private_t;
@ -69,8 +71,6 @@ zathura_renderer_class_init(ZathuraRendererClass* class)
/* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
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
@ -84,8 +84,8 @@ zathura_renderer_init(ZathuraRenderer* renderer)
priv->recolor.enabled = false;
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*
@ -127,8 +127,6 @@ zathura_render_request_class_init(ZathuraRenderRequestClass* class)
/* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
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",
ZATHURA_TYPE_RENDER_REQUEST,
@ -216,15 +214,64 @@ zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer, bool 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)
{
g_return_if_fail(ZATHURA_IS_RENDERER(renderer));
g_return_if_fail(light != NULL && dark != NULL);
private_t* priv = GET_PRIVATE(renderer);
color2double(light, priv->recolor.light);
color2double(dark, priv->recolor.dark);
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);
}
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);
}
}
void
@ -307,7 +354,7 @@ render_job(void* data, void* user_data)
static void
color2double(GdkColor* col, double* v)
color2double(const GdkColor* col, double* v)
{
v[0] = (double) col->red / 65535.;
v[1] = (double) col->green / 65535.;
@ -525,7 +572,7 @@ render_all(zathura_t* zathura)
}
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) {
return 0;

View File

@ -52,6 +52,10 @@ bool zathura_renderer_recolor_hue_enabled(ZathuraRenderer* renderer);
void zathura_renderer_enable_recolor_hue(ZathuraRenderer* renderer,
bool enable);
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);
void zathura_renderer_stop(ZathuraRenderer* renderer);

View File

@ -68,7 +68,6 @@ zathura_create(void)
zathura_t* zathura = g_malloc0(sizeof(zathura_t));
/* global settings */
zathura->global.recolor = false;
zathura->global.update_page_number = true;
zathura->global.search_direction = FORWARD;
@ -718,6 +717,15 @@ document_open(zathura_t* zathura, const char* path, const char* password,
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 */
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
if (zathura->pages == NULL) {

View File

@ -56,8 +56,6 @@ struct zathura_s
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_active; /** Color for highlighting */
GdkColor render_loading_bg; /**< Background color for render "Loading..." */
@ -102,8 +100,6 @@ struct zathura_s
struct
{
bool recolor_keep_hue; /**< Keep hue when recoloring */
bool recolor; /**< Recoloring mode switch */
bool update_page_number; /**< Update current page number */
int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
girara_list_t* marks; /**< Marker */