From 3aea4769d59765e61507a2df25bf946e9b92ac5d Mon Sep 17 00:00:00 2001 From: wjyrich Date: Thu, 9 Oct 2025 17:59:52 +0800 Subject: [PATCH] feat: add delayed window state reset with singleShot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 重置窗口状态修复潜在时序问题 --- frame/dsqmlglobal.cpp | 19 +++++++++++++++++++ frame/private/dsqmlglobal_p.h | 2 ++ frame/qml/PanelPopupWindow.qml | 19 +++++++++---------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/frame/dsqmlglobal.cpp b/frame/dsqmlglobal.cpp index c76ade830..9e9ab2e6a 100644 --- a/frame/dsqmlglobal.cpp +++ b/frame/dsqmlglobal.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #ifdef BUILD_WITH_X11 #include "private/utility_x11_p.h" @@ -85,6 +87,23 @@ DApplet *DQmlGlobal::rootApplet() const return DPluginLoader::instance()->rootApplet(); } +void DQmlGlobal::singleShot(int msec, QJSValue callback) +{ + if (!callback.isCallable()) { + qCWarning(dsLog) << "singleShot: callback is not callable"; + return; + } + + QTimer::singleShot(msec, this, [callback]() { + if (callback.isCallable()) { + QJSValue result = callback.call(); + if (result.isError()) { + qCWarning(dsLog) << "singleShot callback error:" << result.toString(); + } + } + }); +} + DQmlGlobal *DQmlGlobal::instance() { static DQmlGlobal *gInstance = nullptr; diff --git a/frame/private/dsqmlglobal_p.h b/frame/private/dsqmlglobal_p.h index c43a64173..459096b13 100644 --- a/frame/private/dsqmlglobal_p.h +++ b/frame/private/dsqmlglobal_p.h @@ -8,6 +8,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QWindow; @@ -32,6 +33,7 @@ class DQmlGlobal : public QObject, public DTK_CORE_NAMESPACE::DObject Q_INVOKABLE static void closeChildrenWindows(QWindow *target); Q_INVOKABLE bool grabKeyboard(QWindow *target, bool grab = true); Q_INVOKABLE bool grabMouse(QWindow *target, bool grab = true); + Q_INVOKABLE void singleShot(int msec, QJSValue callback); DApplet *rootApplet() const; diff --git a/frame/qml/PanelPopupWindow.qml b/frame/qml/PanelPopupWindow.qml index 53efbc723..c70d93002 100644 --- a/frame/qml/PanelPopupWindow.qml +++ b/frame/qml/PanelPopupWindow.qml @@ -77,17 +77,16 @@ PopupWindow { D.DWindow.shadowOffset: Qt.point(0, 25) D.DWindow.shadowColor: D.DTK.themeType === D.ApplicationHelper.DarkType ? Qt.rgba(0, 0, 0, 0.5) : Qt.rgba(0, 0, 0, 0.2) D.ColorSelector.family: D.Palette.CrystalColor - color: "transparent" - onVisibleChanged: function (arg) { - if (!arg) { - currentItem = null - root.width = 10 - root.height = 10 - } - if (!arg) - DS.closeChildrenWindows(root) - } + + onVisibleChanged: DS.singleShot(200, (function () { + if(root.visible) + return + currentItem = null + root.width = 10 + root.height = 10 + DS.closeChildrenWindows(root) + })) Connections { target: root.transientParent