Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ include(${CMAKE_SOURCE_DIR}/cmake/TranslationUtils.cmake)
find_package(Dtk6 REQUIRED COMPONENTS Core Declarative SystemSettings Tools)
if (NOT DISABLE_DDM)
find_package(DDM 0.2.0 REQUIRED COMPONENTS Common)
if (DDM_VERSION VERSION_LESS 0.3.8)
add_compile_definitions(DDM_VERSION_LT_0_3_8)
endif()
endif()
find_package(QT NAMES Qt6 COMPONENTS Core REQUIRED)
find_package(Qt6 CONFIG REQUIRED ShaderTools Concurrent RemoteObjects Network)
Expand Down
7 changes: 3 additions & 4 deletions src/core/lockscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ LockScreen::LockScreen(ILockScreen *impl, SurfaceContainer *parent, GreeterProxy

void LockScreen::lock()
{
if (isVisible()) {
return;
}

// Do not early-return on isVisible(): the greeter may start in the
// undecided state (surface visible, not yet locked), so lock() must
// still flip the lock state afterwards.
setVisible(true);

if (!m_greeterProxy->isLocked())
Expand Down
47 changes: 46 additions & 1 deletion src/greeter/greeterproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@

// System
#include <security/pam_appl.h>
#include <systemd/sd-login.h>

Check warning on line 37 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <systemd/sd-login.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <pwd.h>

Check warning on line 38 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <pwd.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QTimer>

Check warning on line 40 in src/greeter/greeterproxy.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTimer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace DDM;

/////////////////////
Expand Down Expand Up @@ -120,6 +122,19 @@
connect(m_socket, &QLocalSocket::readyRead, this, &GreeterProxy::readyRead);
connect(m_socket, &QLocalSocket::errorOccurred, this, &GreeterProxy::error);

// Fallback: if DDM never decides (ShowGreeter / UserActivateMessage), show
// the greeter after a grace period instead of staying on the wallpaper.
m_undecidedTimer = new QTimer(this);
m_undecidedTimer->setSingleShot(true);
m_undecidedTimer->setInterval(5000);
connect(m_undecidedTimer, &QTimer::timeout, this, [this] {
if (m_undecided) {
qCWarning(lcTlGreeter) << "DDM did not decide in time, showing greeter by fallback";
lock();
}
});
m_undecidedTimer->start();

conn.connect(Logind::serviceName(),
Logind::managerPath(),
Logind::managerIfaceName(),
Expand Down Expand Up @@ -159,6 +174,11 @@
{
if (isLocked && !m_isLocked) {
m_isLocked = true;
if (m_undecided) {
m_undecided = false;
m_undecidedTimer->stop();
Q_EMIT undecidedChanged(false);
}
if (m_lockScreen && !m_lockScreen->isVisible())
m_lockScreen->lock();
Q_EMIT lockChanged(true);
Expand Down Expand Up @@ -290,7 +310,7 @@
return;
}

if (strcmp(service, "ddm") == 0) {
if (strncmp(service, "ddm", 3) == 0) {
QString user = QString::fromLocal8Bit(username);
qCInfo(lcTlGreeter) << "New session added: id=" << id << ", user=" << user;
userModel()->updateUserLoginState(user, true);
Expand Down Expand Up @@ -496,6 +516,14 @@
qCInfo(lcTlGreeter) << "switch to greeter";
lock();
} break;
#ifndef DDM_VERSION_LT_0_3_8
case DaemonMessages::ShowGreeter: {
qCInfo(lcTlGreeter) << "show greeter";
// Full lock screen transition (LockScreen mode, hidden workspace),
// matching the previous startup behavior of showLockScreen().
Helper::instance()->showLockScreen(false);
} break;
#endif
case DaemonMessages::UserActivateMessage: {
QString user;
int sessionId;
Expand All @@ -512,6 +540,23 @@
break;

qCInfo(lcTlGreeter) << "activate successfully: " << user << ", XDG_SESSION_ID: " << sessionId;

// DDM drives the direct login (autologin / unlock), so the greeter
// must hide unconditionally. onSessionNew's setLock(false) may never
// fire (currentUserName mismatch / session service not "ddm"). When
// still in the undecided state, the lock screen surface is visible
// (wallpaper) but not locked, so setLock(false) alone would no-op:
// restore the desktop mode and hide the surface explicitly.
if (m_undecided) {
m_undecided = false;
m_undecidedTimer->stop();
Q_EMIT undecidedChanged(false);
}
if (m_lockScreen && m_lockScreen->isVisible()) {
Q_EMIT m_lockScreen->unlock();
m_lockScreen->setVisible(false);
}
setLock(false);
} break;
case DaemonMessages::UserLoggedIn: {
QString user;
Expand Down
17 changes: 17 additions & 0 deletions src/greeter/greeterproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#include "QDBusContext"
#include <QDBusObjectPath>
#include <QObject>
#include <QQmlEngine>

Check warning on line 9 in src/greeter/greeterproxy.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QQmlEngine> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class QLocalSocket;
class QTimer;

class LockScreen;

Expand All @@ -34,6 +35,7 @@
Q_PROPERTY(bool canHybridSleep READ canHybridSleep NOTIFY canHybridSleepChanged)

Q_PROPERTY(bool isLocked READ isLocked NOTIFY lockChanged)
Q_PROPERTY(bool undecided READ undecided NOTIFY undecidedChanged)
Q_PROPERTY(int failedAttempts READ failedAttempts NOTIFY failedAttemptsChanged)
Q_PROPERTY(bool showShutdownView READ showShutdownView WRITE setShowShutdownView NOTIFY showShutdownViewChanged)
Q_PROPERTY(bool showAnimation READ showAnimation NOTIFY showAnimationChanged)
Expand Down Expand Up @@ -91,6 +93,16 @@
*/
inline bool isLocked() const { return m_isLocked; };

/**
* @brief Get whether DDM has not decided yet whether to show the greeter
* or to log in directly. The greeter surface (wallpaper) is shown but the
* login UI stays hidden until DDM sends ShowGreeter / UserActivateMessage,
* or the fallback timer fires.
*
* @return true if DDM has not decided yet
*/
inline bool undecided() const { return m_undecided; };

/**
* @brief Get the number of failed login attempts (password incorrect)
* The value is reset to 0 when unlocked successfully
Expand Down Expand Up @@ -275,6 +287,9 @@
/** @brief Emitted when lock state changes. See isLocked() */
void lockChanged (bool isLocked);

/** @brief Emitted when undecided state changes. See undecided() */
void undecidedChanged (bool undecided);

/** @brief Emitted when failed attempts changes. See failedAttempts() */
void failedAttemptsChanged (int failedAttempts);

Expand Down Expand Up @@ -324,6 +339,8 @@
bool m_canHybridSleep { false };

bool m_isLocked { false };
bool m_undecided { true };
QTimer *m_undecidedTimer{ nullptr };
int m_failedAttempts { 0 };
bool m_showShutdownView { false };
bool m_showAnimation { true };
Expand Down
9 changes: 9 additions & 0 deletions src/greeter/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ int UserModel::rowCount(const QModelIndex &parent) const

void UserModel::updateUserLoginState(const QString &username, bool loggedIn)
{
// TODO: May remove once UserModel is guaranteed to resolve every loggable
// user (consider whether users not manually added can still log in directly).
if (loggedIn && !getUser(username)) {
if (!tryAddNssUser(username)) {
qCWarning(lcTlGreeter) << "User" << username << "not found when updating login state";
return;
}
}

auto user = std::find_if(d->users.begin(), d->users.end(), [&username](const UserPtr &user) {
return user->userName() == username;
});
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/lockscreen/qml/Greeter.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FocusScope {
color: 'black'
opacity: 0.0
transformOrigin: Item.Center
state: (GreeterProxy.isLocked || GreeterProxy.showShutdownView) ? "Show" : "Hide"
state: (GreeterProxy.isLocked || GreeterProxy.undecided || GreeterProxy.showShutdownView) ? "Show" : "Hide"
states: [
State {
name: "Show"
Expand Down
Loading
Loading