Skip to content

Commit 4bb14f5

Browse files
raveit65raveit65
raveit65
authored andcommitted
Save/restore context when getting colors for a different state
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. https://bugzilla.gnome.org/show_bug.cgi?id=755442 inspired by: https://git.gnome.org/browse/evince/commit/?id=1987f04 linuxmint/xreader@e76a18d
1 parent 1f6278d commit 4bb14f5

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

libdocument/ev-document-misc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,11 @@ ev_document_misc_paint_one_page (cairo_t *cr,
161161
GtkStateFlags state = gtk_widget_get_state_flags (widget);
162162
GdkRGBA fg, bg, shade_bg;
163163

164+
gtk_style_context_save (context);
164165
gtk_style_context_get_background_color (context, state, &bg);
165166
gtk_style_context_get_color (context, state, &fg);
166167
gtk_style_context_get_color (context, state, &shade_bg);
168+
gtk_style_context_restore (context);
167169
shade_bg.alpha *= 0.5;
168170

169171
gdk_cairo_set_source_rgba (cr, highlight ? &fg : &shade_bg);

libview/ev-view.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3974,7 +3974,9 @@ get_cursor_color (GtkStyleContext *context,
39743974

39753975
gdk_color_free (style_color);
39763976
} else {
3977+
gtk_style_context_save (context);
39773978
gtk_style_context_get_color (context, GTK_STATE_FLAG_NORMAL, color);
3979+
gtk_style_context_restore (context);
39783980
}
39793981
}
39803982

@@ -5622,7 +5624,9 @@ draw_rubberband (EvView *view,
56225624
GdkRGBA color;
56235625

56245626
context = gtk_widget_get_style_context (GTK_WIDGET (view));
5627+
gtk_style_context_save (context);
56255628
gtk_style_context_get_background_color (context, GTK_STATE_FLAG_SELECTED, &color);
5629+
gtk_style_context_restore (context);
56265630

56275631
cairo_save (cr);
56285632

@@ -5811,12 +5815,15 @@ _ev_view_get_selection_colors (EvView *view,
58115815

58125816
state = gtk_widget_has_focus (widget) ? GTK_STATE_FLAG_SELECTED : GTK_STATE_FLAG_ACTIVE;
58135817
context = gtk_widget_get_style_context (widget);
5818+
gtk_style_context_save (context);
58145819

58155820
if (bg_color)
58165821
gtk_style_context_get_background_color (context, state, bg_color);
58175822

58185823
if (fg_color)
58195824
gtk_style_context_get_color (context, state, fg_color);
5825+
5826+
gtk_style_context_restore (context);
58205827
}
58215828

58225829
static void

0 commit comments

Comments
 (0)