From ca07409ebc07f1e2bbc22969530ae40a69b87e3f Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 20 Apr 2024 00:51:14 +0300 Subject: [PATCH] plasma: delay the lock action too from contextmenu containments action Signed-off-by: Ivailo Monev --- .../containmentactions/contextmenu/menu.cpp | 40 ++++++++++--------- plasma/containmentactions/contextmenu/menu.h | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/plasma/containmentactions/contextmenu/menu.cpp b/plasma/containmentactions/contextmenu/menu.cpp index 22c75c60..ac9b32ff 100644 --- a/plasma/containmentactions/contextmenu/menu.cpp +++ b/plasma/containmentactions/contextmenu/menu.cpp @@ -37,6 +37,19 @@ #include "kworkspace/kworkspace.h" #include "screensaver_interface.h" +// this short delay is due to two issues: +// a) KWorkSpace's DBus alls are all syncronous +// b) the destrution of the menu that this action is in is delayed +// +// (a) leads to the menu hanging out where everyone can see it because the even loop doesn't get +// returned to allowing it to close. +// +// (b) leads to a 0ms timer not working since a 0ms timer just appends to the event queue, and then +// the menu closing event gets appended to that. +// +// ergo a timer with small timeout +static const int s_actiondelay = 10; // ms + ContextMenu::ContextMenu(QObject *parent, const QVariantList &args) : Plasma::ContainmentActions(parent, args), @@ -49,10 +62,6 @@ ContextMenu::ContextMenu(QObject *parent, const QVariantList &args) { } -ContextMenu::~ContextMenu() -{ -} - void ContextMenu::init(const KConfigGroup &config) { Plasma::Containment *c = containment(); @@ -91,7 +100,7 @@ void ContextMenu::init(const KConfigGroup &config) } else if (!m_lockScreenAction) { m_lockScreenAction = new QAction(i18n("Lock Screen"), this); m_lockScreenAction->setIcon(KIcon("system-lock-screen")); - connect(m_lockScreenAction, SIGNAL(triggered(bool)), this, SLOT(lockScreen())); + connect(m_lockScreenAction, SIGNAL(triggered(bool)), this, SLOT(startLockScreen())); m_logoutAction = new QAction(i18n("Leave..."), this); m_logoutAction->setIcon(KIcon("system-shutdown")); @@ -168,11 +177,15 @@ QAction *ContextMenu::action(const QString &name) return 0; } +void ContextMenu::startLockScreen() +{ + QTimer::singleShot(s_actiondelay, this, SLOT(lockScreen())); +} + void ContextMenu::lockScreen() { QString interface("org.freedesktop.ScreenSaver"); - org::freedesktop::ScreenSaver screensaver(interface, "/ScreenSaver", - QDBusConnection::sessionBus()); + org::freedesktop::ScreenSaver screensaver(interface, "/ScreenSaver", QDBusConnection::sessionBus()); if (screensaver.isValid()) { screensaver.Lock(); } @@ -180,18 +193,7 @@ void ContextMenu::lockScreen() void ContextMenu::startLogout() { - // this short delay is due to two issues: - // a) KWorkSpace's DBus alls are all syncronous - // b) the destrution of the menu that this action is in is delayed - // - // (a) leads to the menu hanging out where everyone can see it because - // the even loop doesn't get returned to allowing it to close. - // - // (b) leads to a 0ms timer not working since a 0ms timer just appends to - // the event queue, and then the menu closing event gets appended to that. - // - // ergo a timer with small timeout - QTimer::singleShot(10, this, SLOT(logout())); + QTimer::singleShot(s_actiondelay, this, SLOT(logout())); } void ContextMenu::logout() diff --git a/plasma/containmentactions/contextmenu/menu.h b/plasma/containmentactions/contextmenu/menu.h index 6a95b76b..eb716a45 100644 --- a/plasma/containmentactions/contextmenu/menu.h +++ b/plasma/containmentactions/contextmenu/menu.h @@ -28,7 +28,6 @@ class ContextMenu : public Plasma::ContainmentActions Q_OBJECT public: ContextMenu(QObject* parent, const QVariantList& args); - ~ContextMenu(); void init(const KConfigGroup&); @@ -41,6 +40,7 @@ public: void save(KConfigGroup &config); public slots: + void startLockScreen(); void lockScreen(); void startLogout(); void logout();