-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocusmanager.h
More file actions
49 lines (36 loc) · 1.63 KB
/
focusmanager.h
File metadata and controls
49 lines (36 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef FOCUSMANAGER_H
#define FOCUSMANAGER_H
#include <QObject>
#include <QDateTime>
#include <QDebug>
class FocusManager : public QObject
{
Q_OBJECT
public:
explicit FocusManager(QObject *parent = nullptr);
public slots:
// 记录窗口获得焦点
void recordFocusGained(const QString &windowId);
// 记录窗口失去焦点
void recordFocusLost(const QString &windowId);
// 获取当前精确时间字符串
QString getCurrentTimeString();
// 获取全局最后失去焦点的时间
QDateTime getLastFocusLostTime() const { return m_lastFocusLostTime; }
// 获取当前有焦点的窗口ID
QString getCurrentFocusedWindow() const { return m_currentFocusedWindow; }
// 检查获得焦点的时间差是否应该显示(如果获得焦点和失去焦点时间相近,说明是应用内切换)
bool shouldShowTimeDiff(const QDateTime &gainTime) const;
signals:
// 焦点状态变化信号
void focusChanged(const QString &windowId, bool hasFocus, const QString ×tamp);
private:
// 输出日志到控制台
void logToConsole(const QString &windowId, const QString &action, const QString ×tamp);
// 记录状态
QString m_currentFocusedWindow; // 当前有焦点的窗口ID(空字符串表示没有窗口有焦点)
QDateTime m_lastFocusLostTime; // 全局最后失去焦点的时间
QDateTime m_lastFocusGainTime; // 记录最后一次获得焦点的时间,用于判断是否是应用内切换
int m_focusedWindowCount; // 当前有焦点的窗口数量(用于调试)
};
#endif // FOCUSMANAGER_H