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