ScreenLockDetector/src/screenlockdetector.h

120 lines
3.0 KiB
C
Raw Normal View History

2025-11-07 10:56:45 +08:00
#ifndef SCREENLOCKDETECTOR_H
#define SCREENLOCKDETECTOR_H
#include <QObject>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDBusContext>
#include <QCoreApplication>
2025-11-07 10:56:45 +08:00
#include <QDebug>
/**
* @brief
*
* Linux系统的DBus信号来检测屏幕锁定/
2025-11-07 14:57:13 +08:00
* Deepin DDE, GNOME, KDE, XFCE等
2025-11-07 10:56:45 +08:00
*/
class ScreenLockDetector : public QObject, protected QDBusContext
2025-11-07 10:56:45 +08:00
{
Q_OBJECT
public:
explicit ScreenLockDetector(QObject *parent = nullptr);
~ScreenLockDetector();
/**
* @brief
* @return true false
*/
bool isScreenLocked() const;
/**
* @brief DBus连接
* @return true false
*/
bool initialize();
signals:
/**
* @brief
*
*/
void screenLocked();
/**
* @brief
*
*/
void screenUnlocked();
/**
* @brief
* @param locked true表示已锁定false表示已解锁
*/
void lockStateChanged(bool locked);
private slots:
/**
* @brief GNOME屏幕保护程序的DBus信号
* @param active
*/
void onScreenSaverActiveChanged(bool active);
/**
* @brief
*/
void onSessionLocked();
/**
* @brief
*/
void onSessionUnlocked();
private:
/**
* @brief
* @param locked
*/
void setLockState(bool locked);
/**
* @brief GNOME屏幕保护程序的DBus接口
* @return true
*/
bool connectToGnomeScreenSaver();
/**
* @brief DBus接口
* @return true
*/
bool connectToLoginManager();
2025-11-07 14:57:13 +08:00
/**
* @brief Deepin DDE的DBus接口
* @return true
*/
bool connectToDeepinDDE();
2025-11-07 10:56:45 +08:00
/**
* @brief
*/
void queryCurrentLockState();
/**
* @brief DBus
* @return
*/
QString getCurrentSessionPath();
2025-11-07 10:56:45 +08:00
private:
bool m_isLocked; // 当前锁屏状态
QDBusInterface *m_gnomeInterface; // GNOME屏幕保护程序接口
QDBusInterface *m_loginInterface; // 登录管理器接口
2025-11-07 14:57:13 +08:00
QDBusInterface *m_deepinInterface; // Deepin DDE接口
2025-11-07 10:56:45 +08:00
bool m_gnomeConnected; // GNOME接口是否连接成功
bool m_loginConnected; // 登录管理器接口是否连接成功
2025-11-07 14:57:13 +08:00
bool m_deepinConnected; // Deepin DDE接口是否连接成功
2025-11-07 10:56:45 +08:00
};
#endif // SCREENLOCKDETECTOR_H