From ac16f7d0547dfd958d6ade7d637f3a94df2ba9f5 Mon Sep 17 00:00:00 2001 From: ubuntu1804 Date: Mon, 10 Nov 2025 10:34:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=94=AF=E6=8C=81KylinOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++--- src/screenlockdetector.cpp | 117 ++++++++++++------------------------- src/screenlockdetector.h | 6 +- 3 files changed, 47 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index 0e429b1..ac918e5 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,7 @@ export LD_LIBRARY_PATH=$HOME/sdk/qt-5.15.2/lib:$LD_LIBRARY_PATH Service: com.deepin.dde.lockFront Path: /com/deepin/dde/lockFront Interface: com.deepin.dde.lockFront - Signals: Locked(), Unlocked() + Signals: Visible(bool) ``` 2. **GNOME ScreenSaver 接口** @@ -224,12 +224,12 @@ export LD_LIBRARY_PATH=$HOME/sdk/qt-5.15.2/lib:$LD_LIBRARY_PATH Signal: ActiveChanged(bool) ``` -3. **systemd-logind 接口** +3. **KylinOS UKUI接口** ``` - Service: org.freedesktop.login1 - Path: /org/freedesktop/login1/session/auto - Interface: org.freedesktop.login1.Session - Signals: Lock(), Unlock() + Service: org.ukui.ScreenSaver + Path: / + Interface: org.ukui.ScreenSaver + Signals: lock(), unlock() ``` ### macOS: 分布式通知中心 @@ -447,4 +447,4 @@ Qt Screen Lock Detection Demo ## 反馈与贡献 -如有问题或建议,欢迎提出! \ No newline at end of file +如有问题或建议,欢迎提出! diff --git a/src/screenlockdetector.cpp b/src/screenlockdetector.cpp index 7a46ec3..35cc66b 100644 --- a/src/screenlockdetector.cpp +++ b/src/screenlockdetector.cpp @@ -101,7 +101,7 @@ bool ScreenLockDetector::initialize() // 尝试连接到不同的DBus接口 bool deepinOk = connectToDeepinDDE(); bool gnomeOk = connectToGnomeScreenSaver(); - bool loginOk = connectToLoginManager(); + bool loginOk = connectToUkuiManager(); if (!deepinOk && !gnomeOk && !loginOk) { qWarning() << "Failed to connect to any screen lock detection service"; @@ -195,97 +195,54 @@ bool ScreenLockDetector::connectToGnomeScreenSaver() return true; } -bool ScreenLockDetector::connectToLoginManager() +bool ScreenLockDetector::connectToUkuiManager() { - qDebug() << "\n--- Connecting to Login Manager (systemd-logind) ---"; + qDebug() << "\n--- Connecting to ukui ScreenSaver ---"; - // 首先获取当前会话的路径 - QString sessionPath = getCurrentSessionPath(); - if (sessionPath.isEmpty()) { - qWarning() << "Could not determine current session path"; - qWarning() << "Will try to connect to generic session signals"; - } else { - qDebug() << "Current session path:" << sessionPath; - } + QString sessionPath = "/"; + m_loginInterface = new QDBusInterface( + "org.ukui.ScreenSaver", + sessionPath, + "org.ukui.ScreenSaver", + QDBusConnection::systemBus(), + this + ); - // 方法1: 连接到特定会话路径(如果获取到了) - if (!sessionPath.isEmpty()) { - m_loginInterface = new QDBusInterface( - "org.freedesktop.login1", + if (m_loginInterface->isValid()) { + qDebug() << "ukui ScreenSaver interface is valid for session:" << sessionPath; + + // 连接Lock和Unlock信号到特定会话 + bool lockConnected = QDBusConnection::systemBus().connect( + "org.ukui.ScreenSaver", sessionPath, - "org.freedesktop.login1.Session", - QDBusConnection::systemBus(), - this + "org.ukui.ScreenSaver", + "lock", + this, + SLOT(onSessionLocked()) ); - if (m_loginInterface->isValid()) { - qDebug() << "Login Manager interface is valid for session:" << sessionPath; + bool unlockConnected = QDBusConnection::systemBus().connect( + "org.ukui.ScreenSaver", + sessionPath, + "org.ukui.ScreenSaver", + "unlock", + this, + SLOT(onSessionUnlocked()) + ); - // 连接Lock和Unlock信号到特定会话 - bool lockConnected = QDBusConnection::systemBus().connect( - "org.freedesktop.login1", - sessionPath, - "org.freedesktop.login1.Session", - "Lock", - this, - SLOT(onSessionLocked()) - ); + qDebug() << "Session Lock signal connected:" << lockConnected; + qDebug() << "Session Unlock signal connected:" << unlockConnected; - bool unlockConnected = QDBusConnection::systemBus().connect( - "org.freedesktop.login1", - sessionPath, - "org.freedesktop.login1.Session", - "Unlock", - this, - SLOT(onSessionUnlocked()) - ); - - qDebug() << "Session Lock signal connected:" << lockConnected; - qDebug() << "Session Unlock signal connected:" << unlockConnected; - - if (lockConnected || unlockConnected) { - m_loginConnected = true; - qDebug() << "Successfully connected to Login Manager via session path"; - return true; - } - } else { - qDebug() << "Login Manager interface not valid:" << m_loginInterface->lastError().message(); - delete m_loginInterface; - m_loginInterface = nullptr; + if (lockConnected || unlockConnected) { + m_loginConnected = true; + qDebug() << "Successfully connected to Login Manager via session path"; + return true; } } - // 方法2: 监听所有会话的Lock/Unlock信号(不指定具体路径) - qDebug() << "Attempting to connect to all login1 Session signals..."; - - bool lockConnected = QDBusConnection::systemBus().connect( - "org.freedesktop.login1", - "", // 空路径表示监听所有对象 - "org.freedesktop.login1.Session", - "Lock", - this, - SLOT(onSessionLocked()) - ); - - bool unlockConnected = QDBusConnection::systemBus().connect( - "org.freedesktop.login1", - "", // 空路径表示监听所有对象 - "org.freedesktop.login1.Session", - "Unlock", - this, - SLOT(onSessionUnlocked()) - ); - - qDebug() << "Generic Lock signal connected:" << lockConnected; - qDebug() << "Generic Unlock signal connected:" << unlockConnected; - - if (lockConnected || unlockConnected) { - m_loginConnected = true; - qDebug() << "Successfully connected to Login Manager via generic signals"; - return true; - } - qWarning() << "Failed to connect to Login Manager signals"; + delete m_loginInterface; + m_loginInterface = nullptr; return false; } diff --git a/src/screenlockdetector.h b/src/screenlockdetector.h index ee1e54d..82dddc9 100644 --- a/src/screenlockdetector.h +++ b/src/screenlockdetector.h @@ -108,10 +108,10 @@ private: bool connectToGnomeScreenSaver(); /** - * @brief 连接到登录管理器的DBus接口 + * @brief 连接KylinOS的DBus接口 * @return true 如果连接成功 */ - bool connectToLoginManager(); + bool connectToUkuiManager(); /** * @brief 连接到Deepin DDE的DBus接口 @@ -148,4 +148,4 @@ private: #endif }; -#endif // SCREENLOCKDETECTOR_H \ No newline at end of file +#endif // SCREENLOCKDETECTOR_H