From ccb9f83c1095df58ce7100e8b0c1d2c3d164f4fa Mon Sep 17 00:00:00 2001 From: Jente Hidskes Date: Thu, 17 Aug 2017 12:55:02 +0200 Subject: [PATCH] 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. --- piper/mousemap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/piper/mousemap.py b/piper/mousemap.py index a3ebcbf..0d8fbb5 100644 --- a/piper/mousemap.py +++ b/piper/mousemap.py @@ -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")