Commit 72dab0e5 authored by Martin Flöser's avatar Martin Flöser

[screenlocker] Pass grace time as command line argument to greeter

Instead of having the greeter read the settings of the KSLD, KSLD passes
the required values to the greeter as command line arguments. This
ensures that the greeter doesn't show a lock UI while the KSLD is still
in grace time and vice versa.

Two command line options are added:
--graceTime <milliseconds>
--nolock

The option --graceTime starts the timer to show the lock ui on timeout.
The option --nolock is for the case that the KSLD never locks the
screen.

REVIEW: 118214
parent 895ab02d
......@@ -71,8 +71,9 @@ UnlockApp::UnlockApp(int &argc, char **argv)
, m_capsLocked(false)
, m_ignoreRequests(false)
, m_immediateLock(false)
, m_runtimeInitialized(false)
, m_authenticator(new Authenticator(this))
, m_graceTime(0)
, m_noLock(false)
{
connect(m_authenticator, &Authenticator::succeeded, this, &QCoreApplication::quit);
initialize();
......@@ -166,27 +167,7 @@ void UnlockApp::desktopResized()
view->setResizeMode(QQuickView::SizeRootObjectToView);
QQmlProperty lockProperty(view->rootObject(), QStringLiteral("locked"));
if (m_immediateLock) {
lockProperty.write(true);
} else if (KScreenSaverSettings::lock()) {
if (KScreenSaverSettings::lockGrace() < 1) {
lockProperty.write(true);
} else if (m_runtimeInitialized) {
// if we have new views and we are waiting on the
// delayed lock timer still, we don't want to show
// the lock UI just yet
lockProperty.write(!m_delayedLockTimer);
} else {
if (!m_delayedLockTimer) {
m_delayedLockTimer = new QTimer(this);
m_delayedLockTimer->setSingleShot(true);
connect(m_delayedLockTimer, SIGNAL(timeout()), this, SLOT(setLockedPropertyOnViews()));
}
m_delayedLockTimer->start(KScreenSaverSettings::lockGrace());
}
} else {
lockProperty.write(false);
}
lockProperty.write(m_immediateLock || (!m_noLock && !m_delayedLockTimer));
QQmlProperty sleepProperty(view->rootObject(), QStringLiteral("suspendToRamSupported"));
sleepProperty.write(spdMethods.contains(Solid::PowerManagement::SuspendState));
......@@ -212,8 +193,6 @@ void UnlockApp::desktopResized()
m_views << view;
}
m_runtimeInitialized = true;
// update geometry of all views and savers
for (int i = 0; i < nScreens; ++i) {
QQuickView *view = m_views.at(i);
......@@ -439,6 +418,23 @@ void UnlockApp::shareEvent(QEvent *e, QQuickView *from)
}
}
void UnlockApp::setGraceTime(int milliseconds)
{
m_graceTime = milliseconds;
if (milliseconds < 0 || m_delayedLockTimer || m_noLock || m_immediateLock) {
return;
}
m_delayedLockTimer = new QTimer(this);
m_delayedLockTimer->setSingleShot(true);
connect(m_delayedLockTimer, &QTimer::timeout, this, &UnlockApp::setLockedPropertyOnViews);
m_delayedLockTimer->start(m_graceTime);
}
void UnlockApp::setNoLock(bool noLock)
{
m_noLock = noLock;
}
} // namespace
#include "greeterapp.moc"
......@@ -45,6 +45,8 @@ public:
void setTesting(bool enable);
void setImmediateLock(bool immediateLock);
void lockImmediately();
void setGraceTime(int milliseconds);
void setNoLock(bool noLock);
public Q_SLOTS:
void desktopResized();
......@@ -77,6 +79,8 @@ private:
bool m_immediateLock;
bool m_runtimeInitialized;
Authenticator *m_authenticator;
int m_graceTime;
bool m_noLock;
};
} // namespace
......
......@@ -64,9 +64,17 @@ int main(int argc, char* argv[])
i18n("Starts the greeter in testing mode"));
QCommandLineOption immediateLockOption(QStringLiteral("immediateLock"),
i18n("Lock immediately, ignoring any grace time etc."));
QCommandLineOption graceTimeOption(QStringLiteral("graceTime"),
i18n("Delay till the lock user interface gets shown in milliseconds."),
QStringLiteral("milliseconds"),
QStringLiteral("0"));
QCommandLineOption nolockOption(QStringLiteral("nolock"),
i18n("Don't show any lock user interface."));
parser.addOption(testingOption);
parser.addOption(immediateLockOption);
parser.addOption(graceTimeOption);
parser.addOption(nolockOption);
parser.process(app);
if (parser.isSet(testingOption)) {
......@@ -75,6 +83,12 @@ int main(int argc, char* argv[])
} else {
app.setImmediateLock(parser.isSet(immediateLockOption));
}
app.setNoLock(parser.isSet(nolockOption));
bool ok = false;
int graceTime = parser.value(graceTimeOption).toInt(&ok);
if (ok) {
app.setGraceTime(graceTime);
}
app.desktopResized();
// This allow ksmserver to know when the applicaion has actually finished setting itself up.
......
......@@ -340,6 +340,13 @@ bool KSldApp::startLockProcess(EstablishLock establishLock)
if (establishLock == EstablishLock::Immediate) {
args << "--immediateLock";
}
if (m_graceTimer->isActive()) {
args << "--graceTime";
args << QString::number(m_graceTimer->remainingTime());
}
if (m_lockGrace == -1) {
args << "--nolock";
}
m_lockProcess->start(QStringLiteral(KSCREENLOCKER_GREET_BIN), args);
// we wait one minute
if (!m_lockProcess->waitForStarted(60000)) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment