Skip to content

Commit e76d076

Browse files
mhduiydeepin-bot[bot]
authored andcommitted
fix: prevent mouse movement from stopping preview mode
1. Added m_previewing flag to track whether screensaver is in preview mode 2. Modified Preview() method to set m_previewing flag based on preview parameter 3. Changed window flag setting logic to always apply WindowStaysOnTopHint when staysOn is true 4. Unified input event connection to use onInputEventReceived slot instead of conditional connections 5. Added onInputEventReceived slot to filter mouse move events during preview mode 6. Reset m_previewing flag to false when screensaver stops 7. Removed debug log from ScreenSaverView::event() method as logging is now handled in DBusScreenSaver Log: Fixed issue where mouse movement would incorrectly exit screensaver preview mode Influence: 1. Test screensaver preview functionality - mouse movement should not exit preview 2. Verify other input events (keyboard, touch) still properly exit preview mode 3. Test normal screensaver operation - all input events should stop screensaver 4. Verify WindowStaysOnTopHint behavior in preview mode 5. Test WindowStaysOnBottomHint behavior when staysOn is false 6. Ensure screensaver properly starts and stops in both preview and normal modes fix: 防止鼠标移动退出预览模式 1. 添加 m_previewing 标志来跟踪屏保是否处于预览模式 2. 修改 Preview() 方法根据 preview 参数设置 m_previewing 标志 3. 更改窗口标志设置逻辑,当 staysOn 为 true 时始终应用 WindowStaysOnTopHint 4. 统一输入事件连接,使用 onInputEventReceived 槽代替条件连接 5. 添加 onInputEventReceived 槽以在预览模式下过滤鼠标移动事件 6. 屏保停止时将 m_previewing 标志重置为 false 7. 从 ScreenSaverView::event() 方法中移除调试日志,现在日志在 DBusScreenSaver 中处理 Log: 修复了鼠标移动会错误退出屏保预览模式的问题 Influence: 1. 测试屏保预览功能 - 鼠标移动不应退出预览 2. 验证其他输入事件(键盘、触摸)仍能正常退出预览模式 3. 测试正常屏保运行 - 所有输入事件都应停止屏保 4. 验证预览模式下的 WindowStaysOnTopHint 行为 5. 测试 staysOn 为 false 时的 WindowStaysOnBottomHint 行为 6. 确保屏保在预览和正常模式下都能正确启动和停止 pms: BUG-342709
1 parent 6aac1b7 commit e76d076

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/dbusscreensaver.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)
207207
const QDir &moduleDir = m_screenSaverNameToDir.value(name);
208208
if (!QFile::exists(moduleDir.absoluteFilePath(name)))
209209
return false;
210+
211+
m_previewing = preview;
212+
210213
if (preview) {
211214
if (x11event) {
212215
QAbstractEventDispatcher::instance()->removeNativeEventFilter(x11event.data());
@@ -228,7 +231,7 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)
228231

229232
for (ScreenSaverWindow *window : m_windowMap) {
230233
if (staysOn) {
231-
window->setFlags(window->flags() | Qt::WindowStaysOnTopHint, !preview);
234+
window->setFlags(window->flags() | Qt::WindowStaysOnTopHint, true);
232235
} else {
233236
window->setFlags(window->flags() | Qt::WindowStaysOnBottomHint, false);
234237
}
@@ -242,11 +245,7 @@ bool DBusScreenSaver::Preview(const QString &name, int staysOn, bool preview)
242245
window->start(moduleDir.absoluteFilePath(name));
243246
}
244247

245-
if (!preview) {
246-
connect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::stop, Qt::UniqueConnection);
247-
} else {
248-
disconnect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::stop);
249-
}
248+
connect(window, &ScreenSaverWindow::inputEvent, this, &DBusScreenSaver::onInputEventReceived, Qt::UniqueConnection);
250249

251250
window->show();
252251
}
@@ -457,6 +456,7 @@ void DBusScreenSaver::Stop(bool lock)
457456
#endif
458457

459458
emit isRunningChanged(false);
459+
m_previewing = false;
460460
}
461461

462462
void DBusScreenSaver::stop()
@@ -651,6 +651,17 @@ void DBusScreenSaver::onConfigChanged(const QString &key)
651651
setCurrentScreenSaver(screenSaver);
652652
}
653653

654+
void DBusScreenSaver::onInputEventReceived(QEvent::Type type)
655+
{
656+
if (m_previewing) {
657+
if (type == QEvent::MouseMove) { // 预览时鼠标移动不退出
658+
return;
659+
}
660+
}
661+
qInfo() << QDateTime::currentDateTime().toString() << "receive input evnet and will quit:" << type;
662+
Stop();
663+
}
664+
654665
void DBusScreenSaver::clearResourceList()
655666
{
656667
for (const QString &name : m_resourceList) {

src/dbusscreensaver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class DBusScreenSaver : public QObject
7676
Q_SLOT void onSessionPropertyChanged(const QString &interface, const QVariantMap &changed_properties, const QDBusMessage &message);
7777
Q_SLOT void onDBusPropertyChanged(const QString &interface, const QVariantMap &changed_properties, const QDBusMessage &message);
7878
Q_SLOT void onConfigChanged(const QString &key);
79+
Q_SLOT void onInputEventReceived(QEvent::Type type);
7980

8081
void clearResourceList();
8182
void ensureWindowMap();
@@ -111,6 +112,7 @@ class DBusScreenSaver : public QObject
111112
QScopedPointer<QDBusInterface> m_powerInterface;
112113

113114
static const QStringList m_dbusProperties;
115+
bool m_previewing = false;
114116
};
115117

116118
#endif // DBUSSCREENSAVER_H

src/screensaverview.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ bool ScreenSaverView::event(QEvent *event)
9292
case QEvent::TouchCancel:
9393
case QEvent::KeyPress:
9494
case QEvent::KeyRelease:
95-
qInfo() << QDateTime::currentDateTime().toString() << "receive input evnet and will quit:" << event->type();
9695
emit inputEvent(event->type());
9796
break;
9897

0 commit comments

Comments
 (0)