diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp index 958224eb1..eaecc54c0 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp @@ -24,9 +24,11 @@ #include #include #include +#include #include "../../../app/App.hpp" #include "../../../utils/LinphoneUtils.hpp" +#include "../../../utils/Utils.hpp" #include "MessagesCountNotifierLinux.hpp" @@ -35,6 +37,7 @@ #define ICON_COUNTER_BACKGROUND_COLOR "#FF3C31" #define ICON_COUNTER_BACKGROUND_RADIUS 100 +#define ICON_COUNTER_BLINK_INTERVAL 1000 #define ICON_COUNTER_TEXT_COLOR "#FFFBFA" #define ICON_COUNTER_TEXT_PIXEL_SIZE 144 @@ -52,10 +55,21 @@ MessagesCountNotifier::MessagesCountNotifier (QObject *parent) : AbstractMessage renderer.render(&painter); mBuf = new QPixmap(buf); + mBufWithCounter = new QPixmap(); + + mBlinkTimer = new QTimer(this); + mBlinkTimer->setInterval(ICON_COUNTER_BLINK_INTERVAL); + QObject::connect(mBlinkTimer, &QTimer::timeout, this, &MessagesCountNotifier::update); + + Utils::connectOnce( + App::getInstance(), &App::focusWindowChanged, + this, &MessagesCountNotifier::updateUnreadMessagesCount + ); } MessagesCountNotifier::~MessagesCountNotifier () { delete mBuf; + delete mBufWithCounter; } void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { @@ -64,15 +78,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { return; if (!n) { + mBlinkTimer->stop(); sysTrayIcon->setIcon(QIcon(*mBuf)); return; } - QPixmap buf(*mBuf); - QPainter p(&buf); + *mBufWithCounter = *mBuf; + QPainter p(mBufWithCounter); - const int width = buf.width(); - const int height = buf.height(); + const int width = mBufWithCounter->width(); + const int height = mBufWithCounter->height(); // Draw background. { @@ -90,5 +105,16 @@ void MessagesCountNotifier::notifyUnreadMessagesCount (int n) { p.drawText(QRect(0, 0, width, height), Qt::AlignCenter, QString::number(n)); } - sysTrayIcon->setIcon(QIcon(buf)); + // Change counter. + mBlinkTimer->stop(); + mBlinkTimer->start(); + mDisplayCounter = true; + update(); +} + +void MessagesCountNotifier::update () { + QSystemTrayIcon *sysTrayIcon = App::getInstance()->getSystemTrayIcon(); + Q_CHECK_PTR(sysTrayIcon); + sysTrayIcon->setIcon(QIcon(mDisplayCounter ? *mBufWithCounter : *mBuf)); + mDisplayCounter = !mDisplayCounter; } diff --git a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp index 7f4a932ec..6477be15e 100644 --- a/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp +++ b/src/components/core/messages-count-notifier/MessagesCountNotifierLinux.hpp @@ -24,6 +24,8 @@ // ============================================================================= +class QTimer; + class MessagesCountNotifier : public AbstractMessagesCountNotifier { public: MessagesCountNotifier (QObject *parent = Q_NULLPTR); @@ -33,5 +35,10 @@ protected: void notifyUnreadMessagesCount (int n) override; private: + void update (); + const QPixmap *mBuf = nullptr; + QPixmap *mBufWithCounter = nullptr; + QTimer *mBlinkTimer = nullptr; + bool mDisplayCounter = false; };