diff --git a/client/systemtrayicon.cpp b/client/systemtrayicon.cpp index 0adc1629..ce142b32 100644 --- a/client/systemtrayicon.cpp +++ b/client/systemtrayicon.cpp @@ -30,10 +30,14 @@ SystemTrayIcon::SystemTrayIcon(MainWindow* parent) showHideAction->setText(visible ? tr("Hide") : tr("Show")); }); - setIcon(QIcon::fromTheme(appIconName(), QIcon(":/icon.png"))); + m_appIcon = QIcon::fromTheme(appIconName(), QIcon(":/icon.png")); + m_unreadIcon = QIcon::fromTheme("mail-unread", m_appIcon); + m_notified = false; + setIcon(m_appIcon); setToolTip("Quaternion"); setContextMenu(contextMenu); connect( this, &SystemTrayIcon::activated, this, &SystemTrayIcon::systemTrayIconAction); + connect(qApp, &QApplication::focusChanged, this, &SystemTrayIcon::focusChanged); } void SystemTrayIcon::newRoom(Quotient::Room* room) @@ -47,9 +51,22 @@ void SystemTrayIcon::unreadStatsChanged(Quotient::Room* room) { using namespace Quotient; const auto mode = Settings().get("UI/notifications", "intrusive"); - if (mode == "none") + int nNotifs = 0; + + if (qApp->activeWindow() != nullptr || room->notificationCount() == 0) return; - if (qApp->activeWindow() != nullptr && room->notificationCount() > 0) { + + for (auto* c: Accounts.accounts()) + for (auto* r: c->allRooms()) + nNotifs += r->notificationCount(); + setToolTip(tr("%Ln notification(s)", "", nNotifs)); + + if (!m_notified) { + setIcon(m_unreadIcon); + m_notified = true; + if (mode == "none") + return; + showMessage( //: %1 is the room display name tr("Notification in %1").arg(room->displayName()), @@ -80,3 +97,12 @@ void SystemTrayIcon::showHide() m_parent->setFocus(); } } + +void SystemTrayIcon::focusChanged(QWidget* old) +{ + if (m_notified && old == nullptr && qApp->activeWindow() != nullptr) { + setIcon(m_appIcon); + setToolTip("Quaternion"); + m_notified = false; + } +} diff --git a/client/systemtrayicon.h b/client/systemtrayicon.h index 7906f788..3b81aef5 100644 --- a/client/systemtrayicon.h +++ b/client/systemtrayicon.h @@ -29,8 +29,12 @@ class SystemTrayIcon: public QSystemTrayIcon private slots: void unreadStatsChanged(Quotient::Room* room); void systemTrayIconAction(QSystemTrayIcon::ActivationReason reason); + void focusChanged(QWidget* old); private: MainWindow* m_parent; + QIcon m_appIcon; + QIcon m_unreadIcon; + bool m_notified; void showHide(); };