Skip to content

Commit

Permalink
Cache app icons
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Holecek <hluk@email.cz>
  • Loading branch information
hluk committed Aug 3, 2019
1 parent 6c6457a commit c502048
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/gui/iconfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,17 +509,31 @@ class AppIconEngine final : public BaseIconEngine

QPixmap doCreatePixmap(QSize size, QIcon::Mode, QIcon::State, QPainter *) override
{
// If copyq-normal icon exist in theme, omit changing color.
const bool useColoredIcon = !hasNormalIcon();
const auto sessionColor = useColoredIcon ? sessionIconColor() : QColor();

const auto cacheKey = QString("app:%1|%2|%3x%4")
.arg(m_iconType)
.arg(sessionColor.name())
.arg(size.width())
.arg(size.height());

{
QPixmap pixmap;
if ( QPixmapCache::find(cacheKey, &pixmap) )
return pixmap;
}

const bool running = m_iconType == AppIconRunning;
const auto suffix = running ? QLatin1String("-busy") : QLatin1String("");

auto pix = appPixmap(suffix, size);

// If copyq-normal icon exist in theme, omit changing color.
if ( !hasNormalIcon() ) {
const auto sessionColor = sessionIconColor();
if ( sessionColor.isValid() )
replaceColor(&pix, suffix, sessionColor);
}
if ( sessionColor.isValid() )
replaceColor(&pix, suffix, sessionColor);

QPixmapCache::insert(cacheKey, pix);

return pix;
}
Expand Down

0 comments on commit c502048

Please sign in to comment.