From 7c313e502d9a4fdb4dfc0835db4c4968755496b0 Mon Sep 17 00:00:00 2001 From: Zhang Dingyuan Date: Wed, 27 Nov 2024 11:33:44 +0800 Subject: [PATCH] refactor: don't lock when user already login as title Log: --- src/common/Configuration.h | 2 +- src/daemon/Display.cpp | 9 ++++++++ src/daemon/Greeter.cpp | 21 ++++++++++++++++++- src/daemon/Greeter.h | 2 ++ src/helper/singlewaylandhelper.cpp | 33 ++++-------------------------- src/helper/singlewaylandhelper.h | 2 -- 6 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/common/Configuration.h b/src/common/Configuration.h index 5c713d3..011f1a3 100644 --- a/src/common/Configuration.h +++ b/src/common/Configuration.h @@ -87,7 +87,7 @@ namespace DDM { ); Section(Single, - Entry(CompositorCommand, QString, _S("treeland --lockscreen"), _S("Path of the Wayland compositor to execute when starting the greeter")); + Entry(CompositorCommand, QString, _S("treeland"), _S("Path of the Wayland compositor to execute when starting the greeter")); Entry(SessionDir, QStringList, {_S("/usr/local/share/wayland-sessions"), _S("/usr/share/wayland-sessions")}, _S("Comma-separated list of directories containing available Wayland sessions")); Entry(SessionCommand, QString, _S(WAYLAND_SESSION_COMMAND), _S("Path to a script to execute when starting the desktop session")); diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp index a422c3d..ba790be 100644 --- a/src/daemon/Display.cpp +++ b/src/daemon/Display.cpp @@ -208,6 +208,10 @@ namespace DDM { void Display::switchToUser(const QString &user) { auto* server = reinterpret_cast(m_displayServer); server->activateUser(user); + + if (user == "dde") { + m_greeter->setUserActivated(false); + } } bool Display::start() { @@ -554,6 +558,8 @@ namespace DDM { Q_ASSERT(auth && auth->identifyOnly() == identifyOnly); + m_greeter->setUserActivated(success); + if (success) { if (!m_reuseSessionId.isNull()) { OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus()); @@ -635,6 +641,9 @@ namespace DDM { auto* server = reinterpret_cast(m_displayServer); // TODO: switch to greeter server->activateUser("dde"); + + // TODO: only current user logout will reset greeter state + m_greeter->setUserActivated(false); return; } } diff --git a/src/daemon/Greeter.cpp b/src/daemon/Greeter.cpp index 21606bb..568a5e4 100644 --- a/src/daemon/Greeter.cpp +++ b/src/daemon/Greeter.cpp @@ -76,6 +76,10 @@ namespace DDM { m_singleMode = on; } + void Greeter::setUserActivated(bool active) { + m_userActivated = active; + } + QString Greeter::displayServerCommand() const { return m_displayServerCmd; @@ -230,7 +234,11 @@ namespace DDM { // start greeter m_auth->setUser(QStringLiteral("dde")); - m_auth->setDisplayServerCommand(m_displayServerCmd); + QString displayServerCmd = m_displayServerCmd; + if (m_singleMode) { + displayServerCmd += " --lockscreen"; + } + m_auth->setDisplayServerCommand(displayServerCmd); m_auth->setGreeter(true); m_auth->setSession(cmd.join(QLatin1Char(' '))); m_auth->setSingleMode(m_singleMode); @@ -314,6 +322,17 @@ namespace DDM { } void Greeter::onHelperFinished(Auth::HelperExitStatus status) { + if (m_singleMode) { + qDebug() << "Restart treeland"; + QString displayServerCmd = m_displayServerCmd; + if (!m_userActivated) { + displayServerCmd += " --lockscreen"; + } + m_auth->setDisplayServerCommand(displayServerCmd); + m_auth->start(); + return; + } + // reset flag m_started = false; diff --git a/src/daemon/Greeter.h b/src/daemon/Greeter.h index 23e2ad4..1db6a96 100644 --- a/src/daemon/Greeter.h +++ b/src/daemon/Greeter.h @@ -41,6 +41,7 @@ namespace DDM { void setSocket(const QString &socket); void setTheme(const QString &theme); void setSingleMode(bool on = true); + void setUserActivated(bool active); QString displayServerCommand() const; void setDisplayServerCommand(const QString &cmd); @@ -69,6 +70,7 @@ namespace DDM { private: bool m_started { false }; bool m_singleMode { false }; + bool m_userActivated { false }; int m_maxRetry{ 3 }; Display * const m_display { nullptr }; diff --git a/src/helper/singlewaylandhelper.cpp b/src/helper/singlewaylandhelper.cpp index 9e81767..1b7d761 100644 --- a/src/helper/singlewaylandhelper.cpp +++ b/src/helper/singlewaylandhelper.cpp @@ -10,8 +10,6 @@ SingleWaylandHelper::SingleWaylandHelper(QObject *parent) : QObject(parent) - , m_wCompositorCrashCount(0) - , m_maxCrashCountLimit(3) {} bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd) @@ -21,6 +19,9 @@ bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd) m_process = new QProcess(this); m_process->setProgram(compositor); m_process->setArguments(args); + m_process->setStandardOutputFile(QProcess::nullDevice()); + m_process->setStandardErrorFile(QProcess::nullDevice()); + m_process->setStandardInputFile(QProcess::nullDevice()); m_process->setProcessEnvironment([]{ auto env = QProcessEnvironment::systemEnvironment(); env.insert("LIBSEAT_BACKEND", "seatd"); @@ -31,34 +32,8 @@ bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd) return env; }()); - connect(m_process, &QProcess::readyReadStandardError, this, [this] { - qWarning() << m_process->readAllStandardError(); - }); - connect(m_process, &QProcess::readyReadStandardOutput, this, [this] { - qInfo() << m_process->readAllStandardOutput(); - }); connect(m_process, QOverload::of(&QProcess::finished), - m_process, [this](int exitCode, QProcess::ExitStatus exitStatus) { - qDebug() << "kwin_wayland exit with exitCode:" << exitCode << exitStatus; - if (exitCode == 0) { - qApp->quit(); - return; - } else if (exitCode == 133) { - m_wCompositorCrashCount = 0; - } else { - m_wCompositorCrashCount++; - } - - if (m_wCompositorCrashCount > m_maxCrashCountLimit) { - qApp->quit(); - return; - } - - qWarning() << "WAYLAND Restart count: " << QByteArray::number(m_wCompositorCrashCount); - - // restart - m_process->start(); - }); + qApp, &QCoreApplication::quit); m_process->start(); if (!m_process->waitForStarted(10000)) { diff --git a/src/helper/singlewaylandhelper.h b/src/helper/singlewaylandhelper.h index 871c700..b786420 100644 --- a/src/helper/singlewaylandhelper.h +++ b/src/helper/singlewaylandhelper.h @@ -14,6 +14,4 @@ class SingleWaylandHelper : public QObject { private: QProcess *m_process; - int m_wCompositorCrashCount; - int m_maxCrashCountLimit; };