The following two lines of code load an image from an SVG file and set it as the icon for a window:
GdkPixbuf *icon = gdk_pixbuf_new_from_file("icon.svg", NULL);
gtk_window_set_icon(GTK_WINDOW(win), icon);
This SVG file contains, among other things, a rectangle defined like:
<rect
style="fill:#000000"
id="screen"
... />
I would like to dynamically change the color of this rect element after I’ve loaded the file, but before I set it as the icon for the window.
If I manually change the style attribute on this element of the file on disk just before I start my program, it has the desired effect. But I would like to have it set by the program itself, to match a colour it has chosen.
(This is so I can distinguish multiple similar windows in the window switcher menu, among other places)
I’ve now found the answer to this, from IRC (#gtk+ on irc.gnome.org), and reading GTK’s own source code.
The answer involves building a string that sets a stylesheet and uses XML’s xinclude to pull in the original image.