mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-15 09:57:02 +00:00
Try to improve the queing of snore backend notifications.
This commit is contained in:
parent
dd4f01baf2
commit
f5fbb6a7ed
@ -116,6 +116,7 @@ void SnoreCore::broadcastNotification(Notification notification)
|
|||||||
{
|
{
|
||||||
Q_D(SnoreCore);
|
Q_D(SnoreCore);
|
||||||
if (d->m_activeNotifications.size() > d->maxNumberOfActiveNotifications()) {
|
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();
|
snoreDebug(SNORE_DEBUG) << "queue size:" << d->m_notificationQue.size() << "active size:" << d->m_activeNotifications.size();
|
||||||
d->m_notificationQue.append(notification);
|
d->m_notificationQue.append(notification);
|
||||||
return;
|
return;
|
||||||
|
@ -11,19 +11,18 @@ Window {
|
|||||||
color: notifyWidget.color
|
color: notifyWidget.color
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
onVisibleChanged: {
|
onVisibleChanged: {
|
||||||
if(visible){
|
if(visible){
|
||||||
x = 0
|
|
||||||
animation.from = notifyWidget.animationFrom
|
animation.from = notifyWidget.animationFrom
|
||||||
animation.start()
|
animation.restart()
|
||||||
|
show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NumberAnimation{
|
NumberAnimation on x{
|
||||||
id: animation
|
id: animation
|
||||||
properties: "x"
|
|
||||||
duration: 500
|
duration: 500
|
||||||
target: window
|
|
||||||
from: notifyWidget.animationFrom
|
from: notifyWidget.animationFrom
|
||||||
to: notifyWidget.animationTo
|
to: notifyWidget.animationTo
|
||||||
}
|
}
|
||||||
@ -51,9 +50,8 @@ Window {
|
|||||||
Drag.cancel()
|
Drag.cancel()
|
||||||
notifyWidget.dismissed()
|
notifyWidget.dismissed()
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
x = 0
|
|
||||||
}
|
}
|
||||||
|
x = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
|
@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
NotifyWidget::NotifyWidget(int id, const SnoreNotifier *parent) :
|
||||||
m_id(pos),
|
m_id(id),
|
||||||
m_parent(parent),
|
m_parent(parent),
|
||||||
m_mem(QLatin1String("SnoreNotifyWidget_rev") + QString::number(SHARED_MEM_TYPE_REV()) + QLatin1String("_id") + QString::number(m_id)),
|
m_mem(QLatin1String("SnoreNotifyWidget_rev") + QString::number(SHARED_MEM_TYPE_REV()) + QLatin1String("_id") + QString::number(m_id)),
|
||||||
m_ready(true),
|
m_ready(true),
|
||||||
@ -52,6 +52,8 @@ NotifyWidget::NotifyWidget(int pos, const SnoreNotifier *parent) :
|
|||||||
engine->load(QUrl::fromEncoded("qrc:/notification.qml"));
|
engine->load(QUrl::fromEncoded("qrc:/notification.qml"));
|
||||||
m_window = qobject_cast<QQuickWindow *>(engine->rootObjects().value(0));
|
m_window = qobject_cast<QQuickWindow *>(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
|
m_window->setFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowDoesNotAcceptFocus | Qt::BypassWindowManagerHint
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
| Qt::SubWindow
|
| Qt::SubWindow
|
||||||
@ -86,7 +88,7 @@ NotifyWidget::~NotifyWidget()
|
|||||||
|
|
||||||
void NotifyWidget::display(const Notification ¬ification)
|
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;
|
m_notification = notification;
|
||||||
QColor color;
|
QColor color;
|
||||||
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
QVariant vcolor = notification.application().constHints().privateValue(parent(), "backgroundColor");
|
||||||
@ -177,11 +179,6 @@ int NotifyWidget::id() const
|
|||||||
return m_id;
|
return m_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NotifyWidget::isVisible() const
|
|
||||||
{
|
|
||||||
return m_window->isVisible();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NotifyWidget::syncSettings()
|
void NotifyWidget::syncSettings()
|
||||||
{
|
{
|
||||||
Qt::Corner c = static_cast<Qt::Corner>(m_parent->settingsValue(QLatin1String("Position")).toInt());
|
Qt::Corner c = static_cast<Qt::Corner>(m_parent->settingsValue(QLatin1String("Position")).toInt());
|
||||||
|
@ -33,7 +33,7 @@ typedef struct {
|
|||||||
|
|
||||||
} SHARED_MEM_TYPE;
|
} SHARED_MEM_TYPE;
|
||||||
|
|
||||||
inline int SHARED_MEM_TYPE_REV()
|
Q_CONSTEXPR int SHARED_MEM_TYPE_REV()
|
||||||
{
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
@ -41,6 +41,7 @@ inline int SHARED_MEM_TYPE_REV()
|
|||||||
class NotifyWidget : public QObject
|
class NotifyWidget : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(int id READ id)
|
||||||
Q_PROPERTY(bool isOrientatedLeft MEMBER m_isOrientatedLeft NOTIFY isOrientatedLeftChanged)
|
Q_PROPERTY(bool isOrientatedLeft MEMBER m_isOrientatedLeft NOTIFY isOrientatedLeftChanged)
|
||||||
Q_PROPERTY(int animationFrom MEMBER m_animationFrom NOTIFY animationFromChanged)
|
Q_PROPERTY(int animationFrom MEMBER m_animationFrom NOTIFY animationFromChanged)
|
||||||
Q_PROPERTY(int animationTo MEMBER m_animationTo NOTIFY animationtoChanged)
|
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)
|
Q_PROPERTY(QString fontFamily MEMBER m_fontFamily NOTIFY fontFamilyChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit NotifyWidget(int pos, const SnoreNotifier *parent);
|
explicit NotifyWidget(int id, const SnoreNotifier *parent);
|
||||||
~NotifyWidget();
|
~NotifyWidget();
|
||||||
|
|
||||||
void display(const Snore::Notification ¬ification);
|
void display(const Snore::Notification ¬ification);
|
||||||
@ -68,7 +69,6 @@ public:
|
|||||||
Snore::Notification ¬ification();
|
Snore::Notification ¬ification();
|
||||||
|
|
||||||
int id() const;
|
int id() const;
|
||||||
bool isVisible() const;
|
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void invoked();
|
void invoked();
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
SnoreNotifier::SnoreNotifier():
|
SnoreNotifier::SnoreNotifier():
|
||||||
m_widgets(3),
|
m_widgets(1),
|
||||||
m_timer(new QTimer(this))
|
m_timer(new QTimer(this))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < m_widgets.size(); ++i) {
|
for (int i = 0; i < m_widgets.size(); ++i) {
|
||||||
@ -47,26 +47,8 @@ SnoreNotifier::SnoreNotifier():
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
m_timer->setInterval(500);
|
m_timer->setInterval(1000);
|
||||||
connect(m_timer, &QTimer::timeout, [this]() {
|
connect(m_timer, &QTimer::timeout, this, &SnoreNotifier::slotQueueTimeout);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +70,7 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||||||
if (notification.isUpdate()) {
|
if (notification.isUpdate()) {
|
||||||
if (notification.old().hints().privateValue(this, "id").isValid()) {
|
if (notification.old().hints().privateValue(this, "id").isValid()) {
|
||||||
NotifyWidget *w = m_widgets[notification.old().hints().privateValue(this, "id").toInt()];
|
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();
|
snoreDebug(SNORE_DEBUG) << "replacing notification" << w->notification().id() << notification.id();
|
||||||
display(w, notification);
|
display(w, notification);
|
||||||
}
|
}
|
||||||
@ -101,7 +83,8 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
if (m_queue.isEmpty()) {
|
if (m_queue.isEmpty()) {
|
||||||
for (NotifyWidget *w : m_widgets) {
|
for (NotifyWidget *w : m_widgets) {
|
||||||
if (w->acquire(notification.timeout())) {
|
if (w->acquire(notification.timeout())) {
|
||||||
@ -111,6 +94,8 @@ void SnoreNotifier::slotNotify(Snore::Notification notification)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_queue.append(notification);
|
m_queue.append(notification);
|
||||||
|
snoreDebug(SNORE_WARNING) << "queing" << m_queue.size();
|
||||||
|
if(!m_timer->isActive()){
|
||||||
m_timer->start();
|
m_timer->start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +104,26 @@ void SnoreNotifier::slotCloseNotification(Snore::Notification notification)
|
|||||||
{
|
{
|
||||||
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
NotifyWidget *w = m_widgets[notification.hints().privateValue(this, "id").toInt()];
|
||||||
w->release();
|
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
|
bool SnoreNotifier::canCloseNotification() const
|
||||||
|
@ -43,6 +43,9 @@ public Q_SLOTS:
|
|||||||
virtual void slotNotify(Snore::Notification notification) override;
|
virtual void slotNotify(Snore::Notification notification) override;
|
||||||
virtual void slotCloseNotification(Snore::Notification notification) override;
|
virtual void slotCloseNotification(Snore::Notification notification) override;
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void slotQueueTimeout();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Snore::Notification> m_queue;
|
QList<Snore::Notification> m_queue;
|
||||||
QVector<NotifyWidget *> m_widgets;
|
QVector<NotifyWidget *> m_widgets;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user