From 6e0ae807d59ae5c7d110c8feae031584825669ce Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Sun, 1 Oct 2017 18:15:23 +0300 Subject: [PATCH] Update badge counter only on change --- include/TrayIcon.h | 2 +- src/TimelineView.cc | 6 ++---- src/TrayIcon.cc | 18 +++++++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/TrayIcon.h b/include/TrayIcon.h index dec3063b..6073ea69 100644 --- a/include/TrayIcon.h +++ b/include/TrayIcon.h @@ -33,7 +33,7 @@ public: virtual void paint(QPainter *p, const QRect &rect, QIcon::Mode mode, QIcon::State state); virtual QIconEngine *clone() const; virtual QList availableSizes(QIcon::Mode mode, QIcon::State state) const; - virtual QPixmap pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state); + virtual QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state); int msgCount = 0; diff --git a/src/TimelineView.cc b/src/TimelineView.cc index 8b255cde..032d1310 100644 --- a/src/TimelineView.cc +++ b/src/TimelineView.cc @@ -380,14 +380,12 @@ TimelineView::init() scrollbar_ = new ScrollBar(scroll_area_); scroll_area_->setVerticalScrollBar(scrollbar_); - scroll_widget_ = new QWidget(); + scroll_widget_ = new QWidget(this); - scroll_layout_ = new QVBoxLayout(); + scroll_layout_ = new QVBoxLayout(scroll_widget_); scroll_layout_->addStretch(1); scroll_layout_->setSpacing(0); - scroll_widget_->setLayout(scroll_layout_); - scroll_area_->setWidget(scroll_widget_); top_layout_->addWidget(scroll_area_); diff --git a/src/TrayIcon.cc b/src/TrayIcon.cc index 8d3dc99f..1360cc4e 100644 --- a/src/TrayIcon.cc +++ b/src/TrayIcon.cc @@ -16,8 +16,8 @@ */ #include -#include #include +#include #include "TrayIcon.h" @@ -89,7 +89,7 @@ MsgCountComposedIcon::availableSizes(QIcon::Mode mode, QIcon::State state) const } QPixmap -MsgCountComposedIcon::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) +MsgCountComposedIcon::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { QImage img(size, QImage::Format_ARGB32); img.fill(qRgba(0, 0, 0, 0)); @@ -132,15 +132,19 @@ TrayIcon::setUnreadCount(int count) { // Use the native badge counter in MacOS. #if defined(Q_OS_MAC) - if (count == 0) - QtMac::setBadgeLabelText(""); - else - QtMac::setBadgeLabelText(QString::number(count)); + auto labelText = count == 0 ? "" : QString::number(count); + + if (labelText == QtMac::badgeLabelText()) + return; + + QtMac::setBadgeLabelText(labelText); #elif defined(Q_OS_WIN) // FIXME: Find a way to use Windows apis for the badge counter (if any). #else + if (count == icon_->msgCount) + return; + // Custom drawing on Linux. - // FIXME: It doesn't seem to work on KDE. MsgCountComposedIcon *tmp = static_cast(icon_->clone()); tmp->msgCount = count;