Recoloring GtkPicture SVGs on the fly

I’m looking at the gnome-control-center Wacom panel which displays a stylus via a GtkPicture, from an SVG in the gresources. The goal is to hlighlight the active stylus and to do so I need to change the fill color to whatever the palette says.

But I can’t figure out how to do this, short of duplicating all SVGs and swapping them out - but this seems wrong.

Loading a CSS provider lets me change background colour etc but there’s no fill support and I can’t figure out how to make -gtk-recolor work (if it even does for a GtkPicture? does it need modifications to the SVG?). I had some success using a css filter: but that doesn’t stick to the palette.

Swapping to a GtkImage doesn’t seem the solution either since that apparently requires a square area, messing up the spacing.

Any suggestions on how to achieve this? Thanks.

A partial workaround is available in GTK4’s load_symbolic_svg which uses xi:include with the base64-encoded data of the original svg and an extra <style> tag in that svg.

It’s not exactly on-the-fly but it makes it possible to create a GdkPixbuf from the so-styled SVG which can then be used to create a GdkTexture to pass into gtk_picture_set_paintable().

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.