Track and display frame counts during lock

Add m_lastLockFrameCount and m_lockPaintFrameCount, compute frames
painted while the screen was locked and log the values. Show frame
counts in the lock info overlay, record frame count at lock, and reduce
the lock info font size for better layout.
This commit is contained in:
ubuntu1804 2025-11-08 12:21:25 +08:00
parent 7e468e0232
commit 16d1d8d73d
2 changed files with 19 additions and 6 deletions

View File

@ -13,6 +13,8 @@ CustomWidget::CustomWidget(QWidget *parent)
, m_wavePhase(0.0)
, m_startTime(QDateTime::currentDateTime())
, m_lastLockDuration(0)
, m_lastLockFrameCount(0)
, m_lockPaintFrameCount(0)
, m_lockCount(0)
{
// 设置窗口属性
@ -47,7 +49,11 @@ void CustomWidget::setPaintingEnabled(bool enabled)
if (m_lastLockTime.isValid()) {
QDateTime unlockTime = QDateTime::currentDateTime();
m_lastLockDuration = m_lastLockTime.secsTo(unlockTime);
// 计算锁屏期间绘制的帧数通常应该是0或很小
m_lockPaintFrameCount = m_frameCount - m_lastLockFrameCount;
qDebug() << "Screen was locked for" << m_lastLockDuration << "seconds";
qDebug() << "Frames at lock:" << m_lastLockFrameCount
<< "- Frames painted during lock:" << m_lockPaintFrameCount;
}
m_startTime = QDateTime::currentDateTime();
@ -58,9 +64,11 @@ void CustomWidget::setPaintingEnabled(bool enabled)
// 锁屏:记录锁屏时间
m_pauseTime = QDateTime::currentDateTime();
m_lastLockTime = m_pauseTime;
m_lastLockFrameCount = m_frameCount;
m_lockCount++;
qDebug() << "Screen locked at" << m_lastLockTime.toString("yyyy-MM-dd hh:mm:ss")
<< "- Lock count:" << m_lockCount;
<< "- Lock count:" << m_lockCount
<< "- Frame count at lock:" << m_lastLockFrameCount;
}
// 触发重绘以更新状态显示
@ -314,14 +322,14 @@ void CustomWidget::drawLockInfo(QPainter &painter)
"Last Lock Info:");
infoFont.setBold(false);
infoFont.setPointSize(11);
infoFont.setPointSize(9);
painter.setFont(infoFont);
painter.setPen(QColor(255, 220, 255));
// 格式化锁屏时长
QString durationStr;
if (m_lastLockDuration < 60) {
durationStr = QString("%1 seconds").arg(m_lastLockDuration);
durationStr = QString("%1 s").arg(m_lastLockDuration);
} else if (m_lastLockDuration < 3600) {
int minutes = m_lastLockDuration / 60;
int seconds = m_lastLockDuration % 60;
@ -334,11 +342,14 @@ void CustomWidget::drawLockInfo(QPainter &painter)
}
QString lockInfo = QString(
"\nLock Time: %1\n"
"Duration: %2\n"
"Total Locks: %3"
"\nLock Time: %1 (Duration: %2)\n"
"Frame Count at Lock: %3\n"
"Frames During Lock: %4\n"
"Total Locks: %5"
).arg(m_lastLockTime.toString("yyyy-MM-dd hh:mm:ss"))
.arg(durationStr)
.arg(m_lastLockFrameCount)
.arg(m_lockPaintFrameCount)
.arg(m_lockCount);
painter.drawText(lockInfoRect.adjusted(10, 25, -10, -5), Qt::AlignLeft | Qt::AlignTop, lockInfo);

View File

@ -99,6 +99,8 @@ private:
QDateTime m_pauseTime; // 暂停时间
QDateTime m_lastLockTime; // 上次锁屏时间
qint64 m_lastLockDuration; // 上次锁屏持续时长(秒)
int m_lastLockFrameCount; // 上次锁屏时的帧数
int m_lockPaintFrameCount; // 锁屏期间绘制的帧数
int m_lockCount; // 锁屏次数
};