After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756524 - Storm of "draw" callbacks when using gtk_style_context_get with GTK_STATE_FLAG_PRELIGHT
Storm of "draw" callbacks when using gtk_style_context_get with GTK_STATE_FLA...
Status: RESOLVED NOTABUG
Product: gtk+
Classification: Platform
Component: Widget: Other
3.18.x
Other Linux
: Normal critical
: ---
Assigned To: gtk-bugs
gtk-bugs
: 756526 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-10-13 18:36 UTC by Ali
Modified: 2015-10-17 08:35 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Simple code to illustrate the bug (10.00 KB, application/gzip)
2015-10-13 18:36 UTC, Ali
Details

Description Ali 2015-10-13 18:36:31 UTC
Created attachment 313213 [details]
Simple code to illustrate the bug

If I use gtk_style_context_get on the widget style context with GTK_STATE_FLAG_PRELIGHT as flag inside the draw callback, I get a storm of callbacks which make the application. 

I have included a simple test-widget to illustrate the bug. The bug is present in gtk 3.18.*, but not in gtk 3.16.* or gtk 3.14.*
Comment 1 Benjamin Otte (Company) 2015-10-13 21:58:42 UTC
Indeed.

If you query a state different than the current one (the one returned via gtk_style_context_get_state()) on an unsaved style context, you cause a style update to the one you queried and later on back to the style context's state. Both of which cause a style_upated signal to be emitted which probably causes a queue_draw()).

The quick solution to that problem is to use gtk_style_context_save() before and gtk_style_context_restore() after querying the context.

The proper solution is to gtk_widget_set_state_flags() the PRELIGHT state in the enter event and unset it in the leave event and then use gtk_style_context_get_state() in the draw() handler.
Comment 2 Ali 2015-10-14 05:17:53 UTC
Thanks for the quich answer. 

Why this was not the default behaviour in gtk3.16.* and gtk3.14.*. I mean, one cannot expect that getting a widget style information can cause a style update.
Comment 3 Matthias Clasen 2015-10-16 02:44:09 UTC
*** Bug 756526 has been marked as a duplicate of this bug. ***
Comment 4 Matthias Clasen 2015-10-17 03:36:19 UTC
I don't think there's anything to fix here.
Comment 5 Ali 2015-10-17 08:35:28 UTC
Maybe it is a good idea to document it somewhere in the API documentation. As it is difficult to expect that getting style information will lead to a redraw.