Gtk3 port theming

Matthew Brush mbrush at
Sun May 15 19:21:50 CEST 2016

On 2016-05-15 05:37 AM, flo.xfce at wrote:
> Hi all,
> in Landrys porting efforts of various panel plugins (and I have seen it
> in other applications, too) I came across code like this:
> css = g_strdup_printf("label { color: %s; }", gdk_rgba_to_string(color));
> css_provider = gtk_css_provider_new ();
> gtk_css_provider_load_from_data (css_provider, css, strlen(css), NULL);
> This looks really hacky to me, so my question: Is this the recommended
> way of setting widget styles independet of the user's theme? In Xfce
> there are multiple situation where we allow overwriting of the theme,
> for example the panel where you can set custom backgrounds. I'm just
> curious what would be the right way of achieving this.

If it didn't need to be dynamic, I'd say to use a separate 
application-specific CSS file.

Another way is to use stuff like `gtk_widget_override_color()` and 
friends (deprecated since 3.16)[0]. The docs for it also tell the 
non-deprecated alternative to use, but I don't know if it's saying to do 
like you showed above, or to write a whole custom GtkStyleProvider 
subclass and such. In any case, you might have more luck deciphering 
those docs than I.

In theory, it should be safe to use `gtk_widget_override_*` functions 
until GTK+ 4, but who knows if the GTK+ devs are going to just make it 
do nothing, breaking the apps in question without technically breaking 
any API/ABI guarantees, like they've done in the past[1].

Matthew Brush


More information about the Xfce4-dev mailing list