2025-11-07 10:56:45 +08:00
|
|
|
#include "screenlockdetector.h"
|
2025-11-08 16:57:58 +08:00
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
#include "screenlockdetector_mac.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_LINUX
|
2025-11-07 10:56:45 +08:00
|
|
|
#include <QDBusMessage>
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
#include <QDBusConnectionInterface>
|
2025-11-07 15:47:48 +08:00
|
|
|
#include <QDBusReply>
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
2025-11-07 10:56:45 +08:00
|
|
|
|
|
|
|
|
ScreenLockDetector::ScreenLockDetector(QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, m_isLocked(false)
|
2025-11-08 16:57:58 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
2025-11-07 10:56:45 +08:00
|
|
|
, m_gnomeInterface(nullptr)
|
|
|
|
|
, m_loginInterface(nullptr)
|
2025-11-07 14:57:13 +08:00
|
|
|
, m_deepinInterface(nullptr)
|
2025-11-07 10:56:45 +08:00
|
|
|
, m_gnomeConnected(false)
|
|
|
|
|
, m_loginConnected(false)
|
2025-11-07 14:57:13 +08:00
|
|
|
, m_deepinConnected(false)
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
, m_macDetector(nullptr)
|
|
|
|
|
#endif
|
2025-11-07 10:56:45 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScreenLockDetector::~ScreenLockDetector()
|
|
|
|
|
{
|
2025-11-08 16:57:58 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
2025-11-07 10:56:45 +08:00
|
|
|
if (m_gnomeInterface) {
|
|
|
|
|
delete m_gnomeInterface;
|
|
|
|
|
m_gnomeInterface = nullptr;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
if (m_loginInterface) {
|
|
|
|
|
delete m_loginInterface;
|
|
|
|
|
m_loginInterface = nullptr;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
if (m_deepinInterface) {
|
|
|
|
|
delete m_deepinInterface;
|
|
|
|
|
m_deepinInterface = nullptr;
|
|
|
|
|
}
|
2025-11-08 16:57:58 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef Q_OS_MAC
|
|
|
|
|
if (m_macDetector) {
|
|
|
|
|
delete m_macDetector;
|
|
|
|
|
m_macDetector = nullptr;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenLockDetector::isScreenLocked() const
|
|
|
|
|
{
|
|
|
|
|
return m_isLocked;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenLockDetector::initialize()
|
|
|
|
|
{
|
2025-11-08 16:57:58 +08:00
|
|
|
#ifdef Q_OS_MAC
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "=================================================";
|
2025-11-08 16:57:58 +08:00
|
|
|
qDebug() << "Initializing ScreenLockDetector for macOS...";
|
|
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
|
|
|
|
|
// 创建 macOS 特定的检测器
|
|
|
|
|
m_macDetector = new ScreenLockDetectorMac(this);
|
|
|
|
|
|
|
|
|
|
// 连接信号
|
|
|
|
|
connect(m_macDetector, &ScreenLockDetectorMac::screenLocked,
|
|
|
|
|
this, &ScreenLockDetector::screenLocked);
|
|
|
|
|
connect(m_macDetector, &ScreenLockDetectorMac::screenUnlocked,
|
|
|
|
|
this, &ScreenLockDetector::screenUnlocked);
|
|
|
|
|
connect(m_macDetector, &ScreenLockDetectorMac::lockStateChanged,
|
|
|
|
|
this, [this](bool locked) {
|
|
|
|
|
m_isLocked = locked;
|
|
|
|
|
emit lockStateChanged(locked);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bool success = m_macDetector->initialize();
|
|
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
qDebug() << "ScreenLockDetector initialized successfully on macOS";
|
|
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "Failed to initialize ScreenLockDetector on macOS";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
|
|
|
|
|
#elif defined(Q_OS_LINUX)
|
|
|
|
|
qDebug() << "=================================================";
|
|
|
|
|
qDebug() << "Initializing ScreenLockDetector for Linux...";
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "=================================================";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
// 尝试连接到不同的DBus接口
|
2025-11-07 14:57:13 +08:00
|
|
|
bool deepinOk = connectToDeepinDDE();
|
2025-11-07 10:56:45 +08:00
|
|
|
bool gnomeOk = connectToGnomeScreenSaver();
|
2025-11-10 10:34:04 +08:00
|
|
|
bool loginOk = connectToUkuiManager();
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
if (!deepinOk && !gnomeOk && !loginOk) {
|
2025-11-07 10:56:45 +08:00
|
|
|
qWarning() << "Failed to connect to any screen lock detection service";
|
|
|
|
|
qWarning() << "Make sure you are running on a supported Linux desktop environment";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
// 查询当前锁屏状态
|
|
|
|
|
queryCurrentLockState();
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "=================================================";
|
2025-11-08 16:57:58 +08:00
|
|
|
qDebug() << "ScreenLockDetector initialized successfully on Linux";
|
2025-11-07 14:57:13 +08:00
|
|
|
qDebug() << "Deepin DDE connected:" << m_deepinConnected;
|
2025-11-07 10:56:45 +08:00
|
|
|
qDebug() << "GNOME ScreenSaver connected:" << m_gnomeConnected;
|
|
|
|
|
qDebug() << "Login Manager connected:" << m_loginConnected;
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "=================================================";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
return true;
|
2025-11-08 16:57:58 +08:00
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
qWarning() << "ScreenLockDetector: Unsupported platform";
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenLockDetector::setLockState(bool locked)
|
|
|
|
|
{
|
|
|
|
|
if (m_isLocked != locked) {
|
|
|
|
|
m_isLocked = locked;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
qDebug() << "## Screen lock state changed:" << (locked ? "LOCKED" : "UNLOCKED");
|
|
|
|
|
qDebug() << "##################################################";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-08 11:37:10 +08:00
|
|
|
emit lockStateChanged(locked);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
if (locked) {
|
|
|
|
|
emit screenLocked();
|
|
|
|
|
} else {
|
2025-11-08 11:37:10 +08:00
|
|
|
emit screenUnlocked();
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 16:57:58 +08:00
|
|
|
#ifdef Q_OS_LINUX
|
|
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
bool ScreenLockDetector::connectToGnomeScreenSaver()
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "\n--- Connecting to GNOME ScreenSaver ---";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
// 连接到GNOME屏幕保护程序的DBus接口
|
2025-11-07 10:56:45 +08:00
|
|
|
m_gnomeInterface = new QDBusInterface(
|
|
|
|
|
"org.gnome.ScreenSaver",
|
|
|
|
|
"/org/gnome/ScreenSaver",
|
|
|
|
|
"org.gnome.ScreenSaver",
|
|
|
|
|
QDBusConnection::sessionBus(),
|
|
|
|
|
this
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
if (!m_gnomeInterface->isValid()) {
|
2025-11-08 10:51:45 +08:00
|
|
|
qDebug() << "GNOME ScreenSaver interface not available:"
|
2025-11-07 10:56:45 +08:00
|
|
|
<< m_gnomeInterface->lastError().message();
|
|
|
|
|
delete m_gnomeInterface;
|
|
|
|
|
m_gnomeInterface = nullptr;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "GNOME ScreenSaver interface is valid";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
// 连接ActiveChanged信号
|
|
|
|
|
bool connected = QDBusConnection::sessionBus().connect(
|
|
|
|
|
"org.gnome.ScreenSaver",
|
|
|
|
|
"/org/gnome/ScreenSaver",
|
|
|
|
|
"org.gnome.ScreenSaver",
|
|
|
|
|
"ActiveChanged",
|
|
|
|
|
this,
|
|
|
|
|
SLOT(onScreenSaverActiveChanged(bool))
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "GNOME ActiveChanged signal connected:" << connected;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
if (!connected) {
|
|
|
|
|
qWarning() << "Failed to connect to GNOME ScreenSaver ActiveChanged signal";
|
|
|
|
|
delete m_gnomeInterface;
|
|
|
|
|
m_gnomeInterface = nullptr;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
m_gnomeConnected = true;
|
|
|
|
|
qDebug() << "Successfully connected to GNOME ScreenSaver";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-10 10:34:04 +08:00
|
|
|
bool ScreenLockDetector::connectToUkuiManager()
|
2025-11-07 10:56:45 +08:00
|
|
|
{
|
2025-11-10 10:34:04 +08:00
|
|
|
qDebug() << "\n--- Connecting to ukui ScreenSaver ---";
|
|
|
|
|
|
|
|
|
|
QString sessionPath = "/";
|
|
|
|
|
m_loginInterface = new QDBusInterface(
|
|
|
|
|
"org.ukui.ScreenSaver",
|
|
|
|
|
sessionPath,
|
|
|
|
|
"org.ukui.ScreenSaver",
|
2025-11-10 11:09:07 +08:00
|
|
|
QDBusConnection::sessionBus(),
|
2025-11-10 10:34:04 +08:00
|
|
|
this
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-10 10:34:04 +08:00
|
|
|
if (m_loginInterface->isValid()) {
|
|
|
|
|
qDebug() << "ukui ScreenSaver interface is valid for session:" << sessionPath;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-10 10:34:04 +08:00
|
|
|
// 连接Lock和Unlock信号到特定会话
|
2025-11-10 11:09:07 +08:00
|
|
|
bool lockConnected = QDBusConnection::sessionBus().connect(
|
2025-11-10 10:34:04 +08:00
|
|
|
"org.ukui.ScreenSaver",
|
2025-11-07 15:47:48 +08:00
|
|
|
sessionPath,
|
2025-11-10 10:34:04 +08:00
|
|
|
"org.ukui.ScreenSaver",
|
|
|
|
|
"lock",
|
|
|
|
|
this,
|
|
|
|
|
SLOT(onSessionLocked())
|
2025-11-07 15:47:48 +08:00
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-10 11:09:07 +08:00
|
|
|
bool unlockConnected = QDBusConnection::sessionBus().connect(
|
2025-11-10 10:34:04 +08:00
|
|
|
"org.ukui.ScreenSaver",
|
|
|
|
|
sessionPath,
|
|
|
|
|
"org.ukui.ScreenSaver",
|
|
|
|
|
"unlock",
|
|
|
|
|
this,
|
|
|
|
|
SLOT(onSessionUnlocked())
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-10 10:34:04 +08:00
|
|
|
qDebug() << "Session Lock signal connected:" << lockConnected;
|
|
|
|
|
qDebug() << "Session Unlock signal connected:" << unlockConnected;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-10 10:34:04 +08:00
|
|
|
if (lockConnected || unlockConnected) {
|
|
|
|
|
m_loginConnected = true;
|
|
|
|
|
qDebug() << "Successfully connected to Login Manager via session path";
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qWarning() << "Failed to connect to Login Manager signals";
|
2025-11-10 10:34:04 +08:00
|
|
|
delete m_loginInterface;
|
|
|
|
|
m_loginInterface = nullptr;
|
2025-11-07 15:47:48 +08:00
|
|
|
return false;
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
QString ScreenLockDetector::getCurrentSessionPath()
|
2025-11-07 14:57:13 +08:00
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
// 尝试从环境变量获取
|
|
|
|
|
QString xdgSessionId = qgetenv("XDG_SESSION_ID");
|
|
|
|
|
if (!xdgSessionId.isEmpty()) {
|
|
|
|
|
QString path = QString("/org/freedesktop/login1/session/%1").arg(xdgSessionId);
|
|
|
|
|
qDebug() << "Session path from XDG_SESSION_ID:" << path;
|
|
|
|
|
return path;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
// 尝试通过DBus调用获取当前会话
|
|
|
|
|
QDBusInterface managerIface(
|
|
|
|
|
"org.freedesktop.login1",
|
|
|
|
|
"/org/freedesktop/login1",
|
|
|
|
|
"org.freedesktop.login1.Manager",
|
|
|
|
|
QDBusConnection::systemBus()
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
if (managerIface.isValid()) {
|
|
|
|
|
// 获取当前用户的会话列表
|
|
|
|
|
QDBusReply<QDBusObjectPath> reply = managerIface.call("GetSessionByPID", (quint32)QCoreApplication::applicationPid());
|
|
|
|
|
if (reply.isValid()) {
|
|
|
|
|
QString path = reply.value().path();
|
|
|
|
|
qDebug() << "Session path from GetSessionByPID:" << path;
|
|
|
|
|
return path;
|
|
|
|
|
} else {
|
|
|
|
|
qDebug() << "GetSessionByPID failed:" << reply.error().message();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
return QString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ScreenLockDetector::connectToDeepinDDE()
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "\n--- Connecting to Deepin DDE ---";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
// 可能的服务配置列表
|
|
|
|
|
struct DeepinService {
|
|
|
|
|
QString service;
|
|
|
|
|
QString path;
|
|
|
|
|
QString interface;
|
|
|
|
|
QString lockSignal;
|
|
|
|
|
QString unlockSignal;
|
|
|
|
|
};
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
QList<DeepinService> services = {
|
|
|
|
|
// Deepin 20/23 主要接口
|
2025-11-08 09:56:34 +08:00
|
|
|
{"com.deepin.dde.lockFront", "/com/deepin/dde/lockFront", "com.deepin.dde.lockFront", "Visible", "Visible"},
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
// 备用接口
|
2025-11-08 09:56:34 +08:00
|
|
|
{"com.deepin.daemon.ScreenSaver", "/com/deepin/daemon/ScreenSaver", "com.deepin.daemon.ScreenSaver", "ActiveChanged", "ActiveChanged"},
|
2025-11-07 14:57:13 +08:00
|
|
|
};
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
for (const auto& svc : services) {
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "Trying Deepin service:" << svc.service;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
m_deepinInterface = new QDBusInterface(
|
|
|
|
|
svc.service,
|
|
|
|
|
svc.path,
|
|
|
|
|
svc.interface,
|
|
|
|
|
QDBusConnection::sessionBus(),
|
|
|
|
|
this
|
|
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
if (!m_deepinInterface->isValid()) {
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << " Interface not available:" << m_deepinInterface->lastError().message();
|
2025-11-07 14:57:13 +08:00
|
|
|
delete m_deepinInterface;
|
|
|
|
|
m_deepinInterface = nullptr;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << " Interface is valid, connecting signals...";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
// 尝试连接锁屏信号
|
2025-11-08 09:56:34 +08:00
|
|
|
bool visibleConnected = QDBusConnection::sessionBus().connect(
|
2025-11-07 14:57:13 +08:00
|
|
|
svc.service,
|
|
|
|
|
svc.path,
|
|
|
|
|
svc.interface,
|
|
|
|
|
svc.lockSignal,
|
|
|
|
|
this,
|
2025-11-08 09:56:34 +08:00
|
|
|
SLOT(onLockFrontVisible(bool))
|
2025-11-07 14:57:13 +08:00
|
|
|
);
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-08 09:56:34 +08:00
|
|
|
qDebug() << " Visible signal (" << svc.lockSignal << ") connected:" << visibleConnected;
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-08 09:56:34 +08:00
|
|
|
if (visibleConnected) {
|
2025-11-07 14:57:13 +08:00
|
|
|
m_deepinConnected = true;
|
|
|
|
|
qDebug() << "Successfully connected to Deepin DDE via" << svc.service;
|
2025-11-08 09:56:34 +08:00
|
|
|
qDebug() << "Listening for signals:" << svc.lockSignal;
|
2025-11-07 14:57:13 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qWarning() << " Failed to connect signals for" << svc.service;
|
2025-11-07 14:57:13 +08:00
|
|
|
delete m_deepinInterface;
|
|
|
|
|
m_deepinInterface = nullptr;
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
qWarning() << "Failed to connect to any Deepin DDE lock service";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
void ScreenLockDetector::queryCurrentLockState()
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "\n--- Querying current lock state ---";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
// 尝试从Deepin DDE查询当前状态
|
|
|
|
|
if (m_deepinInterface && m_deepinInterface->isValid()) {
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "Querying Deepin DDE lock state...";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 14:57:13 +08:00
|
|
|
QStringList possibleMethods = {"GetLocked", "IsLocked", "GetActive", "GetSessionLocked"};
|
|
|
|
|
for (const QString& method : possibleMethods) {
|
|
|
|
|
QDBusReply<bool> reply = m_deepinInterface->call(method);
|
|
|
|
|
if (reply.isValid()) {
|
|
|
|
|
bool locked = reply.value();
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << " Method" << method << "returned:" << (locked ? "LOCKED" : "UNLOCKED");
|
2025-11-07 14:57:13 +08:00
|
|
|
setLockState(locked);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << " No query method worked, waiting for signals";
|
2025-11-07 14:57:13 +08:00
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
// 尝试从GNOME屏幕保护程序查询当前状态
|
|
|
|
|
if (m_gnomeInterface && m_gnomeInterface->isValid()) {
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "Querying GNOME ScreenSaver state...";
|
2025-11-07 10:56:45 +08:00
|
|
|
QDBusReply<bool> reply = m_gnomeInterface->call("GetActive");
|
|
|
|
|
if (reply.isValid()) {
|
|
|
|
|
bool active = reply.value();
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << " Current GNOME ScreenSaver state:" << (active ? "ACTIVE/LOCKED" : "INACTIVE/UNLOCKED");
|
2025-11-07 10:56:45 +08:00
|
|
|
setLockState(active);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
// 尝试从登录管理器查询锁定状态
|
|
|
|
|
if (m_loginInterface && m_loginInterface->isValid()) {
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "Querying Login Manager lock state...";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
// 尝试读取 LockedHint 属性
|
|
|
|
|
QDBusMessage msg = QDBusMessage::createMethodCall(
|
|
|
|
|
"org.freedesktop.login1",
|
|
|
|
|
m_loginInterface->path(),
|
|
|
|
|
"org.freedesktop.DBus.Properties",
|
|
|
|
|
"Get"
|
|
|
|
|
);
|
|
|
|
|
msg << "org.freedesktop.login1.Session" << "LockedHint";
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
QDBusReply<QVariant> reply = QDBusConnection::systemBus().call(msg);
|
2025-11-07 10:56:45 +08:00
|
|
|
if (reply.isValid()) {
|
2025-11-07 15:47:48 +08:00
|
|
|
bool locked = reply.value().toBool();
|
|
|
|
|
qDebug() << " LockedHint property:" << (locked ? "LOCKED" : "UNLOCKED");
|
|
|
|
|
setLockState(locked);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
qDebug() << " Could not read LockedHint:" << reply.error().message();
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "Could not query initial lock state, will detect on next lock/unlock event";
|
2025-11-07 10:56:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenLockDetector::onScreenSaverActiveChanged(bool active)
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
qDebug() << "## GNOME ScreenSaver ActiveChanged signal received";
|
|
|
|
|
qDebug() << "## New state:" << (active ? "ACTIVE (LOCKED)" : "INACTIVE (UNLOCKED)");
|
|
|
|
|
qDebug() << "##################################################";
|
2025-11-07 10:56:45 +08:00
|
|
|
setLockState(active);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-08 09:56:34 +08:00
|
|
|
void ScreenLockDetector::onLockFrontVisible(bool visible)
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
qDebug() << "## DEEPIN LockFront Visible signal received";
|
|
|
|
|
qDebug() << "## New state:" << (visible ? "ACTIVE (LOCKED)" : "INACTIVE (UNLOCKED)");
|
|
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
setLockState(visible);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-07 10:56:45 +08:00
|
|
|
void ScreenLockDetector::onSessionLocked()
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
qDebug() << "## LOCK SIGNAL RECEIVED";
|
|
|
|
|
qDebug() << "## Screen is now LOCKED";
|
|
|
|
|
qDebug() << "## Sender:" << sender();
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
// 获取信号发送者的详细信息
|
|
|
|
|
QDBusMessage msg = QDBusContext::message();
|
|
|
|
|
if (msg.type() != QDBusMessage::InvalidMessage) {
|
|
|
|
|
qDebug() << "## DBus Message Details:";
|
|
|
|
|
qDebug() << "## Service:" << msg.service();
|
|
|
|
|
qDebug() << "## Path:" << msg.path();
|
|
|
|
|
qDebug() << "## Interface:" << msg.interface();
|
|
|
|
|
qDebug() << "## Member:" << msg.member();
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
2025-11-07 10:56:45 +08:00
|
|
|
setLockState(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ScreenLockDetector::onSessionUnlocked()
|
|
|
|
|
{
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
|
|
|
|
qDebug() << "## UNLOCK SIGNAL RECEIVED";
|
|
|
|
|
qDebug() << "## Screen is now UNLOCKED";
|
|
|
|
|
qDebug() << "## Sender:" << sender();
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
// 获取信号发送者的详细信息
|
|
|
|
|
QDBusMessage msg = QDBusContext::message();
|
|
|
|
|
if (msg.type() != QDBusMessage::InvalidMessage) {
|
|
|
|
|
qDebug() << "## DBus Message Details:";
|
|
|
|
|
qDebug() << "## Service:" << msg.service();
|
|
|
|
|
qDebug() << "## Path:" << msg.path();
|
|
|
|
|
qDebug() << "## Interface:" << msg.interface();
|
|
|
|
|
qDebug() << "## Member:" << msg.member();
|
|
|
|
|
}
|
2025-11-08 10:51:45 +08:00
|
|
|
|
2025-11-07 15:47:48 +08:00
|
|
|
qDebug() << "##################################################";
|
2025-11-07 10:56:45 +08:00
|
|
|
setLockState(false);
|
2025-11-08 10:51:45 +08:00
|
|
|
}
|
2025-11-08 16:57:58 +08:00
|
|
|
|
2025-11-10 11:09:07 +08:00
|
|
|
#endif // Q_OS_LINUX
|