From 8a1c9155509de3c80d55fe7c6e03f3ad5036bc3b Mon Sep 17 00:00:00 2001 From: Paulo Lieuthier Date: Fri, 23 Sep 2016 13:27:44 -0300 Subject: [PATCH] lockscreenmanager: always listen to the session provider's lock signal (#79) Previously, it only listened if "Lock screen before suspending" was enabled. --- lxqt-session/src/lockscreenmanager.cpp | 39 ++++++++++++++----------- lxqt-session/src/lockscreenmanager.h | 2 +- lxqt-session/src/sessionapplication.cpp | 16 +++++----- 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/lxqt-session/src/lockscreenmanager.cpp b/lxqt-session/src/lockscreenmanager.cpp index 31ae84de..1874857e 100644 --- a/lxqt-session/src/lockscreenmanager.cpp +++ b/lxqt-session/src/lockscreenmanager.cpp @@ -42,11 +42,8 @@ LockScreenManager::~LockScreenManager() delete mProvider; } -bool LockScreenManager::startup() +bool LockScreenManager::startup(bool lockBeforeSleep) { - connect(&mScreenSaver, &LXQt::ScreenSaver::done, - &mLoop, &QEventLoop::quit); - mProvider = new LogindProvider; if (!mProvider->isValid()) { @@ -59,12 +56,25 @@ bool LockScreenManager::startup() } } - if (mProvider) + if (!mProvider) { - qCDebug(SESSION) << "LockScreenManager:" - << mProvider->metaObject()->className() - << "will be used"; + qCDebug(SESSION) << "LockScreenManager: no valid provider"; + return false; + } + + qCDebug(SESSION) << "LockScreenManager:" + << mProvider->metaObject()->className() + << "will be used"; + + connect(&mScreenSaver, &LXQt::ScreenSaver::done, &mLoop, &QEventLoop::quit); + connect(mProvider, &LockScreenProvider::lockRequested, [this] { + mScreenSaver.lockScreen(); + mLoop.exec(); + }); + + if (lockBeforeSleep) + { connect(mProvider, &LockScreenProvider::aboutToSleep, [this] (bool beforeSleep) @@ -81,17 +91,12 @@ bool LockScreenManager::startup() mProvider->inhibit(); }); - connect(mProvider, &LockScreenProvider::lockRequested, [this] { - mScreenSaver.lockScreen(); - mLoop.exec(); - }); - - return mProvider->inhibit(); + if (!mProvider->inhibit()) + qCDebug(SESSION) << "LockScreenManager:" + << "could not inhibit session provider"; } - else - qCDebug(SESSION) << "LockScreenManager: no valid provider"; - return false; + return true; } /* diff --git a/lxqt-session/src/lockscreenmanager.h b/lxqt-session/src/lockscreenmanager.h index f54d5a89..35bc50f5 100644 --- a/lxqt-session/src/lockscreenmanager.h +++ b/lxqt-session/src/lockscreenmanager.h @@ -93,7 +93,7 @@ class LockScreenManager : public QObject explicit LockScreenManager(QObject *parent = nullptr); virtual ~LockScreenManager(); - bool startup(); + bool startup(bool lockBeforeSleep); private: LockScreenProvider *mProvider; diff --git a/lxqt-session/src/sessionapplication.cpp b/lxqt-session/src/sessionapplication.cpp index e2fadd70..cf6ed74b 100644 --- a/lxqt-session/src/sessionapplication.cpp +++ b/lxqt-session/src/sessionapplication.cpp @@ -34,7 +34,8 @@ #include SessionApplication::SessionApplication(int& argc, char** argv) : - LXQt::Application(argc, argv) + LXQt::Application(argc, argv), + lockScreenManager(new LockScreenManager(this)) { listenToUnixSignals({SIGINT, SIGTERM, SIGQUIT, SIGHUP}); char* winmanager = NULL; @@ -104,14 +105,11 @@ bool SessionApplication::startup() }); #endif - if (settings.value(QLatin1String("lock_screen_before_power_actions")).toBool()) - { - lockScreenManager = new LockScreenManager(this); - if (lockScreenManager->startup()) - qCDebug(SESSION) << "LockScreenManager started successfully"; - else - qCWarning(SESSION) << "LockScreenManager couldn't start"; - } + bool lockBeforeSleep = settings.value(QLatin1String("lock_screen_before_power_actions"), true).toBool(); + if (lockScreenManager->startup(lockBeforeSleep)) + qCDebug(SESSION) << "LockScreenManager started successfully"; + else + qCWarning(SESSION) << "LockScreenManager couldn't start"; // launch module manager and autostart apps modman->startup(settings);