增加支持KylinOS
This commit is contained in:
parent
471b4c7b3b
commit
ac16f7d054
14
README.md
14
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
|
Service: com.deepin.dde.lockFront
|
||||||
Path: /com/deepin/dde/lockFront
|
Path: /com/deepin/dde/lockFront
|
||||||
Interface: com.deepin.dde.lockFront
|
Interface: com.deepin.dde.lockFront
|
||||||
Signals: Locked(), Unlocked()
|
Signals: Visible(bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
2. **GNOME ScreenSaver 接口**
|
2. **GNOME ScreenSaver 接口**
|
||||||
|
|
@ -224,12 +224,12 @@ export LD_LIBRARY_PATH=$HOME/sdk/qt-5.15.2/lib:$LD_LIBRARY_PATH
|
||||||
Signal: ActiveChanged(bool)
|
Signal: ActiveChanged(bool)
|
||||||
```
|
```
|
||||||
|
|
||||||
3. **systemd-logind 接口**
|
3. **KylinOS UKUI接口**
|
||||||
```
|
```
|
||||||
Service: org.freedesktop.login1
|
Service: org.ukui.ScreenSaver
|
||||||
Path: /org/freedesktop/login1/session/auto
|
Path: /
|
||||||
Interface: org.freedesktop.login1.Session
|
Interface: org.ukui.ScreenSaver
|
||||||
Signals: Lock(), Unlock()
|
Signals: lock(), unlock()
|
||||||
```
|
```
|
||||||
|
|
||||||
### macOS: 分布式通知中心
|
### macOS: 分布式通知中心
|
||||||
|
|
@ -447,4 +447,4 @@ Qt Screen Lock Detection Demo
|
||||||
|
|
||||||
## 反馈与贡献
|
## 反馈与贡献
|
||||||
|
|
||||||
如有问题或建议,欢迎提出!
|
如有问题或建议,欢迎提出!
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ bool ScreenLockDetector::initialize()
|
||||||
// 尝试连接到不同的DBus接口
|
// 尝试连接到不同的DBus接口
|
||||||
bool deepinOk = connectToDeepinDDE();
|
bool deepinOk = connectToDeepinDDE();
|
||||||
bool gnomeOk = connectToGnomeScreenSaver();
|
bool gnomeOk = connectToGnomeScreenSaver();
|
||||||
bool loginOk = connectToLoginManager();
|
bool loginOk = connectToUkuiManager();
|
||||||
|
|
||||||
if (!deepinOk && !gnomeOk && !loginOk) {
|
if (!deepinOk && !gnomeOk && !loginOk) {
|
||||||
qWarning() << "Failed to connect to any screen lock detection service";
|
qWarning() << "Failed to connect to any screen lock detection service";
|
||||||
|
|
@ -195,97 +195,54 @@ bool ScreenLockDetector::connectToGnomeScreenSaver()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenLockDetector::connectToLoginManager()
|
bool ScreenLockDetector::connectToUkuiManager()
|
||||||
{
|
{
|
||||||
qDebug() << "\n--- Connecting to Login Manager (systemd-logind) ---";
|
qDebug() << "\n--- Connecting to ukui ScreenSaver ---";
|
||||||
|
|
||||||
// 首先获取当前会话的路径
|
QString sessionPath = "/";
|
||||||
QString sessionPath = getCurrentSessionPath();
|
m_loginInterface = new QDBusInterface(
|
||||||
if (sessionPath.isEmpty()) {
|
"org.ukui.ScreenSaver",
|
||||||
qWarning() << "Could not determine current session path";
|
sessionPath,
|
||||||
qWarning() << "Will try to connect to generic session signals";
|
"org.ukui.ScreenSaver",
|
||||||
} else {
|
QDBusConnection::systemBus(),
|
||||||
qDebug() << "Current session path:" << sessionPath;
|
this
|
||||||
}
|
);
|
||||||
|
|
||||||
// 方法1: 连接到特定会话路径(如果获取到了)
|
if (m_loginInterface->isValid()) {
|
||||||
if (!sessionPath.isEmpty()) {
|
qDebug() << "ukui ScreenSaver interface is valid for session:" << sessionPath;
|
||||||
m_loginInterface = new QDBusInterface(
|
|
||||||
"org.freedesktop.login1",
|
// 连接Lock和Unlock信号到特定会话
|
||||||
|
bool lockConnected = QDBusConnection::systemBus().connect(
|
||||||
|
"org.ukui.ScreenSaver",
|
||||||
sessionPath,
|
sessionPath,
|
||||||
"org.freedesktop.login1.Session",
|
"org.ukui.ScreenSaver",
|
||||||
QDBusConnection::systemBus(),
|
"lock",
|
||||||
this
|
this,
|
||||||
|
SLOT(onSessionLocked())
|
||||||
);
|
);
|
||||||
|
|
||||||
if (m_loginInterface->isValid()) {
|
bool unlockConnected = QDBusConnection::systemBus().connect(
|
||||||
qDebug() << "Login Manager interface is valid for session:" << sessionPath;
|
"org.ukui.ScreenSaver",
|
||||||
|
sessionPath,
|
||||||
|
"org.ukui.ScreenSaver",
|
||||||
|
"unlock",
|
||||||
|
this,
|
||||||
|
SLOT(onSessionUnlocked())
|
||||||
|
);
|
||||||
|
|
||||||
// 连接Lock和Unlock信号到特定会话
|
qDebug() << "Session Lock signal connected:" << lockConnected;
|
||||||
bool lockConnected = QDBusConnection::systemBus().connect(
|
qDebug() << "Session Unlock signal connected:" << unlockConnected;
|
||||||
"org.freedesktop.login1",
|
|
||||||
sessionPath,
|
|
||||||
"org.freedesktop.login1.Session",
|
|
||||||
"Lock",
|
|
||||||
this,
|
|
||||||
SLOT(onSessionLocked())
|
|
||||||
);
|
|
||||||
|
|
||||||
bool unlockConnected = QDBusConnection::systemBus().connect(
|
if (lockConnected || unlockConnected) {
|
||||||
"org.freedesktop.login1",
|
m_loginConnected = true;
|
||||||
sessionPath,
|
qDebug() << "Successfully connected to Login Manager via session path";
|
||||||
"org.freedesktop.login1.Session",
|
return true;
|
||||||
"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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 方法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";
|
qWarning() << "Failed to connect to Login Manager signals";
|
||||||
|
delete m_loginInterface;
|
||||||
|
m_loginInterface = nullptr;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,10 +108,10 @@ private:
|
||||||
bool connectToGnomeScreenSaver();
|
bool connectToGnomeScreenSaver();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 连接到登录管理器的DBus接口
|
* @brief 连接KylinOS的DBus接口
|
||||||
* @return true 如果连接成功
|
* @return true 如果连接成功
|
||||||
*/
|
*/
|
||||||
bool connectToLoginManager();
|
bool connectToUkuiManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 连接到Deepin DDE的DBus接口
|
* @brief 连接到Deepin DDE的DBus接口
|
||||||
|
|
@ -148,4 +148,4 @@ private:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCREENLOCKDETECTOR_H
|
#endif // SCREENLOCKDETECTOR_H
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue