Rename login interface to UKUI ScreenSaver

Replace m_loginInterface/m_loginConnected with
m_ukuiInterface/m_ukuiConnected, update connection/teardown logic and
log messages, and query lock state via UKUI's GetLockState method
instead of the previous login manager property call.
This commit is contained in:
ubuntu1804 2025-11-10 11:24:10 +08:00
parent eaa40929bd
commit bff9ded0fa
2 changed files with 25 additions and 36 deletions

View File

@ -16,10 +16,10 @@ ScreenLockDetector::ScreenLockDetector(QObject *parent)
, m_isLocked(false) , m_isLocked(false)
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
, m_gnomeInterface(nullptr) , m_gnomeInterface(nullptr)
, m_loginInterface(nullptr) , m_ukuiInterface(nullptr)
, m_deepinInterface(nullptr) , m_deepinInterface(nullptr)
, m_gnomeConnected(false) , m_gnomeConnected(false)
, m_loginConnected(false) , m_ukuiConnected(false)
, m_deepinConnected(false) , m_deepinConnected(false)
#endif #endif
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
@ -36,9 +36,9 @@ ScreenLockDetector::~ScreenLockDetector()
m_gnomeInterface = nullptr; m_gnomeInterface = nullptr;
} }
if (m_loginInterface) { if (m_ukuiInterface) {
delete m_loginInterface; delete m_ukuiInterface;
m_loginInterface = nullptr; m_ukuiInterface = nullptr;
} }
if (m_deepinInterface) { if (m_deepinInterface) {
@ -101,9 +101,9 @@ bool ScreenLockDetector::initialize()
// 尝试连接到不同的DBus接口 // 尝试连接到不同的DBus接口
bool deepinOk = connectToDeepinDDE(); bool deepinOk = connectToDeepinDDE();
bool gnomeOk = connectToGnomeScreenSaver(); bool gnomeOk = connectToGnomeScreenSaver();
bool loginOk = connectToUkuiManager(); bool ukuiOk = connectToUkuiManager();
if (!deepinOk && !gnomeOk && !loginOk) { if (!deepinOk && !gnomeOk && !ukuiOk) {
qWarning() << "Failed to connect to any screen lock detection service"; qWarning() << "Failed to connect to any screen lock detection service";
qWarning() << "Make sure you are running on a supported Linux desktop environment"; qWarning() << "Make sure you are running on a supported Linux desktop environment";
return false; return false;
@ -116,7 +116,7 @@ bool ScreenLockDetector::initialize()
qDebug() << "ScreenLockDetector initialized successfully on Linux"; qDebug() << "ScreenLockDetector initialized successfully on Linux";
qDebug() << "Deepin DDE connected:" << m_deepinConnected; qDebug() << "Deepin DDE connected:" << m_deepinConnected;
qDebug() << "GNOME ScreenSaver connected:" << m_gnomeConnected; qDebug() << "GNOME ScreenSaver connected:" << m_gnomeConnected;
qDebug() << "Login Manager connected:" << m_loginConnected; qDebug() << "UKUI ScreenSaver connected:" << m_ukuiConnected;
qDebug() << "================================================="; qDebug() << "=================================================";
return true; return true;
@ -200,7 +200,7 @@ bool ScreenLockDetector::connectToUkuiManager()
qDebug() << "\n--- Connecting to ukui ScreenSaver ---"; qDebug() << "\n--- Connecting to ukui ScreenSaver ---";
QString sessionPath = "/"; QString sessionPath = "/";
m_loginInterface = new QDBusInterface( m_ukuiInterface = new QDBusInterface(
"org.ukui.ScreenSaver", "org.ukui.ScreenSaver",
sessionPath, sessionPath,
"org.ukui.ScreenSaver", "org.ukui.ScreenSaver",
@ -208,7 +208,7 @@ bool ScreenLockDetector::connectToUkuiManager()
this this
); );
if (m_loginInterface->isValid()) { if (m_ukuiInterface->isValid()) {
qDebug() << "ukui ScreenSaver interface is valid for session:" << sessionPath; qDebug() << "ukui ScreenSaver interface is valid for session:" << sessionPath;
// 连接Lock和Unlock信号到特定会话 // 连接Lock和Unlock信号到特定会话
@ -234,15 +234,15 @@ bool ScreenLockDetector::connectToUkuiManager()
qDebug() << "Session Unlock signal connected:" << unlockConnected; qDebug() << "Session Unlock signal connected:" << unlockConnected;
if (lockConnected || unlockConnected) { if (lockConnected || unlockConnected) {
m_loginConnected = true; m_ukuiConnected = true;
qDebug() << "Successfully connected to Login Manager via session path"; qDebug() << "Successfully connected to UKUI ScreenSaver via session path";
return true; return true;
} }
} }
qWarning() << "Failed to connect to Login Manager signals"; qWarning() << "Failed to connect to UKUI ScreenSaver signals";
delete m_loginInterface; delete m_ukuiInterface;
m_loginInterface = nullptr; m_ukuiInterface = nullptr;
return false; return false;
} }
@ -383,26 +383,15 @@ void ScreenLockDetector::queryCurrentLockState()
} }
// 尝试从登录管理器查询锁定状态 // 尝试从登录管理器查询锁定状态
if (m_loginInterface && m_loginInterface->isValid()) { if (m_ukuiInterface && m_ukuiInterface->isValid()) {
qDebug() << "Querying Login Manager lock state..."; qDebug() << "Querying UKUI ScreenSaver lock state...";
// 尝试读取 LockedHint 属性 QDBusReply<bool> reply = m_ukuiInterface->call("GetLockState");
QDBusMessage msg = QDBusMessage::createMethodCall(
"org.freedesktop.login1",
m_loginInterface->path(),
"org.freedesktop.DBus.Properties",
"Get"
);
msg << "org.freedesktop.login1.Session" << "LockedHint";
QDBusReply<QVariant> reply = QDBusConnection::systemBus().call(msg);
if (reply.isValid()) { if (reply.isValid()) {
bool locked = reply.value().toBool(); bool active = reply.value();
qDebug() << " LockedHint property:" << (locked ? "LOCKED" : "UNLOCKED"); qDebug() << " Current UKUI ScreenSaver state:" << (active ? "ACTIVE/LOCKED" : "INACTIVE/UNLOCKED");
setLockState(locked); setLockState(active);
return; return;
} else {
qDebug() << " Could not read LockedHint:" << reply.error().message();
} }
} }

View File

@ -136,10 +136,10 @@ private:
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
QDBusInterface *m_gnomeInterface; // GNOME屏幕保护程序接口 QDBusInterface *m_gnomeInterface; // GNOME屏幕保护程序接口
QDBusInterface *m_loginInterface; // 登录管理器接口 QDBusInterface *m_ukuiInterface; // UKUI屏幕保护接口
QDBusInterface *m_deepinInterface; // Deepin DDE接口 QDBusInterface *m_deepinInterface; // Deepin DDE接口
bool m_gnomeConnected; // GNOME接口是否连接成功 bool m_gnomeConnected; // GNOME接口是否连接成功
bool m_loginConnected; // 登录管理器接口是否连接成功 bool m_ukuiConnected; // UKUI接口是否连接成功
bool m_deepinConnected; // Deepin DDE接口是否连接成功 bool m_deepinConnected; // Deepin DDE接口是否连接成功
#endif #endif