From 3d4a993476736fc308573e9aafd9a5bd3a5a1a96 Mon Sep 17 00:00:00 2001 From: ksuprynowicz Date: Thu, 24 Aug 2023 21:01:36 +0200 Subject: [PATCH] API changes for detecting active Window --- interface/src/Application.cpp | 16 ++++++++++++++++ .../src/scripting/DesktopScriptingInterface.h | 9 +++++++++ interface/src/ui/LoginDialog.cpp | 2 ++ 3 files changed, 27 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 10574f330d..a4d9b15eff 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -868,6 +868,22 @@ bool setupEssentials(int& argc, char** argv, const QCommandLineParser& parser, b DependencyManager::set(); #if !defined(DISABLE_QML) DependencyManager::set(); + { + auto window = DependencyManager::get()->getWindow(); + auto desktopScriptingInterface = DependencyManager::get(); + QObject::connect(window, &QQuickWindow::focusObjectChanged, [desktopScriptingInterface](QObject *object) { + if (object) { + if (object->objectName() == QString("desktop")) { + emit desktopScriptingInterface->uiFocusChanged(false); + return; + } + // Signal with empty object name happens in addition to regular named ones and is not necessary here + if (!object->objectName().isEmpty()) { + emit desktopScriptingInterface->uiFocusChanged(true); + } + } + }); + } #endif DependencyManager::set(); DependencyManager::set(); diff --git a/interface/src/scripting/DesktopScriptingInterface.h b/interface/src/scripting/DesktopScriptingInterface.h index 0f30b140fc..db52906cfd 100644 --- a/interface/src/scripting/DesktopScriptingInterface.h +++ b/interface/src/scripting/DesktopScriptingInterface.h @@ -104,6 +104,15 @@ public: int getWidth(); int getHeight(); +signals: + + /*@jsdoc + * Triggered when keyboard focus changes to another overlay UI window. + * @param {boolean} isActive - true if the keyboard focus is on overlay UI window, false if not. + * @function Desktop.uiFocusChanged + * @returns {Signal} + */ + void uiFocusChanged(bool isActive); private: static int flagAlwaysOnTop() { return AlwaysOnTop; } diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index 7dd5ac303d..5dcbebab45 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -33,6 +33,7 @@ #include "Application.h" #include "scripting/HMDScriptingInterface.h" #include "Constants.h" +#include "scripting/DesktopScriptingInterface.h" HIFI_QML_DEF(LoginDialog) @@ -67,6 +68,7 @@ void LoginDialog::showWithSelection() { auto hmd = DependencyManager::get(); if (!qApp->isHMDMode()) { + emit DependencyManager::get()->uiFocusChanged(true); if (qApp->getLoginDialogPoppedUp()) { LoginDialog::show(); return;