plasma: check popup status of applets in systemtray applet

this is special case for (notably) passive popups (such as the
notifications applet which has not only automatic popup but also sticks
until deactivated), to do that optimally a signal from
Plasma::PopupApplet::popupEvent() may be emitted in the future so that the
popup status is not checked on timer.

on a side note the old systemtray applet did not handle that case properly
and the notifications applet was not hidden sometimes

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-10-21 14:44:48 +03:00
parent e739972e60
commit 20daf2594c
2 changed files with 16 additions and 2 deletions

View file

@ -24,6 +24,8 @@
// standard issue margin/spacing
static const int s_margin = 4;
static const int s_spacing = 2;
// there is no signal for when the popup is shown so it has to be checked on timer
static const int s_popuptimeout = 500;
static QString kElementForArrow(const Qt::Orientation orientation, const bool reverse)
{
@ -52,11 +54,19 @@ SystemTrayApplet::SystemTrayApplet(QObject *parent, const QVariantList &args)
: Plasma::Applet(parent, args),
m_layout(nullptr),
m_arrowicon(nullptr),
m_showinghidden(false)
m_showinghidden(false),
m_popuptimer(nullptr)
{
KGlobal::locale()->insertCatalog("plasma_applet_systemtray");
setAspectRatioMode(Plasma::AspectRatioMode::IgnoreAspectRatio);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_popuptimer = new QTimer(this);
m_popuptimer->setInterval(s_popuptimeout);
connect(
m_popuptimer, SIGNAL(timeout()),
this, SLOT(slotUpdateVisibility())
);
}
SystemTrayApplet::~SystemTrayApplet()
@ -81,6 +91,7 @@ void SystemTrayApplet::init()
void SystemTrayApplet::updateLayout()
{
m_popuptimer->stop();
QMutexLocker locker(&m_mutex);
foreach (Plasma::Applet* plasmaapplet, m_applets) {
m_layout->removeItem(plasmaapplet);
@ -131,6 +142,7 @@ void SystemTrayApplet::updateLayout()
}
locker.unlock();
slotUpdateVisibility();
m_popuptimer->start();
}
void SystemTrayApplet::updateApplets(const Plasma::Constraints constraints)
@ -200,7 +212,7 @@ void SystemTrayApplet::slotUpdateVisibility()
bool hashidden = false;
QMutexLocker locker(&m_mutex);
foreach (Plasma::Applet* plasmaapplet, m_applets) {
if (plasmaapplet->status() == Plasma::PassiveStatus) {
if (plasmaapplet->status() == Plasma::PassiveStatus && !plasmaapplet->isPopupShowing()) {
hashidden = true;
plasmaapplet->setVisible(false);
// move hidden items to the front

View file

@ -20,6 +20,7 @@
#define SYSTEMTRAY_H
#include <QMutex>
#include <QTimer>
#include <QGraphicsLinearLayout>
#include <Plasma/Applet>
#include <Plasma/IconWidget>
@ -52,6 +53,7 @@ private:
QList<Plasma::Applet*> m_applets;
Plasma::IconWidget* m_arrowicon;
bool m_showinghidden;
QTimer* m_popuptimer;
};
#endif // SYSTEMTRAY_H