Looking at the source code, it looks like the WindowControls are not themable by CSS, as they use GtkImage widgets with hardcoded icon names, and as far as i understand GtkImages will override whatever CSS icon is assigned (should have used a simple widget like gtk_builtin_icon instead for this to work).
Looks like you have to:
create a new icon theme, let’s say “SuperAdwaita”, by copying the folders structure and index.theme from the Adwaita one.
in the index.theme file, inherit from Adwaita:
[Icon Theme]
Name=SuperAdwaita
Inherits=Adwaita
just add the new “window-close-symbolic” icons in appropriate subfolders, no need to add any other icons.
set “SuperAdwaita” as your icon theme in the settings.
Side notes:
in CSS3 “image” is a typedef, for getting an image reference I think you should use “url” instead: -gtk-icon-source: url("close.png");
but anyway themed symbolic icons (i.e. -gtk-icontheme) should be preferred, because they automatically recolor on dark/light themes.
I’ve tried your solution and it worked - but the icon wasn’t found.
My guess is that the icon_name is invalid, here’s how I set it:
gtk::gio::resources_register_include!("icons.gresource").unwrap();
// [...]
let x = gtk::Button::builder().css_name("tab-close").build();
x.set_icon_name("close");
I’m curious how the gresource finds the name for the file icon, does it take everything before the .[extension]? Maybe I’m missing an attribute for the icon name, although looking at the GTK icons docs, my code seems about right.
Maybe the last 2 parts of the gresource prefix have a connection to this? Since I haven’t seen them be used anywhere else in the icons docs <gresource prefix="/org/a/b/icons/symbolic/ui">
The icon seems to be set correctly in the GTK inspector, so I have no clue what went wrong either
These subpaths are defined in the default index.theme which is embedded in the libgtk library.
Well, now that I look at it, indeed this “symbolic/ui” subpath isn’t listed there… (I took the subpath based on my local Adwaita icon theme, that may be incorrect…)
When I look into the libgtk resouces, there are actually multiple instances of the window-close-symbolic icons, in scalable and raster (png) formats. I suspect that when a raster is present, gtk will use it, to avoid expensive SVG conversions. But exactly which resolution will depend on the scaling factor, I think (by 1:1 the 16x16 should be the one used I suppose)
One last question - how can I set the icon names for the WindowControls widget?
I suppose I have to create a new WindowControls and replace the existing one, then loop through each button and set their icons, but if I recall correctly creating another WindowControls wasn’t the correct way of doing it.
Assuming the close icon is already registered in the application, I tried the -gtk-icon-source CSS property on .close class, yet nothing changed.
Regarding CSS, it’s not possible to use -gtk-icon-source to change the icon. Only widget that call gtk_css_style_snapshot_icon() in their snapshot() can support that, which is not the case of Gtk.Image.
Looping through the WindowControls and calling set_icon_name() is a possible solution.
Or create your own widget (a GtkBox respecting the decoration-layout) with custom buttons.