From f5fbb6a7eddfd50515a1a3136b20f5a7f47ac900 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Mon, 5 Oct 2015 16:05:21 +0200 Subject: [PATCH] Try to improve the queing of snore backend notifications. --- src/libsnore/snore.cpp | 1 + src/plugins/backends/snore/notification.qml | 12 ++-- src/plugins/backends/snore/notifywidget.cpp | 13 ++-- src/plugins/backends/snore/notifywidget.h | 6 +- src/plugins/backends/snore/snorenotifier.cpp | 66 +++++++++++--------- src/plugins/backends/snore/snorenotifier.h | 3 + 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/src/libsnore/snore.cpp b/src/libsnore/snore.cpp index bd0a94f..d8a5800 100644 --- a/src/libsnore/snore.cpp +++ b/src/libsnore/snore.cpp @@ -116,6 +116,7 @@ void SnoreCore::broadcastNotification(Notification notification) { Q_D(SnoreCore); if (d->m_activeNotifications.size() > d->maxNumberOfActiveNotifications()) { +#pragma message "TODO: handle updates in queue" snoreDebug(SNORE_DEBUG) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size(); d->m_notificationQue.append(notification); return; diff --git a/src/plugins/backends/snore/notification.qml b/src/plugins/backends/snore/notification.qml index a2570a2..80efbf0 100644 --- a/src/plugins/backends/snore/notification.qml +++ b/src/plugins/backends/snore/notification.qml @@ -11,19 +11,18 @@ Window { color: notifyWidget.color + onVisibleChanged: { if(visible){ - x = 0 animation.from = notifyWidget.animationFrom - animation.start() + animation.restart() + show() } } - NumberAnimation{ + NumberAnimation on x{ id: animation - properties: "x" duration: 500 - target: window from: notifyWidget.animationFrom to: notifyWidget.animationTo } @@ -51,9 +50,8 @@ Window { Drag.cancel() notifyWidget.dismissed() } - } else { - x = 0 } + x = 0 } MouseArea { diff --git a/src/plugins/backends/snore/notifywidget.cpp b/src/plugins/backends/snore/notifywidget.cpp index 1a96b3f..2f545cc 100644 --- a/src/plugins/backends/snore/notifywidget.cpp +++ b/src/plugins/backends/snore/notifywidget.cpp @@ -27,8 +27,8 @@ using namespace Snore; -NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) : - m_id(pos), +NotifyWidget::NotifyWidget(int id, const SnoreNotifier *parent) : + m_id(id), m_parent(parent), m_mem(QLatin1String("SnoreNotifyWidget_rev") + QString::number(SHARED_MEM_TYPE_REV()) + QLatin1String("_id") + QString::number(m_id)), m_ready(true), @@ -52,6 +52,8 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) : engine->load(QUrl::fromEncoded("qrc:/notification.qml")); m_window = qobject_cast(engine->rootObjects().value(0)); + // TODO: Qt::BypassWindowManagerHint is needed on linux to make it possible to animate the Window. + // It looks like there is a Qt bug wich make some Windows with this flag invisible. m_window->setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint #ifdef Q_OS_MAC | Qt::SubWindow @@ -86,7 +88,7 @@ NotifyWidget::~NotifyWidget() void NotifyWidget::display(const Notification ¬ification) { - snoreDebug(SNORE_DEBUG) << m_id << notification.id(); + snoreDebug(SNORE_DEBUG) << m_id << notification.id() << m_window->isVisible(); m_notification = notification; QColor color; QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor"); @@ -177,11 +179,6 @@ int NotifyWidget::id() const return m_id; } -bool NotifyWidget::isVisible() const -{ - return m_window->isVisible(); -} - void NotifyWidget::syncSettings() { Qt::Corner c = static_cast(m_parent->settingsValue(QLatin1String("Position")).toInt()); diff --git a/src/plugins/backends/snore/notifywidget.h b/src/plugins/backends/snore/notifywidget.h index 2e646f9..8ecff54 100644 --- a/src/plugins/backends/snore/notifywidget.h +++ b/src/plugins/backends/snore/notifywidget.h @@ -33,7 +33,7 @@ typedef struct { } SHARED_MEM_TYPE; -inline int SHARED_MEM_TYPE_REV() +Q_CONSTEXPR int SHARED_MEM_TYPE_REV() { return 2; } @@ -41,6 +41,7 @@ inline int SHARED_MEM_TYPE_REV() class NotifyWidget : public QObject { Q_OBJECT + Q_PROPERTY(int id READ id) Q_PROPERTY(bool isOrientatedLeft MEMBER m_isOrientatedLeft NOTIFY isOrientatedLeftChanged) Q_PROPERTY(int animationFrom MEMBER m_animationFrom NOTIFY animationFromChanged) Q_PROPERTY(int animationTo MEMBER m_animationTo NOTIFY animationtoChanged) @@ -57,7 +58,7 @@ class NotifyWidget : public QObject Q_PROPERTY(QString fontFamily MEMBER m_fontFamily NOTIFY fontFamilyChanged) public: - explicit NotifyWidget(int pos, const SnoreNotifier *parent); + explicit NotifyWidget(int id, const SnoreNotifier *parent); ~NotifyWidget(); void display(const Snore::Notification ¬ification); @@ -68,7 +69,6 @@ public: Snore::Notification ¬ification(); int id() const; - bool isVisible() const; Q_SIGNALS: void invoked(); diff --git a/src/plugins/backends/snore/snorenotifier.cpp b/src/plugins/backends/snore/snorenotifier.cpp index 1cf9c2e..0e78594 100644 --- a/src/plugins/backends/snore/snorenotifier.cpp +++ b/src/plugins/backends/snore/snorenotifier.cpp @@ -27,7 +27,7 @@ using namespace Snore; SnoreNotifier::SnoreNotifier(): - m_widgets(3), + m_widgets(1), m_timer(new QTimer(this)) { for (int i = 0; i < m_widgets.size(); ++i) { @@ -47,26 +47,8 @@ SnoreNotifier::SnoreNotifier(): }); } - m_timer->setInterval(500); - connect(m_timer, &QTimer::timeout, [this]() { - if (m_queue.isEmpty()) { - snoreDebug(SNORE_DEBUG) << "queue is empty"; - m_timer->stop(); - } else { - for (NotifyWidget *w : m_widgets) { - if (w->acquire(m_queue.first().timeout())) { - Notification notification = m_queue.takeFirst(); - w->display(notification); - notification.hints().setPrivateValue(this, "id", w->id()); - slotNotificationDisplayed(notification); - if (m_queue.isEmpty()) { - m_timer->stop(); - return; - } - } - } - } - }); + m_timer->setInterval(1000); + connect(m_timer, &QTimer::timeout, this, &SnoreNotifier::slotQueueTimeout); } @@ -88,7 +70,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification) if (notification.isUpdate()) { if (notification.old().hints().privateValue(this, "id").isValid()) { NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()]; - if (w->isVisible() && w->notification().isValid() && w->notification().id() == notification.old().id()) { + if (w->notification().isValid() && w->notification().id() == notification.old().id()) { snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id(); display(w, notification); } @@ -101,16 +83,19 @@ void SnoreNotifier::slotNotify(Snore::Notification notification) } } } - } else { - if (m_queue.isEmpty()) { - for (NotifyWidget *w : m_widgets) { - if (w->acquire(notification.timeout())) { - display(w, notification); - return; - } + return; + } + if (m_queue.isEmpty()) { + for (NotifyWidget *w : m_widgets) { + if (w->acquire(notification.timeout())) { + display(w, notification); + return; } } - m_queue.append(notification); + } + m_queue.append(notification); + snoreDebug(SNORE_WARNING) << "queing" << m_queue.size(); + if(!m_timer->isActive()){ m_timer->start(); } } @@ -119,7 +104,26 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification) { NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()]; w->release(); - //the timer will show the next + slotQueueTimeout(); +} + +void SnoreNotifier::slotQueueTimeout() +{ + snoreDebug(SNORE_WARNING) << "queue" << m_queue.size(); + if (m_queue.isEmpty()) { + // snoreDebug(SNORE_DEBUG) << "queue is empty"; + m_timer->stop(); + } else { + for (NotifyWidget *w : m_widgets) { + if (!m_queue.isEmpty() && w->acquire(m_queue.first().timeout())) { + snoreDebug(SNORE_WARNING) << "aquired " << w->id(); + Notification notification = m_queue.takeFirst(); + notification.hints().setPrivateValue(this, "id", w->id()); + w->display(notification); + slotNotificationDisplayed(notification); + } + } + } } bool SnoreNotifier::canCloseNotification() const diff --git a/src/plugins/backends/snore/snorenotifier.h b/src/plugins/backends/snore/snorenotifier.h index b57d089..52e97ba 100644 --- a/src/plugins/backends/snore/snorenotifier.h +++ b/src/plugins/backends/snore/snorenotifier.h @@ -43,6 +43,9 @@ public Q_SLOTS: virtual void slotNotify(Snore::Notification notification) override; virtual void slotCloseNotification(Snore::Notification notification) override; +private Q_SLOTS: + void slotQueueTimeout(); + private: QList m_queue; QVector m_widgets;