From fa5715aba4513442ad1404ae018c3023a7d4087f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 22 May 2024 15:22:32 +0300 Subject: [PATCH] plasma: catch even child events to cancel auto-hide in notifications applet continue from: ff687e99e7294c451b77a7c568aba902c3f593ff a bit expensive but gets the job done Signed-off-by: Ivailo Monev --- .../applets/notifications/notifications.cpp | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/plasma/applets/notifications/notifications.cpp b/plasma/applets/notifications/notifications.cpp index edd50b4d..1bb592bf 100644 --- a/plasma/applets/notifications/notifications.cpp +++ b/plasma/applets/notifications/notifications.cpp @@ -54,7 +54,7 @@ public: NotificationsWidget(NotificationsApplet* notifications); protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event) final; + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) final; private Q_SLOTS: void slotCountChanged(); @@ -79,6 +79,8 @@ NotificationsWidget::NotificationsWidget(NotificationsApplet* notifications) setMinimumSize(s_minimumsize); // makes it truly passive popup setWindowFlags(windowFlags() | Qt::X11BypassWindowManagerHint); + // the easy way to cancel auto-hide on activity + setFiltersChildEvents(true); m_jobsscrollwidget = new Plasma::ScrollWidget(this); m_jobsscrollwidget->setMinimumSize(s_minimumsize); @@ -101,13 +103,26 @@ NotificationsWidget::NotificationsWidget(NotificationsApplet* notifications) addTab(KIcon("dialog-information"), i18n("Notifications"), m_applicationsscrollwidget); } -void NotificationsWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) +bool NotificationsWidget::sceneEventFilter(QGraphicsItem *watched, QEvent *event) { - Plasma::TabBar::mousePressEvent(event); + const bool result = Plasma::TabBar::sceneEventFilter(watched, event); if (m_automaticpopup) { - // stop auto-hide timer of the popup - m_notifications->showPopup(0); + switch (event->type()) { + case QEvent::KeyPress: + case QEvent::MouseButtonPress: + case QEvent::GraphicsSceneMousePress: + case QEvent::GraphicsSceneWheel: { + // stop auto-hide timer of the popup + m_automaticpopup = false; + m_notifications->showPopup(0); + break; + } + default: { + break; + } + } } + return result; } void NotificationsWidget::slotCountChanged() @@ -145,6 +160,7 @@ NotificationsApplet::NotificationsApplet(QObject *parent, const QVariantList &ar setPopupIcon(kNotificationIcon(this, false)); setStatus(Plasma::ItemStatus::PassiveStatus); m_notificationswidget = new NotificationsWidget(this); + installEventFilter(m_notificationswidget); } NotificationsApplet::~NotificationsApplet()