Fallback to non-panel icon when tray counter is disabled

This commit is contained in:
Ilya Fedin 2020-02-20 05:13:15 +04:00 committed by John Preston
parent 02bc999bd5
commit db2aa7000a

View File

@ -44,7 +44,7 @@ int32 _trayIconCount = 0;
QImage _trayIconImageBack, _trayIconImage; QImage _trayIconImageBack, _trayIconImage;
QString _trayIconThemeName, _trayIconName; QString _trayIconThemeName, _trayIconName;
QString GetTrayIconName() { QString GetPanelIconName() {
const auto counter = Core::App().unreadBadge(); const auto counter = Core::App().unreadBadge();
const auto muted = Core::App().unreadBadgeMuted(); const auto muted = Core::App().unreadBadgeMuted();
@ -55,6 +55,24 @@ QString GetTrayIconName() {
: kPanelTrayIconName.utf16(); : kPanelTrayIconName.utf16();
} }
QString GetTrayIconName() {
const auto panelIconName = GetPanelIconName();
if (QIcon::hasThemeIcon(panelIconName)) {
return panelIconName;
} else if (InSandbox()) {
const auto launcherBasename = GetLauncherBasename();
if (QIcon::hasThemeIcon(launcherBasename)) {
return launcherBasename;
}
} else if (QIcon::hasThemeIcon(kTrayIconName.utf16())) {
return kTrayIconName.utf16();
}
return QString();
}
QImage TrayIconImageGen() { QImage TrayIconImageGen() {
const auto counter = Core::App().unreadBadge(); const auto counter = Core::App().unreadBadge();
const auto muted = Core::App().unreadBadgeMuted(); const auto muted = Core::App().unreadBadgeMuted();
@ -76,16 +94,8 @@ QImage TrayIconImageGen() {
|| _trayIconImageBack.size() != desiredSize || _trayIconImageBack.size() != desiredSize
|| iconThemeName != _trayIconThemeName || iconThemeName != _trayIconThemeName
|| iconName != _trayIconName) { || iconName != _trayIconName) {
const auto hasPanelIcon = QIcon::hasThemeIcon(iconName); if (!iconName.isEmpty()) {
const auto systemIcon = QIcon::fromTheme(iconName);
if (hasPanelIcon || QIcon::hasThemeIcon(kTrayIconName.utf16())) {
QIcon systemIcon;
if (hasPanelIcon) {
systemIcon = QIcon::fromTheme(iconName);
} else {
systemIcon = QIcon::fromTheme(kTrayIconName.utf16());
}
if (systemIcon.actualSize(desiredSize) == desiredSize) { if (systemIcon.actualSize(desiredSize) == desiredSize) {
_trayIconImageBack = systemIcon _trayIconImageBack = systemIcon
@ -118,7 +128,8 @@ QImage TrayIconImageGen() {
_trayIconThemeName = iconThemeName; _trayIconThemeName = iconThemeName;
_trayIconName = iconName; _trayIconName = iconName;
if (counter > 0) { if (!qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
&& counter > 0) {
QPainter p(&_trayIconImage); QPainter p(&_trayIconImage);
int32 layerSize = -16; int32 layerSize = -16;
@ -270,8 +281,10 @@ void MainWindow::psTrayMenuUpdated() {
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION #ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
void MainWindow::setSNITrayIcon( void MainWindow::setSNITrayIcon(
const QIcon &icon, const QImage &iconImage) { const QIcon &icon, const QImage &iconImage) {
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())) { const auto iconName = GetTrayIconName();
const auto iconName = GetTrayIconName();
if (qEnvironmentVariableIsSet(kDisableTrayCounter.utf8())
&& !iconName.isEmpty()) {
_sniTrayIcon->setIconByName(iconName); _sniTrayIcon->setIconByName(iconName);
_sniTrayIcon->setToolTipIconByName(iconName); _sniTrayIcon->setToolTipIconByName(iconName);
} else if (NeedTrayIconFile()) { } else if (NeedTrayIconFile()) {