mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Implement monochrome icon setting on Linux
This commit is contained in:
parent
1d7dbc4d17
commit
439f8d0914
2 changed files with 41 additions and 24 deletions
|
@ -22,6 +22,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include <QtWidgets/QSystemTrayIcon>
|
||||
|
||||
namespace Platform {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] QString PanelIconName(int counter, bool muted) {
|
||||
return (counter > 0)
|
||||
? (muted
|
||||
? u"telegram-mute-panel"_q
|
||||
: u"telegram-attention-panel"_q)
|
||||
: u"telegram-panel"_q;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class IconGraphic final {
|
||||
public:
|
||||
|
@ -35,29 +46,27 @@ public:
|
|||
bool muted) const;
|
||||
[[nodiscard]] QIcon systemIcon(
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted) const;
|
||||
[[nodiscard]] QIcon trayIcon(
|
||||
const QIcon &systemIcon,
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted);
|
||||
|
||||
private:
|
||||
[[nodiscard]] QString panelIconName(int counter, bool muted) const;
|
||||
[[nodiscard]] int counterSlice(int counter) const;
|
||||
void updateIconRegenerationNeeded(
|
||||
const QIcon &icon,
|
||||
const QIcon &systemIcon,
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted);
|
||||
[[nodiscard]] QSize dprSize(const QImage &image) const;
|
||||
|
||||
const QString _panelTrayIconName;
|
||||
const QString _mutePanelTrayIconName;
|
||||
const QString _attentionPanelTrayIconName;
|
||||
|
||||
const int _iconSizes[7];
|
||||
|
||||
bool _muted = true;
|
||||
|
@ -66,42 +75,37 @@ private:
|
|||
QIcon _trayIcon;
|
||||
QIcon _systemIcon;
|
||||
QString _themeName;
|
||||
bool _monochrome;
|
||||
|
||||
};
|
||||
|
||||
IconGraphic::IconGraphic()
|
||||
: _panelTrayIconName("telegram-panel")
|
||||
, _mutePanelTrayIconName("telegram-mute-panel")
|
||||
, _attentionPanelTrayIconName("telegram-attention-panel")
|
||||
, _iconSizes{ 16, 22, 32, 48, 64, 128, 256 } {
|
||||
: _iconSizes{ 16, 22, 32, 48, 64, 128, 256 } {
|
||||
}
|
||||
|
||||
IconGraphic::~IconGraphic() = default;
|
||||
|
||||
QString IconGraphic::panelIconName(int counter, bool muted) const {
|
||||
return (counter > 0)
|
||||
? (muted
|
||||
? _mutePanelTrayIconName
|
||||
: _attentionPanelTrayIconName)
|
||||
: _panelTrayIconName;
|
||||
}
|
||||
|
||||
QIcon IconGraphic::systemIcon(
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted) const {
|
||||
if (iconThemeName == _themeName
|
||||
&& monochrome == _monochrome
|
||||
&& (counter > 0) == (_count > 0)
|
||||
&& muted == _muted) {
|
||||
return _systemIcon;
|
||||
}
|
||||
|
||||
const auto candidates = {
|
||||
panelIconName(counter, muted),
|
||||
monochrome ? PanelIconName(counter, muted) : QString(),
|
||||
base::IconName(),
|
||||
};
|
||||
|
||||
for (const auto &candidate : candidates) {
|
||||
if (candidate.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
const auto icon = QIcon::fromTheme(candidate);
|
||||
if (icon.name() == candidate) {
|
||||
return icon;
|
||||
|
@ -134,11 +138,13 @@ void IconGraphic::updateIconRegenerationNeeded(
|
|||
const QIcon &icon,
|
||||
const QIcon &systemIcon,
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted) {
|
||||
_trayIcon = icon;
|
||||
_systemIcon = systemIcon;
|
||||
_themeName = iconThemeName;
|
||||
_monochrome = monochrome;
|
||||
_count = counterSlice(counter);
|
||||
_muted = muted;
|
||||
}
|
||||
|
@ -150,18 +156,19 @@ QSize IconGraphic::dprSize(const QImage &image) const {
|
|||
QIcon IconGraphic::trayIcon(
|
||||
const QIcon &systemIcon,
|
||||
const QString &iconThemeName,
|
||||
bool monochrome,
|
||||
int counter,
|
||||
bool muted) {
|
||||
if (!isRefreshNeeded(systemIcon, iconThemeName, counter, muted)) {
|
||||
return _trayIcon;
|
||||
}
|
||||
|
||||
|
||||
if (systemIcon.name() == panelIconName(counter, muted)) {
|
||||
if (systemIcon.name() == PanelIconName(counter, muted)) {
|
||||
updateIconRegenerationNeeded(
|
||||
systemIcon,
|
||||
systemIcon,
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted);
|
||||
|
||||
|
@ -227,6 +234,7 @@ QIcon IconGraphic::trayIcon(
|
|||
result,
|
||||
systemIcon,
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted);
|
||||
|
||||
|
@ -290,6 +298,7 @@ void Tray::createIcon() {
|
|||
};
|
||||
|
||||
const auto iconThemeName = QIcon::themeName();
|
||||
const auto monochrome = Core::App().settings().trayIconMonochrome();
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
const auto muted = Core::App().unreadBadgeMuted();
|
||||
|
||||
|
@ -297,9 +306,11 @@ void Tray::createIcon() {
|
|||
_icon->setIcon(_iconGraphic->trayIcon(
|
||||
_iconGraphic->systemIcon(
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted),
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted));
|
||||
_icon->setToolTip(AppName.utf16());
|
||||
|
@ -342,9 +353,11 @@ void Tray::updateIcon() {
|
|||
}
|
||||
const auto counter = Core::App().unreadBadge();
|
||||
const auto muted = Core::App().unreadBadgeMuted();
|
||||
const auto monochrome = Core::App().settings().trayIconMonochrome();
|
||||
const auto iconThemeName = QIcon::themeName();
|
||||
const auto systemIcon = _iconGraphic->systemIcon(
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted);
|
||||
|
||||
|
@ -356,6 +369,7 @@ void Tray::updateIcon() {
|
|||
_icon->setIcon(_iconGraphic->trayIcon(
|
||||
systemIcon,
|
||||
iconThemeName,
|
||||
monochrome,
|
||||
counter,
|
||||
muted));
|
||||
}
|
||||
|
@ -436,4 +450,11 @@ rpl::lifetime &Tray::lifetime() {
|
|||
|
||||
Tray::~Tray() = default;
|
||||
|
||||
bool HasMonochromeSetting() {
|
||||
return QIcon::hasThemeIcon(
|
||||
PanelIconName(
|
||||
Core::App().unreadBadge(),
|
||||
Core::App().unreadBadgeMuted()));
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
|
|
@ -67,8 +67,4 @@ private:
|
|||
|
||||
};
|
||||
|
||||
inline bool HasMonochromeSetting() {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
|
|
Loading…
Add table
Reference in a new issue