From 025f530db623f62136e1d07abbcd9a04b62da4e8 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Sun, 27 Aug 2023 22:06:03 +0200 Subject: [PATCH] Added an API function to check if an overlay has keyboard focus --- interface/src/scripting/DesktopScriptingInterface.cpp | 4 +++- interface/src/scripting/DesktopScriptingInterface.h | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/scripting/DesktopScriptingInterface.cpp b/interface/src/scripting/DesktopScriptingInterface.cpp index ffa63ea670..f7ac8f43c9 100644 --- a/interface/src/scripting/DesktopScriptingInterface.cpp +++ b/interface/src/scripting/DesktopScriptingInterface.cpp @@ -60,7 +60,9 @@ static const QVariantMap RELATIVE_POSITION_ANCHOR { }; DesktopScriptingInterface::DesktopScriptingInterface(QObject* parent, bool restricted) - : QObject(parent), _restricted(restricted) { } + : QObject(parent), _restricted(restricted) { + connect(this, &DesktopScriptingInterface::uiFocusChanged, [this] (bool isActive) { _isOverlayWindowFocused = isActive; }); +} int DesktopScriptingInterface::getWidth() { QSize size = qApp->getWindow()->windowHandle()->screen()->virtualSize(); diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h index db52906cfd..41a2c51ac9 100644 --- a/interface/src/scripting/DesktopScriptingInterface.h +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -104,6 +104,13 @@ public: int getWidth(); int getHeight(); + /*@jsdoc + * Checks whether the keyboard focus belongs to overlay UI window. + * @function Desktop.isOverlayWindowFocused + * @returns {boolean} true if the keyboard focus is on overlay UI window, false if not. + */ + Q_INVOKABLE bool isOverlayWindowFocused() { return _isOverlayWindowFocused; }; + signals: /*@jsdoc @@ -124,6 +131,7 @@ private: static QVariantMap getRelativePositionAnchor(); Q_INVOKABLE static QVariantMap getPresentationMode(); const bool _restricted; + std::atomic _isOverlayWindowFocused { false }; };