Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowproxyregistry.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <render/qwindowproxyregistry.h>
5
6#include <QtGui/private/qguiapplication_p.h>
7#include <algorithm>
8#include <qarkui/window.h>
9#include <qohosplatformwindow.h>
10#include <qohosutils.h>
11#include <render/qohosview.h>
12#include <render/qohoswindowproxy.h>
13
15
16namespace
17{
18
20{
21 auto allWindows = qGuiApp->allWindows();
22 auto qWindowIt = std::find_if(
23 allWindows.begin(), allWindows.end(), [&](QWindow *qWindow) {
24 auto *platformWindow = QOhosPlatformWindow::fromQWindowOrNull(qWindow);
25 return platformWindow != nullptr
26 && platformWindow->internalWindowId() == internalWindowId;
27 });
28
29 return qWindowIt != allWindows.end()
30 ? *qWindowIt
31 : nullptr;
32}
33
34}
35
36QWindowProxyRegistry::QWindowProxyRegistry() = default;
38
40 QWindow *qWindow, const QOhosWindowProxy &windowProxy)
41{
42 auto jsWindowId = windowProxy.getWindowProperties().id;
43 auto *platformWindow = QOhosPlatformWindow::fromQWindow(qWindow);
44 auto internalWindowId = platformWindow->internalWindowId();
45
46 bool internalWindowIdAdded = false;
47 std::tie(std::ignore, internalWindowIdAdded) = m_jsWindowIdMap.insert({jsWindowId, internalWindowId});
48
49 bool qAbilityInstanceIdAdded = false;
50 std::tie(std::ignore, qAbilityInstanceIdAdded) = m_qAbilityInstanceIdMap.emplace(
51 internalWindowId, windowProxy.qAbilityInstanceId());
52
53 if (internalWindowIdAdded != qAbilityInstanceIdAdded) {
54 qOhosReportFatalErrorAndAbort(
55 "%s: state inconsistency: internalWindowIdAdded: %d, qAbilityInstanceIdAdded: %d, InternalWindowId='%s', JsWindowId=%f",
56 Q_FUNC_INFO, internalWindowIdAdded, qAbilityInstanceIdAdded,
57 internalWindowId.toStdString().c_str(), jsWindowId.value());
58 }
59
60 return internalWindowIdAdded
61 ? QtOhos::makeDestroyNotifier([this, jsWindowId, internalWindowId]() {
62 m_jsWindowIdMap.erase(jsWindowId);
63 m_qAbilityInstanceIdMap.erase(internalWindowId);
64 })
65 : nullptr;
66}
67
68QOhosOptional<QArkUi::JsWindowId> QWindowProxyRegistry::tryMapInternalWindowIdToJsWindowId(
69 QtOhos::InternalWindowId internalWindowId) const
70{
71 auto foundEntryIter = std::find_if(
72 m_jsWindowIdMap.begin(), m_jsWindowIdMap.end(),
73 [&](const auto &entry) {
74 return entry.second == internalWindowId;
75 });
76
77 return foundEntryIter != m_jsWindowIdMap.end()
78 ? makeQOhosOptional(foundEntryIter->first)
79 : makeEmptyQOhosOptional();
80}
81
83 QArkUi::JsWindowId jsWindowId)
84{
85 auto windowIdMapIt = m_jsWindowIdMap.find(jsWindowId);
86 if (windowIdMapIt == m_jsWindowIdMap.end())
87 return nullptr;
88
89 auto internalWindowId = windowIdMapIt->second;
90 return findQWindowByInternalWindowIdOrNull(internalWindowId);
91}
92
93QOhosOptional<std::string> QWindowProxyRegistry::tryFindQAbilityInstanceIdByInternalWindowId(
94 QtOhos::InternalWindowId internalWindowId)
95{
96 auto qAbilityInstanceIdIt = m_qAbilityInstanceIdMap.find(internalWindowId);
97 return qAbilityInstanceIdIt != m_qAbilityInstanceIdMap.end()
98 ? makeQOhosOptional(qAbilityInstanceIdIt->second)
99 : makeEmptyQOhosOptional();
100}
101
103{
104 static QWindowProxyRegistry instance;
105 return instance;
106}
107
109{
110 return querySystemWindows(
111 [](QtOhos::JsState &, const QArkUi::JsWindowRef &jsWindow) {
112 return jsWindow.isFocused();
113 });
114}
115
117{
118 return querySystemWindows(
119 [](QtOhos::JsState &, const QArkUi::JsWindowRef &jsWindow) {
120 return jsWindow.isWindowShown();
121 });
122}
123
124std::vector<QWindow *> QWindowProxyRegistry::querySystemWindows(
125 const std::function<bool(QtOhos::JsState &, const QArkUi::JsWindowRef &)> &predicate)
126{
127 auto jsWindowIds = QOhosWindowProxy::queryQtManagedWindowIdsByPredicate(predicate);
128
129 std::vector<QWindow *> qWindowsWithSystemWindow;
130 for (const auto &jsWindowId : jsWindowIds) {
131 auto *qWindow = findQWindowByJsWindowIdOrNull(jsWindowId);
132 if (qWindow != nullptr)
133 qWindowsWithSystemWindow.push_back(qWindow);
134 }
135
136 return qWindowsWithSystemWindow;
137}
138
139QT_END_NAMESPACE
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
QArkUi::WindowProperties getWindowProperties() const
std::vector< QWindow * > queryWindowsWithVisibleSystemWindow()
std::vector< QWindow * > queryWindowsWithSystemWindowAndFocus()
std::shared_ptr< void > registerQWindowWithWindowProxy(QWindow *window, const QOhosWindowProxy &windowProxy)
static QWindowProxyRegistry & instance()
QWindow * findQWindowByJsWindowIdOrNull(QArkUi::JsWindowId jsWindowId)
Combined button and popup list for selecting options.
QWindow * findQWindowByInternalWindowIdOrNull(QtOhos::InternalWindowId internalWindowId)