Bug 502273

Summary: KIconLoader prefers PNG icons over SVG icons
Product: [Frameworks and Libraries] frameworks-kiconthemes Reporter: pallaswept <pallaswept>
Component: generalAssignee: Christoph Feck <cfeck>
Status: RESOLVED FIXED    
Severity: normal CC: akselmo, kde, kdedev, kdelibs-bugs-null, nate
Priority: NOR    
Version First Reported In: 6.12.0   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.18
Sentry Crash Report:

Description pallaswept 2025-04-01 12:18:23 UTC
SUMMARY
SVG icons are not used, if the theme contains PNG icons for that application.

STEPS TO REPRODUCE
1. Install an application with SVG and PNG icons
2. Change the SVG icon to something visually distinct (eg use another app's icon) so you can tell if it is being used at all
3. Restart plasma to apply the change

OBSERVED RESULT
SVG icon is not being used

EXPECTED RESULT
SVG icon is used

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20250329
KDE Plasma Version: 6.3.3
KDE Frameworks Version: 6.12.0
Qt Version: 6.8.2
Kernel Version: 6.13.8-1-default (64-bit)
Graphics Platform: Wayland
Processors: 24 × AMD Ryzen 9 5900X 12-Core Processor
Memory: 31.2 GiB of RAM
Graphics Processor: NVIDIA GeForce RTX 3090/PCIe/SSE2

ADDITIONAL INFORMATION
I really can't tell if this is a bug or a design flaw. I'm not even sure if it's a plasma thing, a frameworks thing, a qt thing or an XDG thing... Possibly all of the above.

Reading the XDG icon theme spec, it says that applications should ship with a 48x48 PNG, and also that it will search PNG format first, and that it will stop the search on the first hit.

This suggest that XDG's intention is that DEs ignore scalable SVGs in favour of scaling PNGs. In which case, Plasma appears to be compliant.

But it also says that applications could install SVGs so that nicely scaling icons are available. Which conflicts with all the above. And I feel like Plasma would want to be using SVGs wherever possible.

It also says it scans by directory, before scanning by file extension, which it obviously does (because that allows icons in the home dir to override those in the root) but even an SVG in a prior directory (such as in ~/.local/share/icons) will not be used if a PNG is present even in the later directory (such as /usr/share/icons/). So, that doesn't quite add up, either.

So I don't know. Any advice would be most welcome, I am a bit puzzled as to how this is meant to work, but I'm pretty sure it's not working optimally at the moment. Seems weird to have all these apps shipping SVG icons that don't get used.

I've come across this in attempt to help a dev package an app, and we don't know what icons to package. We'd like to package PNG for compatibility with other DE, but we'd like the SVG icons to be used when they'd look nicer. 

This also effects that app's facility for users to provide a custom icon, since any PNGs in the package, will mean that they now need to generate multiple fixed-size PNGs when it would be nice to just let them drop a single SVG.

Thanks for your advice.
Comment 1 TraceyC 2025-04-01 18:13:38 UTC
So we can more easily reproduce and investigate this, can you give us an example of an application you have seen this with?
Also, can you be more specific about where you're looking at the icon? Is this in the apps menu, on the panel as a shortcut, in the task manager when the app is running, for example?

Thanks.
Comment 2 pallaswept 2025-04-02 00:01:01 UTC
Thank you Tracey!

> So we can more easily reproduce and investigate this, can you give us an
> example of an application you have seen this with?

To be very specific, I am mostly testing with CoolerControl: https://gitlab.com/coolercontrol/coolercontrol

But I did of course test this with other apps and it's the same for everything I tried. It will work with anything that has an SVG and PNG icons.

To select an example from my system, the foot terminal is handy because it only has SVG and a single PNG of 48x48px. I can reproduce by these steps:

- In /usr/share/icons/hicolor/
- Rename scalable/apps/foot.svg to foot.svg.0 
- Make a duplicate of scalable/apps/gimp.svg
- Rename it to foot.svg (now foot should have gimp's icon)
- Restart plasma
- Foot has foot's icon
- Rename 48x48/apps/foot.png to foot.png.0
- Restart plasma
- Foot has gimp's icon

> Also, can you be more specific about where you're looking at the icon? Is
> this in the apps menu, on the panel as a shortcut, in the task manager when
> the app is running, for example?

All of the above. Icons within the application are not effected, but those in Plasma are subject to this behaviour. The panel icon is configured to use a symbolic icon and only an SVG is created, so I don't observe the behaviour there, but earlier when the symbolic icon was not used, it used the normal icon, and the behaviour was the same in all of the above places.
Comment 3 Nate Graham 2025-04-02 15:11:29 UTC

*** This bug has been marked as a duplicate of bug 493034 ***
Comment 4 pallaswept 2025-04-02 15:24:21 UTC
Nate is this a dupe of that? It seems kinda different. I get the same icon everywhere, they get two different ones, they use absolute paths, I don't, they change the desktop file, I don't... Sorry if I'm mistaken about this.
Comment 5 Nate Graham 2025-04-03 15:57:48 UTC
Yeah my bad, not the same thing.
Comment 6 TraceyC 2025-04-03 17:30:38 UTC
I tested on git-master, focusing on firefox and pidgin, which have .svg and .png icons and was able to replicate the bug with the Breeze Dark icon theme

**Test of renaming the png with Firefox**
- Set the bottom panel to 48px, left panel is at 54px
- Icon theme was Tela Dark
- Renamed /u/s/icons/hicolor/48x48/apps/firefox.png to firefox.png.bak
- Copied /u/s/icons/hicolor/48x48/apps/vlc-xmas.png  to firefox.png
- Restarted Plasma

Result: The icon for Firefox showed the Firefox logo correctly - ok

- Set the global theme (which also sets the icon theme) to Breeze Dark
Result: on the 54px panel the VLC icon is shown instead of the svg Firefox icon - not ok

**Test of renaming the svg with pidgin**
- Renamed hicolor/scalable/apps/pidgin.svg to pidgin.svg.bak
- Copy hicolor/scalable/apps/mpv.svg to pidgin.svg
Expect: When pidgin's buddy list is open, the panel icon should be the mpv icon (svg)

Result: The pidgin png icon is shown in both panels - not ok
Comment 7 Nate Graham 2025-04-03 19:54:26 UTC
Icon loading priorities are in KIconLoader which lives in the kiconthemes framework; moving there.
Comment 8 pallaswept 2025-04-03 20:35:29 UTC
(In reply to TraceyC from comment #6)
> I tested on git-master, focusing on firefox and pidgin, which have .svg and
> .png icons and was able to replicate the bug with the Breeze Dark icon theme

Oh nice one Tracey, thank you!

I found it interesting that Tela did not suffer this, at first I thought maybe it was a hint of a workaround. I realised that Tela has a built-in firefox icon.

You showed me part of this I had not tested - It will prefer any icon from the current theme, over any icon from the fallback (hicolor) theme, ie
PNG(this theme)  >  SVG(this theme)  >  PNG(fallback theme)  >  SVG(fallback theme) 

Reading it again I can see that, once again, this matches the spec https://specifications.freedesktop.org/icon-theme-spec/latest/#icon_lookup

More and more, I feel like this is actually a case of KDE (or is it KF or Qt? I couldn't figure it out) being perfectly compliant with XDG's spec and the spec prefers PNG over SVG. As in, intentional, so not really a bug... Though I'm not sure it was actually the intended result, that SVG icons go un-used.

(In reply to Nate Graham from comment #7)
> Icon loading priorities are in KIconLoader which lives in the kiconthemes framework; moving there.

Thanks Nate!
PS sorry to bother you in both issues, I wasn't sure if you would actually get the message from this resolved issue, since I imagine there's a lot of 'noise' in those for you. I hope that wasn't too annoying.
Comment 9 Nate Graham 2025-04-04 12:26:34 UTC
Maybe a tiny bit, but by a freak coincidence I had accidentally deleted the email where you first complained that I did it wrong, so getting a second one in the other bug report actually saved me time since I didn't have to go dig around in the trash. :) 

I need to sit down with the icon spec docs again to confirm what you're saying, but it wouldn't surprise me at all if we're in a state that's "compliant, but not ideal".
Comment 10 pallaswept 2025-04-17 10:16:57 UTC
(In reply to Nate Graham from comment #9)
> email where you first complained that I did it wrong

Sorry Nate, I really didn't mean for it to come across like that. I think you do a bloody amazing job.
Comment 11 Nate Graham 2025-04-17 16:56:51 UTC
It's all right, it was a valid complaint! I really did do it wrong.
Comment 12 Akseli Lahtinen 2025-08-21 11:36:11 UTC
In KIconLoader::iconPath we have:
```
    QString path;
    if (group_or_size == KIconLoader::User) {
        path = d->locate(name + QLatin1String(".png"));
        if (path.isEmpty()) {
            path = d->locate(name + QLatin1String(".svgz"));
        }
        if (path.isEmpty()) {
            path = d->locate(name + QLatin1String(".svg"));
        }
        if (path.isEmpty()) {
            path = d->locate(name + QLatin1String(".xpm"));
        }
        return path;
    }
```

So it takes png first. Switching those around might resolve this bug, will try.

I'm curious though why it has been done this way, the git blame doesnt show that far back.
Comment 13 Akseli Lahtinen 2025-08-21 11:45:25 UTC
I made a branch for testing my theory https://invent.kde.org/frameworks/kiconthemes/-/commit/c3ed2be285401e263db0ec77e08472394f20258a

I haven't been able to repro the bug myself though
Comment 14 pallaswept 2025-08-21 11:58:42 UTC
(In reply to Akseli Lahtinen from comment #12)

Thanks Akseli!

> I'm curious though why it has been done this way, the git blame doesnt show that far back.

I suspect it's XDG compliance: https://specifications.freedesktop.org/icon-theme-spec/latest/#icon_lookup
Their pseudocode implementation specifically prefers PNG. To save you the time, one of the two examples:

    for extension in ("png", "svg", "xpm") {
      if exists directory/iconname.extension
        return directory/iconname.extension
    }

So it won't even consider svg unless there is no suitable png found. I seem to remember reading that xdg historically did it that way because svg could be too expensive.

Hope that's helpful.
Comment 15 Nate Graham 2025-08-22 19:45:11 UTC
Right, this doesn't seem to be a bug per se. The behavior may be undesirable today though. SVG icons are pretty well established throughout the ecosystem, not just in KDE.
Comment 16 Bug Janitor Service 2025-09-03 12:57:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kiconthemes/-/merge_requests/191
Comment 17 Nate Graham 2025-09-19 02:18:05 UTC
Fixed by Akseli Lahtinen with https://invent.kde.org/frameworks/kiconthemes/-/commit/4510bba2b31f9346e328ee262c5c42ef5170856c in Frameworks 6.18.