How to recolor custom icons

For a reason that I can’t find uncover, I am unable to have my icons get recolored according to the system theme. This is how it looks like:

I checked if it was maybe the .svg that was missing a property or something, but Shortwave’s resize icon (copied for testing) doesn’t get recolored either in my app, even though it obviously does get recolored when testing Shortwave itself.

Searching through its repository, I don’t find yet what I am not doing that is necessary for icon recoloring.

The documentation mentions

Only symbolic icons loaded via their icon name through GtkIconTheme will be recolored using the style colors. Icons loaded directly from a file or a resource, or stored inside a location that does not match the icon theme directory structure, will not be automatically recolored by GTK.

Given that my icon file is a resource, what am I supposed to do differently? I see most apps include it as resources – I’m missing the point of that text, probably.

You can find my code (without the extra icon) on codeberg.org, as you probably want to take a look at the structure.

The icon recoloring works fine on my side, so check whether there’s any weird GTK theming going on on your side.

Note that you don’t have to use GtkIconTheme directly if the directory structure is correct. In your case, the icons are stored in icons/hicolor/scalable/actions/ instead of icons/scalable/actions/, so just shift the files around and update your gresource from:

<file preprocess="xml-stripblanks" alias="low-vision-symbolic.svg">icons/hicolor/scalable/actions/low-vision-symbolic.svg</file>

To:

<file preprocess="xml-stripblanks">icons/scalable/actions/low-vision-symbolic.svg</file>

Then after that, remove the Gtk.IconTheme code in window.js.

Thanks for looking into this.

I did have org.gtk.Gtk3theme.adw-gtk3-dark with flatpak installed (and not org.gtk.Gtk3theme.adw-gtk3 as I probably forgot to delete them both before). Removing it didn’t change anything, unfortunately. For the rest, I don’t have user themes active, nor icon themes on my system. My desktop’s OS is pretty vanilla (not even 3 months in use), I can’t recall installing themes and glancing at Gnome Tweaks I believe I’m not using non-defaults, but I might be wrong.

Anyhow, as it works on your device, I just tested on another (laptop) and there I do run into the exact same issue. This might not be much of a surprise, since I might have done exactly the same thing there (in the past) that prevents recoloring on my desktop. To be clear: you tried the Gamepad Mirror repository on your device, right? Using Gnome Builder? Installed as flatpak? For both my desktop and laptop, the answer to all questions is yes.

I also followed the instructions you provided to move the icons. The application is not able to find those icons and shows for both icons a placeholder icon instead. That does work for you?

Edit: I’m wrong, I forgot to remove the alias as you suggested. Now it works. Still wondering why it works as-is though on your device :thinking: Any clues (or pointing me to the documentation) are welcome to prevent this in the future.

I think building it with a newer runtime fixed it for me actually (I was too lazy to install the 48 runtime so I used master). Lots of stuff changed on the icon side, so I’m assuming it has to do with that.

That did raise an error at the start though, so I commented out some code to make it run :slight_smile:

Alrighty, thanks for helping out!

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