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