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