Skip to content

Commit

Permalink
Consider Qt's fallback search paths when finding icons (#259)
Browse files Browse the repository at this point in the history
Closes #258

Notes:

 * For respecting Freedesktop standards, Qt's fallback search paths are taken into account only after inherited paths.
 * Colorizing of SVG icons is ignored with Qt's fallback paths because it depends on icon themes, not on paths.
 * To test it, you could do something like this in a code:

```c++
    QIcon::setFallbackSearchPaths(QIcon::fallbackSearchPaths() << PARENT_DIR_OF_EXTRA_ICON);
    anAction->setIcon(QIcon::fromTheme(EXTRA_ICON_NAME));
```
  • Loading branch information
tsujan authored Oct 25, 2021
1 parent ecff783 commit 44038d7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/xdgiconloader/xdgiconloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,31 @@ QThemeIconInfo XdgIconLoader::findIconHelper(const QString &themeName,
}
}

if (info.entries.isEmpty()) {
// Also, consider Qt's fallback search paths (which are not defined by Freedesktop)
// if the icon is not found in any inherited theme
const auto fallbackPaths = QIcon::fallbackSearchPaths();
for (const auto &fallbackPath : fallbackPaths) {
const QString pngPath = fallbackPath + QLatin1Char('/') + iconName + pngext;
if (QFile::exists(pngPath)) {
PixmapEntry *iconEntry = new PixmapEntry;
QIconDirInfo dirInfo(fallbackPath);
iconEntry->dir = dirInfo;
iconEntry->filename = pngPath;
info.entries.prepend(iconEntry);
} else {
const QString svgPath = fallbackPath + QLatin1Char('/') + iconName + svgext;
if (gSupportsSvg && QFile::exists(svgPath)) {
ScalableEntry *iconEntry = new ScalableEntry;
QIconDirInfo dirInfo(fallbackPath);
iconEntry->dir = dirInfo;
iconEntry->filename = svgPath;
info.entries.append(iconEntry);
}
}
}
}

if (dashFallback && info.entries.isEmpty()) {
// If it's possible - find next fallback for the icon
const int indexOfDash = iconNameFallback.lastIndexOf(QLatin1Char('-'));
Expand Down

0 comments on commit 44038d7

Please sign in to comment.