Skip to content

Commit 2889f4a

Browse files
committed
feat: add delayed window state reset with singleShot
1. Added singleShot method to DQmlGlobal for delayed JavaScript callback execution 2. Implemented QTimer-based delayed callback with proper error handling 3. Modified PanelPopupWindow to use delayed reset instead of immediate cleanup 4. Added necessary includes for QTimer and QQmlEngine in implementation 5. Fixed potential timing issues by delaying window state reset by 200ms feat: 添加延迟窗口状态重置功能 1. 在 DQmlGlobal 中添加 singleShot 方法用于延迟执行 JavaScript 回调 2. 实现基于 QTimer 的延迟回调并包含错误处理 3. 修改 PanelPopupWindow 使用延迟重置替代立即清理 4. 在实现中添加必要的 QTimer 和 QQmlEngine 头文件包含 5. 通过延迟 200ms 重置窗口状态修复潜在时序问题
1 parent efa3dee commit 2889f4a

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

frame/dsqmlglobal.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <QQueue>
1414
#include <QWindow>
1515
#include <QGuiApplication>
16+
#include <QTimer>
17+
#include <QQmlEngine>
1618

1719
#ifdef BUILD_WITH_X11
1820
#include "private/utility_x11_p.h"
@@ -85,6 +87,23 @@ DApplet *DQmlGlobal::rootApplet() const
8587
return DPluginLoader::instance()->rootApplet();
8688
}
8789

90+
void DQmlGlobal::singleShot(int msec, const QJSValue &callback)
91+
{
92+
if (!callback.isCallable()) {
93+
qCWarning(dsLog) << "singleShot: callback is not callable";
94+
return;
95+
}
96+
97+
QTimer::singleShot(msec, this, [callback]() mutable {
98+
if (callback.isCallable()) {
99+
QJSValue result = callback.call();
100+
if (result.isError()) {
101+
qCWarning(dsLog) << "singleShot callback error:" << result.toString();
102+
}
103+
}
104+
});
105+
}
106+
88107
DQmlGlobal *DQmlGlobal::instance()
89108
{
90109
static DQmlGlobal *gInstance = nullptr;

frame/private/dsqmlglobal_p.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <QObject>
1010
#include <DObject>
11+
#include <private/qjsvalue_p.h>
12+
#include <qtmetamacros.h>
1113

1214
QT_BEGIN_NAMESPACE
1315
class QWindow;
@@ -32,6 +34,7 @@ class DQmlGlobal : public QObject, public DTK_CORE_NAMESPACE::DObject
3234
Q_INVOKABLE static void closeChildrenWindows(QWindow *target);
3335
Q_INVOKABLE bool grabKeyboard(QWindow *target, bool grab = true);
3436
Q_INVOKABLE bool grabMouse(QWindow *target, bool grab = true);
37+
Q_INVOKABLE void singleShot(int msec, const QJSValue &callback);
3538

3639
DApplet *rootApplet() const;
3740

frame/qml/PanelPopupWindow.qml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,17 @@ PopupWindow {
7777
D.DWindow.shadowOffset: Qt.point(0, 25)
7878
D.DWindow.shadowColor: D.DTK.themeType === D.ApplicationHelper.DarkType ? Qt.rgba(0, 0, 0, 0.5) : Qt.rgba(0, 0, 0, 0.2)
7979
D.ColorSelector.family: D.Palette.CrystalColor
80-
8180
color: "transparent"
82-
onVisibleChanged: function (arg) {
83-
if (!arg) {
84-
currentItem = null
85-
root.width = 10
86-
root.height = 10
87-
}
88-
if (!arg)
89-
DS.closeChildrenWindows(root)
81+
82+
function resetWindowState() {
83+
if(root.visible)
84+
return
85+
currentItem = null
86+
root.width = 10
87+
root.height = 10
88+
DS.closeChildrenWindows(root)
9089
}
90+
onVisibleChanged: DS.singleShot(200, resetWindowState)
9191

9292
Connections {
9393
target: root.transientParent

0 commit comments

Comments
 (0)