MouseMap: save & restore GtkStyleContext to prevent hogging the CPU

Since Gtk 3.18 passing a state other than the current state isn't
recommended and can apparently lead to hogging the CPU due to triggering
a loop: requesting style context triggers pixel cache refresh, which triggers
do_draw, which requests the style context that triggers the pixel cache again,
et cetera.

For background, see https://bugzilla.gnome.org/show_bug.cgi?id=760462
and the linked blog post https://blogs.gnome.org/mclasen/2015/11/20/a-gtk-update/.
Note that the advice of using the gtk_render_* API doesn't work for the
MouseMap, so we have to use the suggested workaround.

Fixes #133.
This commit is contained in:
Jente Hidskes
2017-08-17 12:55:02 +02:00
committed by Peter Hutterer
parent 424a66ae48
commit ccb9f83c10

View File

@@ -390,7 +390,10 @@ class MouseMap(Gtk.Container):
# Draws the SVG into the Cairo context. If there is an element to be
# highlighted, it will do as such in a separate surface which will be
# used as a mask over the device surface.
color = self.get_style_context().get_color(Gtk.StateFlags.LINK)
style_context = self.get_style_context()
style_context.save()
color = style_context.get_color(Gtk.StateFlags.LINK)
style_context.restore()
cr.set_source_rgba(color.red, color.green, color.blue, 0.5)
self._handle.render_cairo_sub(cr, id="#Device")