From 0cd8cc67c5f67ffb3171037ac7293d4967edf8da Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Sat, 27 Mar 2021 01:37:25 +0400 Subject: [PATCH] Scale window icon manually when getting from icon theme --- Telegram/SourceFiles/window/main_window.cpp | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index f4fbe21af5..5c148558a2 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -119,7 +119,43 @@ QIcon CreateOfficialIcon(Main::Session *session) { QIcon CreateIcon(Main::Session *session) { auto result = CreateOfficialIcon(session); #if defined Q_OS_UNIX && !defined Q_OS_MAC - return QIcon::fromTheme(Platform::GetIconName(), result); + const auto iconFromTheme = QIcon::fromTheme( + Platform::GetIconName(), + result); + + result = QIcon(); + + static const auto iconSizes = { + 16, + 22, + 32, + 48, + 64, + 128, + 256, + }; + + // Qt's standard QIconLoaderEngine sets availableSizes + // to XDG directories sizes, since svg icons are scalable, + // they could be only in one XDG folder (like 48x48) + // and Qt will set only a 48px icon to the window + // even though the icon could be scaled to other sizes. + // Thus, scale it manually to the most widespread sizes. + for (const auto iconSize : iconSizes) { + // We can't use QIcon::actualSize here + // since it works incorrectly with svg icon themes + const auto iconPixmap = iconFromTheme.pixmap(iconSize); + + const auto iconPixmapSize = iconPixmap.size() + / iconPixmap.devicePixelRatio(); + + // Not a svg icon, don't scale it + if (iconPixmapSize.width() != iconSize) { + return iconFromTheme; + } + + result.addPixmap(iconPixmap); + } #endif return result; }