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
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)
36
37 return makeQOhosOptional(
38 WindowProperties {
39 .windowRect = makeQRectFromWindowManagerRect(windowProperties.windowRect),
40 .drawableRect = makeQRectFromWindowManagerRect(windowProperties.drawableRect),
41 .id = JsWindowId(windowProperties.id),
42 .displayId = makeQOhosOptional(QOhosDisplayInfo::JsDisplayId(windowProperties.displayId)),
43 });
44}
45
46JsWindowRef::JsWindowRef(JsWindowId windowId, QNapi::Object jsWindow)
49{
50}
51
53{
54 bool result = false;
55 const auto windowShownErrorCode = callArkUi(
56 Q_OHOS_NAMED_FUNC(::OH_WindowManager_IsWindowShown),
57 static_cast<std::int32_t>(m_jsWindowId.value()), &result);
58 if (windowShownErrorCode == ::WindowManager_ErrorCode::WINDOW_MANAGER_ERRORCODE_INVALID_PARAM)
59 qOhosReportFatalErrorAndAbort("%s: error: %d", Q_FUNC_INFO, windowShownErrorCode);
60 return windowShownErrorCode == ::WindowManager_ErrorCode::OK
61 ? result
62 : false;
63}
64
66{
67 if (QtOhos::JsWindowsTracker::isWindowClosing(m_jsWindow.Value()))
68 return false;
69 return m_jsWindow.call<QNapi::Boolean>("isFocused").Value();
70}
71
72JsWindowId JsWindowRef::id() const
73{
74 return m_jsWindowId;
75}
76
78{
79 return m_jsWindow.Value();
80}
81
82}
83
84QT_END_NAMESPACE
QNapi::Object jsObject()
Definition window.cpp:77
bool isFocused() const
Definition window.cpp:65
JsWindowRef(JsWindowId windowId, QNapi::Object jsWindow)
Definition window.cpp:46
bool isWindowShown() const
Definition window.cpp:52
JsWindowId id() const
Definition window.cpp:72
std::enable_if_t< qohosplugincore_h_detail::isQOhosOptional< QOhosInvokeResult< Func, T > >, QOhosInvokeResult< Func, T > > andThen(Func &&func) const
QOhosOptional< WindowProperties > tryGetWindowProperties(JsWindowId jsWindowId)
Definition window.cpp:27
Combined button and popup list for selecting options.
QOhosOptional< void > makeEmptyQOhosOptional()