From 17553e5a1fb72a92dbbff3fa6bc7d55b8f1a0123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 7 Nov 2013 14:10:35 +0100 Subject: [PATCH] Work around problem of restored QQuickWindows not being visible A declarative KWin script needs to register the QQuickWindows it is using in the KWin object. This method ensures that the QQuickWindow will destroy the platfrom window once it gets hidden. So the next time the QQuickWindow is shown a new platform window is created. As can be seen in the OSD this is not really nice, therefore a KWin.Dialog should be created which takes care of these steps. --- scripting/scripting.cpp | 11 +++++++++++ scripting/scripting.h | 2 ++ scripts/desktopchangeosd/contents/ui/osd.qml | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/scripting/scripting.cpp b/scripting/scripting.cpp index 3069bd04ba..14434d3fa3 100644 --- a/scripting/scripting.cpp +++ b/scripting/scripting.cpp @@ -50,6 +50,7 @@ along with this program. If not, see . #include #include #include +#include QScriptValue kwinScriptPrint(QScriptContext *context, QScriptEngine *engine) { @@ -556,6 +557,7 @@ void KWin::DeclarativeScript::run() qmlRegisterType("org.kde.kwin", 2, 0, "ClientModelByScreenAndDesktop"); qmlRegisterType("org.kde.kwin", 2, 0, "ClientFilterModel"); qmlRegisterType(); + qmlRegisterType(); m_engine->rootContext()->setContextProperty(QStringLiteral("workspace"), AbstractScript::workspace()); m_engine->rootContext()->setContextProperty(QStringLiteral("options"), options); @@ -594,6 +596,15 @@ QVariant KWin::JSEngineGlobalMethodsWrapper::readConfig(const QString &key, QVar return m_script->config().readEntry(key, defaultValue); } +void KWin::JSEngineGlobalMethodsWrapper::registerWindow(QQuickWindow *window) +{ + connect(window, &QWindow::visibilityChanged, [window](QWindow::Visibility visibility) { + if (visibility == QWindow::Hidden) { + window->destroy(); + } + }); +} + KWin::Scripting *KWin::Scripting::s_self = NULL; KWin::Scripting *KWin::Scripting::create(QObject *parent) diff --git a/scripting/scripting.h b/scripting/scripting.h index 3a0f89a6ef..a7f991d88c 100644 --- a/scripting/scripting.h +++ b/scripting/scripting.h @@ -39,6 +39,7 @@ class QMenu; class QMutex; class QScriptEngine; class QScriptValue; +class QQuickWindow; class KConfigGroup; /// @c true == javascript, @c false == qml @@ -315,6 +316,7 @@ public: public Q_SLOTS: QVariant readConfig(const QString &key, QVariant defaultValue = QVariant()); + void registerWindow(QQuickWindow *window); private: DeclarativeScript *m_script; diff --git a/scripts/desktopchangeosd/contents/ui/osd.qml b/scripts/desktopchangeosd/contents/ui/osd.qml index 44032f3fba..dc038d39ed 100644 --- a/scripts/desktopchangeosd/contents/ui/osd.qml +++ b/scripts/desktopchangeosd/contents/ui/osd.qml @@ -294,4 +294,8 @@ PlasmaCore.Dialog { dialogItem.show(); } } + + Component.onCompleted: { + KWin.registerWindow(dialog); + } }