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
window.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 <qarkui/window.h>
5
6#include <cstdint>
7#include <qarkui/qarkuiutils.h>
8#include <qohosutils.h>
9#include <window_manager/oh_window.h>
10#include <window_manager/oh_window_comm.h>
11
13
14namespace QArkUi {
15
16namespace {
17
18QRect makeQRectFromWindowManagerRect(const ::WindowManager_Rect &wmRect)
19{
20 return QRect(
21 QPoint(wmRect.posX, wmRect.posY),
22 QSize(wmRect.width, wmRect.height));
23}
24
25}
26
27std::optional<WindowProperties> tryGetWindowProperties(JsWindowId jsWindowId)
28{
29 ::WindowManager_WindowProperties windowProperties;
30 auto errorCode = ::OH_WindowManager_GetWindowProperties(
31 static_cast<std::int32_t>(jsWindowId.value()),
32 &windowProperties);
33
34 if (errorCode != ::OK)
35 return {};
36
37 return WindowProperties {
38 .windowRect = makeQRectFromWindowManagerRect(windowProperties.windowRect),
39 .drawableRect = makeQRectFromWindowManagerRect(windowProperties.drawableRect),
40 .id = JsWindowId(windowProperties.id),
41 .displayId = QOhosDisplayInfo::JsDisplayId(windowProperties.displayId),
42 };
43}
44
46 std::string owningQAbilityInstanceId, JsWindowId windowId,
47 QNapi::Object jsWindow, QtOhos::QObjectThreadSafeRef owningQWindowRef)
48 : m_owningQAbilityInstanceId(std::move(owningQAbilityInstanceId))
52{
53}
54
56{
57 bool result = false;
58 const auto windowShownErrorCode = callArkUi(
59 Q_OHOS_NAMED_FUNC(::OH_WindowManager_IsWindowShown),
60 static_cast<std::int32_t>(m_jsWindowId.value()), &result);
61 if (windowShownErrorCode == ::WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM)
62 qOhosReportFatalErrorAndAbort("%s: error: %d", Q_FUNC_INFO, windowShownErrorCode);
63 return windowShownErrorCode == ::WindowManager_ErrorCode::OK
64 ? result
65 : false;
66}
67
69{
70 if (QtOhos::JsWindowsTracker::isWindowClosing(m_jsWindow.Value()))
71 return false;
72 return m_jsWindow.eval<QNapi::Boolean>("isFocused()").Value();
73}
74
76{
77 return m_owningQAbilityInstanceId;
78}
79
80JsWindowId JsWindowRef::id() const
81{
82 return m_jsWindowId;
83}
84
86{
87 return m_owningQWindowRef;
88}
89
91{
92 return m_jsWindow.Value();
93}
94
95}
96
97QT_END_NAMESPACE
QNapi::Object jsObject()
Definition window.cpp:90
JsWindowRef(std::string owningQAbilityInstanceId, JsWindowId windowId, QNapi::Object jsWindow, QtOhos::QObjectThreadSafeRef owningQWindowRef)
Definition window.cpp:45
bool isFocused() const
Definition window.cpp:68
QtOhos::QObjectThreadSafeRef owningQWindowRef() const
Definition window.cpp:85
bool isWindowShown() const
Definition window.cpp:55
JsWindowId id() const
Definition window.cpp:80
const std::string & owningQAbilityInstanceId() const
Definition window.cpp:75
std::optional< WindowProperties > tryGetWindowProperties(JsWindowId jsWindowId)
Definition window.cpp:27
Combined button and popup list for selecting options.