GNOME Bugzilla – Bug 708583
StyleContext: removing or adding a provider doesn't invalidate the style context
Last modified: 2013-10-05 12:03:33 UTC
When calling gtk_style_context_add_provider() or gtk_style_context_remove_provider(), the style context is not invalided. I.e. gtk_style_context_invalidate() is not called. The gtk_style_context_invalidate() documentation says: > If you're using a GtkStyleContext returned from > gtk_widget_get_style_context(), you do not need to call this yourself. It is the case in GtkSourceView (where the bug occurs), the StyleContext comes from gtk_widget_get_style_context(). So either the documentation must be fixed, or the style context must be invalidated when a provider is added or removed.
Yeah, this probably needs doc fixes. Style contexts returned from gtk_widget_get_style_context() are invalidated lazily. So the invalidate signal (and in turn the widget's style_updated() signal are only emitted once the frame clock runs and the style + layout + draw cycle is executed.
Fwiw, other style contexts should be invalidated immediately since 3.6 or so when style providers got their changed signal without the need to call gtk_style_context_invalidate().
gtk_style_context_get_color() is called just after changing the provider, in the same main loop cycle. But the returned color is wrong. When calling gtk_style_context_invalidate() after changing the provider, the returned color is good. So it's maybe a bug in the lazy invalidation.
Lazy means it's not updated immediately. It will return the color used in the last drawing cycle, even if you explicitly override it. That's by design.
Okay. I thought the value should be updated when we request it. So the invalidate() function is useful when we don't want to wait the next drawing cycle.
Ideally we'd want that, but there were a bunch of reasons why that was a bad idea (too many GTK apps requesting stuff immediately to make lazy invalidation not worth it) so that I did it this way. It's one of the things we might want to look at again for 4.0 (because that's how Javascript Style objects work) after we've fixed all the stupid GTK widgets.
Created attachment 255985 [details] [review] Improve doc of gtk_style_context_invalidate()
I've deprecated gtk_style_context_invalidate() now. It shouldn't be needed in regular code as the style context should invalidate itself properly whenever it gets modified. Attachment 255985 [details] pushed as ab112a2 - Improve doc of gtk_style_context_invalidate()