Skip to content


Save/restore context when getting colors for a different state
Browse files Browse the repository at this point in the history
Getting colors for a state different from the current state of the
corresponding widget without saving the context might trigger an
invalidation and a redraw. Because this was happening from the draw
function this resulted in a redraw loop and constant high CPU usage.

This could be triggered by selecting text or searching.

inspired by:
  • Loading branch information
raveit65 committed Mar 19, 2018
1 parent 56e08ae commit 6217a89
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libdocument/ev-document-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ ev_document_misc_paint_one_page (cairo_t *cr,
GtkStateFlags state = gtk_widget_get_state_flags (widget);
GdkRGBA fg, bg, shade_bg;

gtk_style_context_save (context);
gtk_style_context_get_background_color (context, state, &bg);
gtk_style_context_get_color (context, state, &fg);
gtk_style_context_get_color (context, state, &shade_bg);
gtk_style_context_restore (context);
shade_bg.alpha *= 0.5;

gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);
Expand Down
7 changes: 7 additions & 0 deletions libview/ev-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -3974,7 +3974,9 @@ get_cursor_color (GtkStyleContext *context,

gdk_color_free (style_color);
} else {
gtk_style_context_save (context);
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
gtk_style_context_restore (context);

Expand Down Expand Up @@ -5622,7 +5624,9 @@ draw_rubberband (EvView *view,
GdkRGBA color;

context = gtk_widget_get_style_context (GTK_WIDGET (view));
gtk_style_context_save (context);
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color);
gtk_style_context_restore (context);

cairo_save (cr);

Expand Down Expand Up @@ -5811,12 +5815,15 @@ _ev_view_get_selection_colors (EvView *view,

state = gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE;
context = gtk_widget_get_style_context (widget);
gtk_style_context_save (context);

if (bg_color)
gtk_style_context_get_background_color (context, state, bg_color);

if (fg_color)
gtk_style_context_get_color (context, state, fg_color);

gtk_style_context_restore (context);

static void
Expand Down

0 comments on commit 6217a89

Please sign in to comment.