Skip to content

Commit

Permalink
refactor: don't lock when user already login
Browse files Browse the repository at this point in the history
as title

Log:
  • Loading branch information
justforlxz committed Nov 28, 2024
1 parent b2248cb commit 7c313e5
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion src/common/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
9 changes: 9 additions & 0 deletions src/daemon/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ namespace DDM {
void Display::switchToUser(const QString &user) {
auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
server->activateUser(user);

if (user == "dde") {
m_greeter->setUserActivated(false);
}
}

bool Display::start() {
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -635,6 +641,9 @@ namespace DDM {
auto* server = reinterpret_cast<SingleWaylandDisplayServer*>(m_displayServer);
// TODO: switch to greeter
server->activateUser("dde");

// TODO: only current user logout will reset greeter state
m_greeter->setUserActivated(false);
return;
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/daemon/Greeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace DDM {
m_singleMode = on;
}

void Greeter::setUserActivated(bool active) {

Check warning on line 79 in src/daemon/Greeter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setUserActivated' is never used.
m_userActivated = active;
}

QString Greeter::displayServerCommand() const

Check warning on line 83 in src/daemon/Greeter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'displayServerCommand' is never used.
{
return m_displayServerCmd;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/daemon/Greeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
Expand Down
33 changes: 4 additions & 29 deletions src/helper/singlewaylandhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

SingleWaylandHelper::SingleWaylandHelper(QObject *parent)

Check warning on line 11 in src/helper/singlewaylandhelper.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Member variable 'SingleWaylandHelper::m_process' is not initialized in the constructor.
: QObject(parent)
, m_wCompositorCrashCount(0)
, m_maxCrashCountLimit(3)
{}

bool SingleWaylandHelper::start(const QString &compositor, const QString &cmd)
Expand All @@ -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");
Expand All @@ -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<int, QProcess::ExitStatus>::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)) {
Expand Down
2 changes: 0 additions & 2 deletions src/helper/singlewaylandhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ class SingleWaylandHelper : public QObject {

private:
QProcess *m_process;
int m_wCompositorCrashCount;
int m_maxCrashCountLimit;
};

0 comments on commit 7c313e5

Please sign in to comment.