diff options
author | Nicolas Werner <nicolas.werner@hotmail.de> | 2024-06-20 21:35:55 +0200 |
---|---|---|
committer | Nicolas Werner <nicolas.werner@hotmail.de> | 2024-06-20 21:35:55 +0200 |
commit | a486d8d7fc567c191e7259b478b6f03b3800ac4a (patch) | |
tree | 9f01f7bb80df5b2502d92d91fe1329209224289c | |
parent | Fix QT_CONFIG check for wayland is only available since Qt6.7 (diff) | |
download | nheko-a486d8d7fc567c191e7259b478b6f03b3800ac4a.tar.xz |
Fix tray icon badge count not getting updated since 838b091acd07b681fc52f6f705b2bee8ce8519d5
-rw-r--r-- | src/MainWindow.cpp | 2 | ||||
-rw-r--r-- | src/TrayIcon.cpp | 25 | ||||
-rw-r--r-- | src/TrayIcon.h | 13 |
3 files changed, 21 insertions, 19 deletions
diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ea9f560d..42a1521d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -60,7 +60,7 @@ MainWindow::MainWindow(QWindow *parent) connect(chat_page_, &ChatPage::closing, this, [this] { switchToLoginPage(""); }); connect(chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle); - connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int))); + connect(chat_page_, &ChatPage::unreadMessages, trayIcon_, &TrayIcon::setUnreadCount); connect(chat_page_, &ChatPage::showLoginPage, this, &MainWindow::switchToLoginPage); connect(chat_page_, &ChatPage::showNotification, this, &MainWindow::showNotification); diff --git a/src/TrayIcon.cpp b/src/TrayIcon.cpp index c89e69cc..c62fecea 100644 --- a/src/TrayIcon.cpp +++ b/src/TrayIcon.cpp @@ -12,9 +12,9 @@ #include "TrayIcon.h" -MsgCountComposedIcon::MsgCountComposedIcon(const QString &filename) +MsgCountComposedIcon::MsgCountComposedIcon(const QIcon &icon) : QIconEngine() - , icon_{QIcon{filename}} + , icon_{icon} { } @@ -41,8 +41,8 @@ MsgCountComposedIcon::paint(QPainter *painter, brush.setColor(backgroundColor); QFont f; - f.setPointSizeF(8); - f.setWeight(QFont::Thin); + f.setPixelSize(int(BubbleDiameter * 0.6)); + f.setWeight(QFont::Bold); painter->setBrush(brush); painter->setPen(Qt::NoPen); @@ -66,9 +66,6 @@ MsgCountComposedIcon::clone() const QList<QSize> MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - const -#endif { Q_UNUSED(mode); Q_UNUSED(state); @@ -97,11 +94,12 @@ MsgCountComposedIcon::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State s TrayIcon::TrayIcon(const QString &filename, QWindow *parent) : QSystemTrayIcon(parent) + , icon(filename) { #if defined(Q_OS_MACOS) || defined(Q_OS_WIN) - setIcon(QIcon(filename)); + setIcon(icon); #else - icon_ = new MsgCountComposedIcon(filename); + auto icon_ = new MsgCountComposedIcon(icon); setIcon(QIcon(icon_)); #endif @@ -122,6 +120,15 @@ void TrayIcon::setUnreadCount(int count) { qGuiApp->setBadgeNumber(count); + +#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN) + if (count != previousCount) { + auto i = new MsgCountComposedIcon(icon); + i->msgCount = count; + setIcon(QIcon(i)); + previousCount = count; + } +#endif } #include "moc_TrayIcon.cpp" diff --git a/src/TrayIcon.h b/src/TrayIcon.h index f2009612..7c0bc7b2 100644 --- a/src/TrayIcon.h +++ b/src/TrayIcon.h @@ -15,15 +15,11 @@ class QPainter; class MsgCountComposedIcon final : public QIconEngine { public: - MsgCountComposedIcon(const QString &filename); + MsgCountComposedIcon(const QIcon &icon); void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; QIconEngine *clone() const override; - QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - const -#endif - override; + QList<QSize> availableSizes(QIcon::Mode mode, QIcon::State state) override; QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; int msgCount = 0; @@ -47,7 +43,6 @@ private: QAction *viewAction_; QAction *quitAction_; -#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN) - MsgCountComposedIcon *icon_; -#endif + int previousCount = 0; + QIcon icon; }; |