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
qohoswindowproxy.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/qohoswindowproxy.h>
5
6#include <QtCore/qcoreapplication.h>
7#include <QtCore/qharmonyjscontext.h>
8#include <QtCore/qset.h>
9#include <QtCore/private/qnapi_p.h>
10#include <QtCore/qscopeguard.h>
11#include <QtGui/private/qohosimageconversions_p.h>
12#include <QtGui/qguiapplication.h>
13#include <QtGui/qimage.h>
14#include <algorithm>
15#include <functional>
16#include <memory>
17#include <multimedia/image_framework/image/pixelmap_native.h>
18#include <qarkui/input.h>
19#include <qarkui/qarkuiutils.h>
20#include <qarkui/qxcomponentregistry.h>
21#include <qarkui/window.h>
22#include <qarkui/window_manager.h>
23#include <qohosdeviceinfo_p.h>
24#include <qohosdisplayinfo.h>
25#include <qohosjsmain.h>
26#include <qohosjsutils.h>
27#include <qohospixelmapconversions.h>
28#include <qohosplugincore.h>
29#include <qohosqpaenums.h>
30#include <qohossettings.h>
31#include <qohosutils.h>
32#include <render/qohosbatchingrequestshandler.h>
33#include <render/qohosjswindowregistry.h>
34#include <render/qohoswindowproxydatafactory.h>
35#include <render/qxcomponent.h>
36#include <type_traits>
37
39
40namespace
41{
42
44
45QRect ohosWindowRectToQRect(const QNapi::Object &ohosWindowRect)
46{
47 return QRect {
48 ohosWindowRect.get<QNapi::Number>("left"),
49 ohosWindowRect.get<QNapi::Number>("top"),
50 ohosWindowRect.get<QNapi::Number>("width"),
51 ohosWindowRect.get<QNapi::Number>("height"),
52 };
53}
54
55QOhosWindowProxy::AvoidArea mapAvoidAreaFromJs(const QNapi::Object &avoidAreaObject)
56{
57 return {
58 .visible = avoidAreaObject.get<QNapi::Boolean>("visible"),
59 .leftRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>("leftRect")),
60 .topRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>("topRect")),
61 .rightRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>("rightRect")),
62 .bottomRect = ohosWindowRectToQRect(avoidAreaObject.get<QNapi::Object>("bottomRect")),
63 };
64}
65
67{
68 switch (shape) {
69 case Qt::ArrowCursor:
71 case Qt::UpArrowCursor:
73 case Qt::CrossCursor:
75 case Qt::WaitCursor:
77 case Qt::IBeamCursor:
79 case Qt::SizeVerCursor:
81 case Qt::SizeHorCursor:
83 case Qt::SizeBDiagCursor:
85 case Qt::SizeFDiagCursor:
87 case Qt::SizeAllCursor:
89 case Qt::BlankCursor:
90 // TODO: there is no dedicated Ohos 'Qt::BlankCursor'. Return default.
92 case Qt::SplitVCursor:
94 case Qt::SplitHCursor:
96 case Qt::PointingHandCursor:
98 case Qt::ForbiddenCursor:
100 case Qt::WhatsThisCursor:
102 case Qt::BusyCursor:
104 case Qt::OpenHandCursor:
106 case Qt::ClosedHandCursor:
108 case Qt::DragCopyCursor:
110 case Qt::DragMoveCursor:
112 case Qt::DragLinkCursor:
113 // TODO: there is no dedicated Ohos 'Qt::DragLinkCursor'. Return default.
115 case Qt::BitmapCursor:
116 // TODO: there is no dedicated Ohos 'Qt::BitmapCursor'. Return default.
118 case Qt::CustomCursor:
119 // TODO: there is no dedicated Ohos 'Qt::CustomCursor'. Return default.
121 }
122
124}
125
126std::optional<double> getOptionalNumberPropAsOptionalDouble(const QNapi::Object &object, const std::string &propertyName)
127{
128 auto propOrEmpty = QNapi::getOptionalPropOrEmpty<QNapi::Number>(object, propertyName);
129 return !propOrEmpty.IsEmpty()
130 ? std::optional<double>(propOrEmpty)
131 : std::nullopt;
132}
133
135{
136 auto windowPropsObj = jsWindow.eval<QNapi::Object>("getWindowProperties()");
137 auto displayIdOrEmpty = QNapi::getOptionalPropOrEmpty<QNapi::Number>(windowPropsObj, "displayId");
138 return QArkUi::WindowProperties {
139 .windowRect = ohosWindowRectToQRect(windowPropsObj.get<QNapi::Object>("windowRect")),
140 .drawableRect = ohosWindowRectToQRect(windowPropsObj.get<QNapi::Object>("drawableRect")),
141 .id = QArkUi::JsWindowId(windowPropsObj.get<QNapi::Number>("id")),
142 .displayId = !displayIdOrEmpty.IsEmpty()
143 ? std::optional(QOhosDisplayInfo::JsDisplayId{displayIdOrEmpty.DoubleValue()})
144 : std::nullopt,
145 };
146}
147
148QNapi::Object toNapiObject(napi_env env, const QOhosWindowProxy::MoveConfiguration &moveConfiguration)
149{
150 auto moveConfigurationObject = QNapi::makeObject(env);
151 if (moveConfiguration.displayId.has_value()) {
152 moveConfigurationObject.set(
153 "displayId", moveConfiguration.displayId.value().value());
154 }
155 return moveConfigurationObject;
156}
157
158template<typename ...Args>
160 std::function<void(Args...)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
161 std::shared_ptr<QOhosWindowProxy::WindowCallbacks> qtWindowCallbacks)
162{
163 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
164
165 return [memberPtr, weakQtWindowCallbacks](Args ...args) {
166 QtOhos::invokeInQtThread([memberPtr, weakQtWindowCallbacks, args...]() {
167 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
168 if (qtWindowCallbacks)
169 (*qtWindowCallbacks.*memberPtr)(args...);
170 });
171 };
172}
173
174template<typename T>
176 std::function<void(T)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
177 std::shared_ptr<QOhosWindowProxy::WindowCallbacks> qtWindowCallbacks)
178{
179 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
180
181 return QtOhos::makeCompressingAsyncConsumer<T>(
182 [memberPtr, weakQtWindowCallbacks](T value) {
183 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
184 if (qtWindowCallbacks)
185 (*qtWindowCallbacks.*memberPtr)(value);
186 },
187 QtOhos::invokeInQtThread);
188}
189
190bool isPointInNonClientArea(const QPoint &point, const QArkUi::WindowProperties &windowProperties)
191{
192 constexpr bool containsPolicyExcludeEdgeValue = true;
193
194 auto drawableRectInScreenSpace =
195 windowProperties.drawableRect.translated(windowProperties.windowRect.topLeft());
196 return !drawableRectInScreenSpace.contains(point, containsPolicyExcludeEdgeValue);
197}
198
200{
201 switch (action) {
202 case ::MOUSE_ACTION_MOVE:
203 return QEvent::NonClientAreaMouseMove;
204 case ::MOUSE_ACTION_BUTTON_DOWN:
205 return QEvent::NonClientAreaMouseButtonPress;
206 case ::MOUSE_ACTION_BUTTON_UP:
207 return QEvent::NonClientAreaMouseButtonRelease;
208 case ::MOUSE_ACTION_CANCEL:
209 case ::MOUSE_ACTION_AXIS_BEGIN:
210 case ::MOUSE_ACTION_AXIS_UPDATE:
211 case ::MOUSE_ACTION_AXIS_END:
212 break;
213 }
214 return std::nullopt;
215}
216
217std::optional<Qt::MouseButton> tryMapMouseEventButtonToQt(::Input_MouseEventButton button)
218{
219 switch (button) {
220 case ::MOUSE_BUTTON_LEFT:
221 return Qt::LeftButton;
222 case ::MOUSE_BUTTON_MIDDLE:
223 return Qt::MiddleButton;
224 case ::MOUSE_BUTTON_RIGHT:
225 return Qt::RightButton;
226 case ::MOUSE_BUTTON_FORWARD:
227 return Qt::ForwardButton;
228 case ::MOUSE_BUTTON_BACK:
229 return Qt::BackButton;
230 case ::MOUSE_BUTTON_NONE:
231 break;
232 }
233 return std::nullopt;
234}
235
237{
238 switch (action) {
239 case ::TOUCH_ACTION_MOVE:
240 return QEvent::NonClientAreaMouseMove;
241 case ::TOUCH_ACTION_DOWN:
242 return QEvent::NonClientAreaMouseButtonPress;
243 case ::TOUCH_ACTION_UP:
244 return QEvent::NonClientAreaMouseButtonRelease;
245 case ::TOUCH_ACTION_CANCEL:
246 break;
247 }
248 return std::nullopt;
249}
250
251template<typename EnumsContainer>
252std::string mapEnumsToLogString(const EnumsContainer &enums)
253{
254 std::string output;
255 for (auto enumValue : enums) {
256 if (!output.empty())
257 output += ",";
258 output += std::to_string(static_cast<std::underlying_type_t<decltype(enumValue)>>(enumValue));
259 }
260 return output;
261}
262
263bool isAbilityTerminating(QNapi::Object ability)
264{
265 return ability.eval<QNapi::Boolean>("context.isTerminating()");
266}
267
269{
270 try {
271 return jsWindowRef.eval<QNapi::Boolean>("isInFreeWindowMode()");
272 } catch (const Napi::Error &error) {
273 qOhosPrintfWarning("isInFreeWindowMode() failed (%s), assuming it is not", error.what());
274 return false;
275 }
276}
277
279 QNapi::Object jsWindow, WindowProxyType windowType, std::shared_ptr<QtOhos::QAbilityPeer> abilityPeer)
280{
281 const bool boundToAbility = windowType != WindowProxyType::FloatWindow;
282 return QtOhos::JsWindowsTracker::isWindowClosing(jsWindow) || (boundToAbility && isAbilityTerminating(abilityPeer->qAbility()));
283}
284
285}
286
287const QOhosWindowProxy::EventHandlerDescriptor QOhosWindowProxy::eventHandlerDescriptors[] = {
288 {
289 .eventName = "avoidAreaChange",
290 .eventHandler = &QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback,
291 .eventHandlerFlags = {},
292 },
293 {
294 .eventName = "touchOutside",
295 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback,
296 .eventHandlerFlags = {},
297 },
298 {
299 .eventName = "windowEvent",
300 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowEventCallback,
301 .eventHandlerFlags = EventHandlerFlagBits::allowCallWhenAbilityIsTerminating,
302 },
303 {
304 .eventName = "windowRectChange",
305 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback,
306 .eventHandlerFlags = {},
307 },
308 {
309 .eventName = "rectChangeInGlobalDisplay",
310 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowRectChangeInGlobalDisplayCallback,
311 .eventHandlerFlags = {},
312 },
313 {
314 .eventName = "windowStatusChange",
315 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowStatusCallback,
316 .eventHandlerFlags = {},
317 },
318 {
319 .eventName = "windowVisibilityChange",
320 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback,
321 .eventHandlerFlags = {},
322 },
323 {
324 .eventName = "displayIdChange",
325 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback,
326 .eventHandlerFlags = EventHandlerFlagBits::allowEventHandlerRegistrationFailure,
327 },
328};
329
330QOhosWindowProxy::QOhosWindowProxy(
331 const std::function<void(QtOhos::JsState &, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData>)> &makeWindowProxyDataInJsThread)
332{
333 auto jsThreadInitResult = QOhosJsThreadGateway::evalWithPromise<JsThreadInitResult>(
334 [&](QOhosJsState &jsState, QOhosTaskPromise<JsThreadInitResult> evalPromise) {
335 auto sharedEvalPromise = QtOhos::moveToSharedPtr(std::move(evalPromise).makeChained(Q_FUNC_INFO));
336 makeWindowProxyDataInJsThread(
337 QtOhos::JsState::castFrom(jsState),
338 [sharedEvalPromise, this](QtOhos::JsState &jsState, QOhosWindowProxyData windowProxyData) {
339 (*sharedEvalPromise)(initInJsThread(jsState, std::move(windowProxyData)));
340 });
341 },
342 Q_FUNC_INFO);
343 m_windowProxyType = jsThreadInitResult.windowProxyType;
344 m_subWindowMaximizeSupported = jsThreadInitResult.subWindowMaximizeSupported;
345 m_nodeXComponent = std::move(jsThreadInitResult.nodeXComponent);
346 m_qAbilityInstanceId = std::move(jsThreadInitResult.qAbilityInstanceId);
347 m_abilityObjectRef = std::move(jsThreadInitResult.abilityObjectRef);
348 m_jsWindowObjectRef = std::move(jsThreadInitResult.jsWindowObjectRef);
349 m_jsWindowRegistrationHandle = std::move(jsThreadInitResult.jsWindowRegistrationHandle);
350}
351
352QOhosWindowProxy::JsThreadInitResult QOhosWindowProxy::initInJsThread(
353 QtOhos::JsState &jsState, QOhosWindowProxyData windowProxyData)
354{
355 *m_jsScopeData = JsScopeData(
356 windowProxyData.windowProxyType,
357 std::move(windowProxyData.jsWindow),
358 std::move(windowProxyData.jsKeepAliveData),
359 std::move(windowProxyData.qAbilityPeer),
360 windowProxyData.owningQWindowRef);
361
362 std::vector<std::shared_ptr<void>> eventListenersHandles;
363 for (const auto &eventHandlerDescriptor : eventHandlerDescriptors) {
364 eventListenersHandles.push_back(
365 m_jsScopeData->registerEventListener(
366 eventHandlerDescriptor.eventName, eventHandlerDescriptor.eventHandler,
367 eventHandlerDescriptor.eventHandlerFlags));
368 }
369 m_jsScopeData->m_eventListenersHandle = QtOhos::moveToSharedPtr(std::move(eventListenersHandles));
370
371 auto &jsContext = QHarmonyJsContext::fromEnv(jsState.env());
372 return JsThreadInitResult {
373 .windowProxyType = windowProxyData.windowProxyType,
374 .subWindowMaximizeSupported = windowProxyData.subWindowMaximizeSupported,
375 .nodeXComponent = std::move(windowProxyData.nodeXComponent),
376 .qAbilityInstanceId = m_jsScopeData->jsWindowRef->owningQAbilityInstanceId(),
377 .abilityObjectRef = QHarmonyJsObjectRef::fromValue(jsContext, m_jsScopeData->qAbilityPeer->qAbility()),
378 .jsWindowObjectRef = QHarmonyJsObjectRef::fromValue(jsContext, m_jsScopeData->jsWindowRef->jsObject()),
379 .jsWindowRegistrationHandle = QOhosJsWindowRegistry::instance(jsState).registerJsWindow(m_jsScopeData->jsWindowRef),
380 };
381}
382
383QOhosWindowProxy::~QOhosWindowProxy()
384{
385 // NOTE
386 // we need to unregister from JS Window events now, while the Window is
387 // still in consistent state. While destroying the m_jsScopeData we
388 // call Window::destroyWindow(), which makes the JS object unusable
389 // (trying to unregister something on it will throw).
390 // The registry entry goes first so lookups never return a window being torn down.
391 m_jsWindowRegistrationHandle.reset();
392 m_subWindowCloseRegistrationHandle.reset();
393}
394
395void QOhosWindowProxy::removeStartingWindow(JsCallBatch &jsCallBatch)
396{
397 jsCallBatch.submit(
398 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
399 if (m_jsScopeData->isWindowClosing()) {
400 taskPromise();
401 return;
402 }
403 auto optQUiAbilityPeer
404 = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
405 if (!optQUiAbilityPeer) {
406 taskPromise();
407 return;
408 }
409 auto promise = optQUiAbilityPeer->windowStage().evalToPromiseOrRejectOnThrow(
410 "removeStartingWindow()");
411 promise
412 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
413 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
414 },
415 Q_FUNC_INFO);
416}
417
419 const QPoint &point, std::optional<QOhosDisplayInfo::JsDisplayId> optMoveToTargetDisplay, JsCallBatch &jsCallBatch)
420{
421 auto displayIdValue = optMoveToTargetDisplay.value_or(QOhosDisplayInfo::JsDisplayId(-1)).value();
422 qOhosPrintfDebug("%s: %d,%d,%f", Q_FUNC_INFO, point.x(), point.y(), displayIdValue);
423
424 jsCallBatch.submit(
425 [this, point, optMoveToTargetDisplay](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
426 if (m_jsScopeData->isWindowClosing()) {
427 taskPromise();
428 return;
429 }
430
431 const auto primaryJsDisplayId = QOhosDisplayInfo::JsDisplayId(0);
432
433 auto targetDisplayId = optMoveToTargetDisplay.has_value()
434 ? optMoveToTargetDisplay.value()
435 : getWindowProperties().displayId.value_or(primaryJsDisplayId);
436
437 auto optDisplayInfo = qTransform(
438 QOhosDisplayInfo::tryGetDisplayById(jsState, targetDisplayId),
439 [&](auto displayObject) {
440 return QOhosDisplayInfo::makeFromOhosDisplayObject(jsState, displayObject);
441 });
442
443 auto optIsDisplayMainOrExtended = qTransform(
444 optDisplayInfo,
445 [](const QOhosDisplayInfo &displayInfo) {
446 return displayInfo.isDisplayMainOrExtended();
447 });
448
449 bool isDisplayMainOrExtended;
450 if (optIsDisplayMainOrExtended.has_value()) {
451 isDisplayMainOrExtended = optIsDisplayMainOrExtended.value();
452 } else {
453 qOhosPrintfWarning(
454 "%s: no display source mode detected. Assumming main/extended screen", Q_FUNC_INFO);
455 isDisplayMainOrExtended = true;
456 }
457
458 QNapi::Promise promise;
459 if (!isDisplayMainOrExtended) {
460 auto optDisplayOffset = qAndThen(
461 optDisplayInfo,
462 [](const QOhosDisplayInfo &displayInfo) {
463 return displayInfo.topLeftOffsetPixels;
464 });
465
466 const QPoint defaultDisplayOffset(0, 0);
467 auto targetCoordinates = point - optDisplayOffset.value_or(defaultDisplayOffset);
468
469 if (!optMoveToTargetDisplay.has_value())
470 qOhosPrintfWarning("%s: trying to move window to not valid target display", Q_FUNC_INFO);
471
472 auto moveConfigurationObject = toNapiObject(
473 jsState.env(),
474 MoveConfiguration {
475 .displayId = optMoveToTargetDisplay,
476 });
477
478 promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
479 "moveWindowToGlobal(*)", {targetCoordinates.x(), targetCoordinates.y(), moveConfigurationObject});
480 } else {
481 promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
482 "moveWindowToGlobalDisplay(*)", {point.x(), point.y()});
483 }
484
485 const char *errorMessagePrefix = !isDisplayMainOrExtended
486 ? "Got error from moveWindowToGlobal()"
487 : "Got error from moveWindowToGlobalDisplay()";
488 auto weakWindowCallbackReceiver = QtOhos::makeWeakPtr(m_jsScopeData->windowCallbackReceiver);
489 promise
490 .onCatch(
491 [weakWindowCallbackReceiver, errorMessagePrefix, point](const QtOhos::CallbackInfo &cbInfo) {
492 QtOhos::logJsCallbackError(cbInfo, errorMessagePrefix);
493 auto windowCallbackReceiver = weakWindowCallbackReceiver.lock();
494 if (windowCallbackReceiver)
495 windowCallbackReceiver->onWindowMoveRejected(point);
496 })
497 .onFinally(std::move(taskPromise));
498 },
499 Q_FUNC_INFO);
500}
501
502void QOhosWindowProxy::setSize(const QSize &size, JsCallBatch &jsCallBatch)
503{
504 qOhosPrintfDebug("%s: %d,%d", Q_FUNC_INFO, size.width(), size.height());
505
506 jsCallBatch.submit(
507 [this, size](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
508 if (m_jsScopeData->isWindowClosing()) {
509 taskPromise();
510 return;
511 }
512
513 const auto currentSize = getWindowPropertiesFromJsWindow(
514 m_jsScopeData->jsWindowRef->jsObject()).windowRect.size();
515 if (currentSize == size) {
516 taskPromise();
517 return;
518 }
519
520 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
521 "resizeAsync(*)", {size.width(), size.height()});
522 auto weakWindowCallbackReceiver = QtOhos::makeWeakPtr(m_jsScopeData->windowCallbackReceiver);
523 promise
524 .onCatch(
525 [weakWindowCallbackReceiver, size](const QtOhos::CallbackInfo &cbInfo) {
526 QtOhos::logJsCallbackError(cbInfo, "Got error from resizeAsync()");
527 auto windowCallbackReceiver = weakWindowCallbackReceiver.lock();
528 if (windowCallbackReceiver)
529 windowCallbackReceiver->onWindowResizeRejected(size);
530 })
531 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
532 },
533 Q_FUNC_INFO);
534}
535
536void QOhosWindowProxy::setWindowBackgroundColor(const QColor &color, JsCallBatch &jsCallBatch)
537{
538 qCDebug(QtForOhos) << Q_FUNC_INFO << color;
539
540 jsCallBatch.submit(
541 [this, color](QOhosJsState &) {
542 if (m_jsScopeData->isWindowClosing())
543 return;
544 m_jsScopeData->jsWindowRef->eval("setWindowBackgroundColor(*)", {color.name(QColor::HexArgb).toStdString()});
545 },
546 Q_FUNC_INFO);
547}
548
549void QOhosWindowProxy::setCustomCursor(const QImage &customCursorImage, const QPoint &hotSpot, JsCallBatch &jsCallBatch)
550{
551 const auto maxOhosCustomCursorSize = QSize(256, 256);
552 const auto customCursorSize = customCursorImage.size();
553 if (customCursorSize.width() > maxOhosCustomCursorSize.width()
554 || customCursorSize.height() > maxOhosCustomCursorSize.height()) {
555 qOhosPrintfError(
556 "%s: can't set %dx%d custom cursor, OHOS max custom cursor size is %dx%d",
557 Q_FUNC_INFO, customCursorSize.width(), customCursorSize.height(),
558 maxOhosCustomCursorSize.width(), maxOhosCustomCursorSize.height());
559 return;
560 }
561
562 auto convertedImage = customCursorImage.convertToFormat(QImage::Format_RGBA8888);
563 jsCallBatch.submit(
564 [this, convertedImage, hotSpot](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
565 if (m_jsScopeData->isWindowClosing()) {
566 taskPromise();
567 return;
568 }
569 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>("getWindowProperties().id");
570
571 auto jsCursor = QNapi::makeObject(
572 jsState.env(),
573 {
574 {"pixelMap", makeOhosNapiPixelMapFromQImage(jsState, convertedImage)},
575 {"focusX", hotSpot.x()},
576 {"focusY", hotSpot.y()},
577 });
578
579 auto jsCursorConfig = QNapi::makeObject(
580 jsState.env(),
581 {
582 {"followSystem", false},
583 });
584
585 jsState.evalToPromiseOrRejectOnThrow(
586 "@ohos.multimodalInput.pointer.setCustomCursor(*)", {windowId, jsCursor, jsCursorConfig})
587 .onCatch(QtOhos::makeErrorLoggingJsCallback("setCustomCursor()"))
588 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
589 },
590 Q_FUNC_INFO);
591}
592
593void QOhosWindowProxy::setPointerStyleSync(const QCursor &cursor, JsCallBatch &jsCallBatch)
594{
595 const auto cursorShape = cursor.shape();
596 jsCallBatch.submit(
597 [this, cursorShape](QOhosJsState &jsState) {
598 if (m_jsScopeData->isWindowClosing())
599 return;
600 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>("getWindowProperties().id");
601
602 jsState.eval(
603 "@ohos.multimodalInput.pointer.setPointerStyleSync(*)",
604 {windowId, jsState.mapOhosEnumToJs(convertToOhosCursor(cursorShape))});
605 },
606 Q_FUNC_INFO);
607}
608
610{
611 return QOhosJsThreadGateway::eval(
612 [&](QOhosJsState &) {
613 if (m_jsScopeData->isWindowClosing())
614 return QArkUi::WindowProperties {};
615 return getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject());
616 },
617 Q_FUNC_INFO);
618}
619
620void QOhosWindowProxy::setWindowCallbackReceiver(
621 std::unique_ptr<WindowCallbacks> callbackReceiver, JsCallBatch &jsCallBatch)
622{
623 auto sharedWindowCallbackReceiver = std::shared_ptr<WindowCallbacks>(std::move(callbackReceiver));
624 m_qtWindowCallbacksReceiverHandle = sharedWindowCallbackReceiver;
625
626 jsCallBatch.submit(
627 [this, sharedWindowCallbackReceiver](QOhosJsState &) {
628 m_jsScopeData->windowCallbackReceiver = QtOhos::moveToSharedPtr(WindowCallbacks {
629 .onWindowEvent = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowEvent, sharedWindowCallbackReceiver),
630 .onWindowStatusChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowStatusChange, sharedWindowCallbackReceiver),
631 .onWindowVisibilityChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowVisibilityChange, sharedWindowCallbackReceiver),
632 .onTouchOutside = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onTouchOutside, sharedWindowCallbackReceiver),
633 .onAvoidAreaChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onAvoidAreaChange, sharedWindowCallbackReceiver),
634 .onWindowRectChange = makeCompressingQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowRectChange, sharedWindowCallbackReceiver),
635 .onWindowRectChangeInGlobalDisplay = makeCompressingQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowRectChangeInGlobalDisplay, sharedWindowCallbackReceiver),
636 .onWindowDisplayIdChange = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowDisplayIdChange, sharedWindowCallbackReceiver),
637 .onWindowResizeRejected = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowResizeRejected, sharedWindowCallbackReceiver),
638 .onWindowMoveRejected = makeQtThreadWindowCallbackDelegate(&WindowCallbacks::onWindowMoveRejected, sharedWindowCallbackReceiver),
639 });
640 },
641 Q_FUNC_INFO);
642}
643
645 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaMouseEvent>> mouseEventBatchConsumer,
646 JsCallBatch &jsCallBatch)
647{
648 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(mouseEventBatchConsumer));
649 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
650
651 auto jsConsumer = makeQtOhosSimpleBatchingQtRequestsHandler<NonClientAreaMouseEvent>(
652 QtOhos::QObjectThreadSafeRef(contextObject),
653 [weakQtConsumer](std::vector<NonClientAreaMouseEvent> &&batch) {
654 auto qtConsumer = weakQtConsumer.lock();
655 if (qtConsumer)
656 (*qtConsumer)(std::move(batch));
657 });
658
659 m_qtNonClientAreaMouseWindowCallbackReceiverHandle = qtConsumer;
660
661 jsCallBatch.submit(
662 [this, jsConsumer = std::move(jsConsumer)](QOhosJsState &) mutable {
663 m_jsScopeData->nonClientAreaEventsDispatcher->mouseEventsConsumer = std::move(jsConsumer);
664 },
665 Q_FUNC_INFO);
666}
667
669 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaTouchEvent>> touchEventBatchConsumer,
670 JsCallBatch &jsCallBatch)
671{
672 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(touchEventBatchConsumer));
673 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
674
675 auto jsConsumer = makeQtOhosSimpleBatchingQtRequestsHandler<NonClientAreaTouchEvent>(
676 QtOhos::QObjectThreadSafeRef(contextObject),
677 [weakQtConsumer](std::vector<NonClientAreaTouchEvent> &&batch) {
678 auto qtConsumer = weakQtConsumer.lock();
679 if (qtConsumer)
680 (*qtConsumer)(std::move(batch));
681 });
682
683 m_qtNonClientAreaTouchWindowCallbackReceiverHandle = qtConsumer;
684
685 jsCallBatch.submit(
686 [this, jsConsumer = std::move(jsConsumer)](QOhosJsState &) mutable {
687 m_jsScopeData->nonClientAreaEventsDispatcher->touchEventsConsumer = std::move(jsConsumer);
688 },
689 Q_FUNC_INFO);
690}
691
692bool QOhosWindowProxy::qtIsMainWindow() const
693{
694 return m_windowProxyType == WindowProxyType::MainWindow;
695}
696
697bool QOhosWindowProxy::isSubWindowMaximizeSupported() const
698{
699 return m_subWindowMaximizeSupported;
700}
701
702void QOhosWindowProxy::raiseToAppTop(JsCallBatch &jsCallBatch)
703{
704 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
705 jsCallBatch.submit(
706 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
707 if (m_jsScopeData->isWindowClosing()) {
708 taskPromise();
709 return;
710 }
711 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("raiseToAppTop()");
712 promise
713 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
714 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
715 },
716 Q_FUNC_INFO);
717}
718
719void QOhosWindowProxy::showWindow(const ShowWindowOptions &options, JsCallBatch &jsCallBatch)
720{
721 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
722 jsCallBatch.submit(
723 [this, options](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
724 if (m_jsScopeData->isWindowClosing()) {
725 taskPromise();
726 return;
727 }
728
729 std::vector<std::pair<std::string, QNapi::ValueWrapper>> jsOptionsProps;
730
731 if (options.focusOnShow.has_value())
732 jsOptionsProps.emplace_back("focusOnShow", options.focusOnShow.value());
733
734 std::vector<QNapi::ValueWrapper> showWindowArgs;
735 constexpr bool brokenHandlingOfEmptyOptionsParamInOhos = true;
736 if (!(jsOptionsProps.empty() && brokenHandlingOfEmptyOptionsParamInOhos))
737 showWindowArgs.push_back(QNapi::makeObject(jsState.env(), jsOptionsProps));
738
739 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("showWindow(*)", showWindowArgs);
740 promise
741 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
742 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
743 },
744 Q_FUNC_INFO);
745}
746
747void QOhosWindowProxy::recover(JsCallBatch &jsCallBatch)
748{
749 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
750 jsCallBatch.submit(
751 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
752 if (m_jsScopeData->isWindowClosing()) {
753 taskPromise();
754 return;
755 }
756
757 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("recover()")
758 .onCatch(QtOhos::makeErrorLoggingJsCallback("recover()"))
759 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
760 },
761 Q_FUNC_INFO);
762}
763
764void QOhosWindowProxy::restore(JsCallBatch &jsCallBatch)
765{
766 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
767 jsCallBatch.submit(
768 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
769 if (m_jsScopeData->isWindowClosing()) {
770 taskPromise();
771 return;
772 }
773 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("restore()")
774 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
775 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
776 },
777 Q_FUNC_INFO);
778}
779
780void QOhosWindowProxy::minimize(JsCallBatch &jsCallBatch)
781{
782 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
783 jsCallBatch.submit(
784 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
785 if (m_jsScopeData->isWindowClosing()) {
786 taskPromise();
787 return;
788 }
789 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("minimize()")
790 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
791 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
792 },
793 Q_FUNC_INFO);
794}
795
796bool QOhosWindowProxy::tryMaximize(MaximizePresentation maximizePresentation)
797{
798 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
799
800 if (m_windowProxyType != WindowProxyType::MainWindow && m_windowProxyType != WindowProxyType::SubWindow) {
801 qCWarning(QtForOhos(), "%s: Maximize is currently supported only on main and sub windows", Q_FUNC_INFO);
802 return false;
803 }
804
805 return QOhosJsThreadGateway::evalWithPromise<bool>(
806 [&](QOhosJsState &jsState, QOhosTaskPromise<bool> evalPromise) {
807 if (m_jsScopeData->isWindowClosing()) {
808 evalPromise(false);
809 return;
810 }
811
812 if (m_windowProxyType == WindowProxyType::SubWindow
813 && !isJsWindowInFreeWindowMode(*m_jsScopeData->jsWindowRef)) {
814 qOhosPrintfWarning(
815 "%s: maximize request ignored: the sub window is not in free window mode",
816 Q_FUNC_INFO);
817 evalPromise(false);
818 return;
819 }
820
821 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
822 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
823 "maximize(*)", {jsState.mapOhosEnumToJs(maximizePresentation)})
824 .onThen(
825 [thenPromise = std::move(thenCatchPromises.first)](const QtOhos::CallbackInfo &) {
826 thenPromise(true);
827 })
828 .onCatch(
829 [catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
830 QtOhos::logJsCallbackError(cbInfo, "Got error from maximize()");
831 catchPromise(false);
832 });
833 },
834 Q_FUNC_INFO);
835}
836
837void QOhosWindowProxy::setWindowLayoutFullScreen(bool isLayoutFullScreen, JsCallBatch &jsCallBatch)
838{
839 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, isLayoutFullScreen ? "true" : "false");
840 jsCallBatch.submit(
841 [this, isLayoutFullScreen](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
842 if (m_jsScopeData->isWindowClosing()) {
843 taskPromise();
844 return;
845 }
846 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
847 "setWindowLayoutFullScreen(*)", {isLayoutFullScreen})
848 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowLayoutFullScreen()"))
849 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
850 },
851 Q_FUNC_INFO);
852}
853
854void QOhosWindowProxy::setWindowSystemBarEnable(const QStringList &names, JsCallBatch &jsCallBatch)
855{
856 qCDebug(QtForOhos) << Q_FUNC_INFO << names;
857 jsCallBatch.submit(
858 [this, names](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
859 if (m_jsScopeData->isWindowClosing()) {
860 taskPromise();
861 return;
862 }
863 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
864 "setWindowSystemBarEnable(*)",
865 {QNapi::makeArray(jsState.env(), names, std::mem_fn(&QString::toStdString))})
866 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowSystemBarEnable()"))
867 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
868 },
869 Q_FUNC_INFO);
870}
871
872void QOhosWindowProxy::showAbility(JsCallBatch &jsCallBatch)
873{
874 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
875
876 jsCallBatch.submit(
877 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
878 if (m_jsScopeData->isWindowClosing()) {
879 taskPromise();
880 return;
881 }
882
883 m_jsScopeData->qAbilityPeer->qAbility().evalToPromiseOrRejectOnThrow("context.showAbility()")
884 .onCatch(QtOhos::makeErrorLoggingJsCallback("showAbility()"))
885 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
886 },
887 Q_FUNC_INFO);
888}
889
890bool QOhosWindowProxy::tryHideAbility()
891{
892 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
893
894 return QOhosJsThreadGateway::evalWithPromise<bool>([&](QOhosJsState &, QOhosTaskPromise<bool> evalPromise) {
895 if (m_jsScopeData->isWindowClosing()) {
896 evalPromise(false);
897 return;
898 }
899
900 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
901 m_jsScopeData->qAbilityPeer->qAbility().evalToPromiseOrRejectOnThrow("context.hideAbility()")
902 .onThen(
903 [thenPromise = std::move(thenCatchPromises.first)](const QtOhos::CallbackInfo &) {
904 thenPromise(true);
905 })
906 .onCatch(
907 [catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
908 QtOhos::logJsCallbackError(cbInfo, "got error from hideAbility()");
909 catchPromise(false);
910 });
911 },
912 Q_FUNC_INFO);
913}
914
915bool QOhosWindowProxy::getImmersiveModeEnabledState()
916{
917 return QOhosJsThreadGateway::eval(
918 [&](QOhosJsState &) {
919 if (m_jsScopeData->isWindowClosing())
920 return false;
921 return m_jsScopeData->jsWindowRef->eval<QNapi::Boolean>("getImmersiveModeEnabledState()").Value();
922 },
923 Q_FUNC_INFO);
924}
925
926void QOhosWindowProxy::setWindowPrivacyMode(bool privacyMode, JsCallBatch &jsCallBatch)
927{
928 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, privacyMode ? "true" : "false");
929
930 jsCallBatch.submit(
931 [this, privacyMode](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
932 if (m_jsScopeData->isWindowClosing()) {
933 taskPromise();
934 return;
935 }
936
937 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowPrivacyMode(*)", {privacyMode})
938 .onCatch(QtOhos::makeErrorLoggingJsCallback("setPrivacyMode()"))
939 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
940 },
941 Q_FUNC_INFO);
942}
943
944void QOhosWindowProxy::setWindowFocusable(bool focusable, JsCallBatch &jsCallBatch)
945{
946 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, focusable ? "true" : "false");
947 jsCallBatch.submit(
948 [this, focusable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
949 if (m_jsScopeData->isWindowClosing()) {
950 taskPromise();
951 return;
952 }
953
954 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowFocusable(*)", {focusable})
955 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowFocusable()"))
956 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
957 },
958 Q_FUNC_INFO);
959}
960
961void QOhosWindowProxy::setWindowTouchable(bool touchable, JsCallBatch &jsCallBatch)
962{
963 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, touchable ? "true" : "false");
964 jsCallBatch.submit(
965 [this, touchable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
966 if (m_jsScopeData->isWindowClosing()) {
967 taskPromise();
968 return;
969 }
970
971 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowTouchable(*)", {touchable})
972 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowTouchable()"))
973 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
974 },
975 Q_FUNC_INFO);
976}
977
978void QOhosWindowProxy::setWindowLimits(const QSize &minSize, const QSize &maxSize, JsCallBatch &jsCallBatch)
979{
980 qCDebug(
981 QtForOhos, "%s: (%d x %d)-(%d x %d)", Q_FUNC_INFO, minSize.width(), minSize.height(),
982 maxSize.width(), maxSize.height());
983 jsCallBatch.submit(
984 [this, minSize, maxSize](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
985 if (m_jsScopeData->isWindowClosing()) {
986 taskPromise();
987 return;
988 }
989 auto windowLimits = QNapi::makeObject(
990 jsState.env(),
991 {
992 {"minWidth", minSize.width()},
993 {"minHeight", minSize.height()},
994 {"maxWidth", maxSize.width()},
995 {"maxHeight", maxSize.height()},
996 });
997
998 std::vector<QNapi::ValueWrapper> setWindowLimitsArgs = {windowLimits};
1000 constexpr bool isForcible = true;
1001 setWindowLimitsArgs.push_back(isForcible);
1002 }
1003 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
1004 "setWindowLimits(*)", setWindowLimitsArgs)
1005 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowLimits()"))
1006 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1007 },
1008 Q_FUNC_INFO);
1009}
1010
1011QOhosWindowProxy::WindowLimits QOhosWindowProxy::getWindowLimits() const
1012{
1013 qCDebug(QtForOhos, "%s", Q_FUNC_INFO);
1014 return QOhosJsThreadGateway::eval(
1015 [&](QOhosJsState &) {
1016 if (m_jsScopeData->isWindowClosing())
1017 return WindowLimits {};
1018 auto windowLimitsObject = m_jsScopeData->jsWindowRef->eval<QNapi::Object>("getWindowLimits()");
1019 return WindowLimits {
1020 .minWidth = getOptionalNumberPropAsOptionalDouble(windowLimitsObject, "minWidth"),
1021 .minHeight = getOptionalNumberPropAsOptionalDouble(windowLimitsObject, "minHeight"),
1022 .maxWidth = getOptionalNumberPropAsOptionalDouble(windowLimitsObject, "maxWidth"),
1023 .maxHeight = getOptionalNumberPropAsOptionalDouble(windowLimitsObject, "maxHeight"),
1024 };
1025 },
1026 Q_FUNC_INFO);
1027}
1028
1029QOhosWindowProxy::AvoidArea QOhosWindowProxy::getWindowAvoidArea(AvoidAreaType avoidAreaType) const
1030{
1031 qCDebug(QtForOhos, "%s: %d", Q_FUNC_INFO, avoidAreaType);
1032 return QOhosJsThreadGateway::eval(
1033 [&](QOhosJsState &jsState) {
1034 if (m_jsScopeData->isWindowClosing())
1035 return AvoidArea {};
1036 auto avoidAreaObject = m_jsScopeData->jsWindowRef->eval<QNapi::Object>(
1037 "getWindowAvoidArea(*)", {jsState.mapOhosEnumToJs(avoidAreaType)});
1038 return mapAvoidAreaFromJs(avoidAreaObject);
1039 },
1040 Q_FUNC_INFO);
1041}
1042
1043void QOhosWindowProxy::setWindowMask(
1044 const WindowMask &windowMask, const std::optional<QSize> &ohosMaskSizeOverride, JsCallBatch &jsCallBatch)
1045{
1046 if (qtIsMainWindow())
1047 return;
1048
1049 jsCallBatch.submit(
1050 [this, windowMask, ohosMaskSizeOverride](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1051 if (m_jsScopeData->isWindowClosing()) {
1052 taskPromise();
1053 return;
1054 }
1055
1056 auto ohosMaskSize = ohosMaskSizeOverride.has_value()
1057 ? ohosMaskSizeOverride.value()
1058 : getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject()).windowRect.size();
1059
1060 if (ohosMaskSize.isEmpty()) {
1061 if (ohosMaskSizeOverride.has_value()) {
1062 qOhosPrintfError(
1063 "QOhosWindowProxy::setWindowMask failed - overridden mask source size is 0x0");
1064 }
1065 taskPromise();
1066 return;
1067 }
1068
1069 auto *env = jsState.env();
1070
1071 QNapi::Array maskRowsArray = QNapi::Array::New(env, ohosMaskSize.height());
1072 const int defaultValue = windowMask.windowMaskRegion.isEmpty() ? 1 : 0;
1073
1074 for (int rowIndex = 0; rowIndex < ohosMaskSize.height(); ++rowIndex) {
1075 auto arr = QNapi::Array::New(env, ohosMaskSize.width());
1076 arr.fill(defaultValue);
1077 maskRowsArray[rowIndex] = arr;
1078 }
1079
1080 auto valueToSet = QNapi::Number::New(env, 1);
1081 for (const auto &rect: windowMask.windowMaskRegion) {
1082 auto top = qBound(0, rect.top(), ohosMaskSize.height() - 1);
1083 auto bottom = qBound(0, rect.bottom(), ohosMaskSize.height() - 1);
1084 auto left = qBound(0, rect.left(), ohosMaskSize.width() - 1);
1085 auto right = qBound(0, rect.right(), ohosMaskSize.width() - 1);
1086
1087 for (auto rowIndex = top; rowIndex <= bottom; ++rowIndex) {
1088 auto row = maskRowsArray.Get(rowIndex).As<QNapi::Array>();
1089 for (auto columnIndex = left; columnIndex <= right; ++columnIndex)
1090 row[columnIndex] = valueToSet;
1091 }
1092 }
1093
1094 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowMask(*)", {maskRowsArray})
1095 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowMask()"))
1096 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1097 },
1098 Q_FUNC_INFO);
1099}
1100
1101void QOhosWindowProxy::setSubWindowModalDisabled(JsCallBatch &jsCallBatch)
1102{
1103 if (qtIsMainWindow())
1104 return;
1105
1106 jsCallBatch.submit(
1107 [this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1108 if (m_jsScopeData->isWindowClosing()) {
1109 taskPromise();
1110 return;
1111 }
1112 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setSubWindowModal(*)", {false})
1113 .onCatch(QtOhos::makeErrorLoggingJsCallback("setSubWindowModal()"))
1114 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1115 },
1116 Q_FUNC_INFO);
1117}
1118
1119void QOhosWindowProxy::setSubWindowModalEnabled(ModalityType modalityType, JsCallBatch &jsCallBatch)
1120{
1121 if (qtIsMainWindow())
1122 return;
1123
1125 qOhosPrintfWarning(
1126 "%s: APPLICATION_MODALITY option can be used only on devices in the freeform window state - skipping",
1127 Q_FUNC_INFO);
1128 return;
1129 }
1130
1131 jsCallBatch.submit(
1132 [this, modalityType](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1133 if (m_jsScopeData->isWindowClosing()) {
1134 taskPromise();
1135 return;
1136 }
1137 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
1138 "setSubWindowModal(*)", {true, jsState.mapOhosEnumToJs(modalityType)})
1139 .onCatch(QtOhos::makeErrorLoggingJsCallback("setSubWindowModal()"))
1140 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1141 },
1142 Q_FUNC_INFO);
1143}
1144
1145void QOhosWindowProxy::setTitle(const QString &title, JsCallBatch &jsCallBatch)
1146{
1147 jsCallBatch.submit(
1148 [this, title](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1149 if (m_jsScopeData->isWindowClosing()) {
1150 taskPromise();
1151 return;
1152 }
1153
1154 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowTitle(*)", {title.toStdString()})
1155 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
1156 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1157 },
1158 Q_FUNC_INFO);
1159}
1160
1161void QOhosWindowProxy::setWindowTitleButtonVisible(
1162 bool maximizeVisible, bool minimizeVisible, bool closeVisible, JsCallBatch &jsCallBatch)
1163{
1164 qOhosPrintfDebug(
1165 "%s: isMaximizeVisible:%s, isMinimizeVisible:%s, isCloseVisible:%s",
1166 Q_FUNC_INFO, maximizeVisible ? "true" : "false", minimizeVisible ? "true": "false",
1167 closeVisible ? "true" : "false");
1168
1169 if (!qtIsMainWindow())
1170 return;
1171
1172 jsCallBatch.submit(
1173 [this, maximizeVisible, minimizeVisible, closeVisible](QOhosJsState &jsState) {
1174 if (m_jsScopeData->isWindowClosing())
1175 return;
1176
1177 constexpr auto capabilityNotSupportedErrorCode = 801;
1178 std::vector<std::uint32_t> ignoredErrorCodes{capabilityNotSupportedErrorCode};
1180 constexpr auto windowStateAbnormalErrorCode = 1300002;
1181 ignoredErrorCodes.push_back(windowStateAbnormalErrorCode);
1182 }
1184 jsState, ignoredErrorCodes, "setWindowTitleButtonVisible()",
1185 [&]() {
1186 m_jsScopeData->jsWindowRef->eval(
1187 "setWindowTitleButtonVisible(*)",
1188 {maximizeVisible, minimizeVisible, closeVisible});
1189 });
1190 },
1191 Q_FUNC_INFO);
1192}
1193
1194void QOhosWindowProxy::setWindowTopmost(bool topmost, JsCallBatch &jsCallBatch)
1195{
1196 if (!qtIsMainWindow())
1197 return;
1198
1200 qOhosPrintfWarning("%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
1201 return;
1202 }
1203
1204 qOhosPrintfDebug("%s: topMost: %s", Q_FUNC_INFO, topmost ? "true" : "false");
1205
1206 jsCallBatch.submit(
1207 [this, topmost](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1208 if (m_jsScopeData->isWindowClosing()) {
1209 taskPromise();
1210 return;
1211 }
1212
1213 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowTopmost(*)", {topmost})
1214 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
1215 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1216 },
1217 Q_FUNC_INFO);
1218}
1219
1220void QOhosWindowProxy::setWindowDecorVisible(bool visible, JsCallBatch &jsCallBatch)
1221{
1222 jsCallBatch.submit(
1223 [this, visible](QOhosJsState &) {
1224 if (m_jsScopeData->isWindowClosing())
1225 return;
1226
1227 m_jsScopeData->jsWindowRef->eval("setWindowDecorVisible(*)", {visible});
1228 },
1229 Q_FUNC_INFO);
1230}
1231
1232void QOhosWindowProxy::setWindowTitleMoveEnabled(bool enabled, JsCallBatch &jsCallBatch)
1233{
1235 qOhosPrintfWarning("%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
1236 return;
1237 }
1238
1239 jsCallBatch.submit(
1240 [this, enabled](QOhosJsState &) {
1241 if (m_jsScopeData->isWindowClosing())
1242 return;
1243
1244 m_jsScopeData->jsWindowRef->eval("setWindowTitleMoveEnabled(*)", {enabled});
1245 },
1246 Q_FUNC_INFO);
1247}
1248
1249void QOhosWindowProxy::setWindowShadowRadius(double radius, JsCallBatch &jsCallBatch)
1250{
1252 qOhosPrintfWarning("%s: can be used only on 2-in-1 devices or tablets - skipping", Q_FUNC_INFO);
1253 return;
1254 }
1255
1256 if (qtIsMainWindow())
1257 return;
1258
1259 jsCallBatch.submit(
1260 [this, radius](QOhosJsState &) {
1261 m_jsScopeData->jsWindowRef->eval("setWindowShadowRadius(*)", {radius});
1262 },
1263 Q_FUNC_INFO);
1264}
1265
1266void QOhosWindowProxy::setWindowCornerRadius(double radius, JsCallBatch &jsCallBatch)
1267{
1268 if (qtIsMainWindow())
1269 return;
1270
1271 jsCallBatch.submit(
1272 [this, radius](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1273 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowCornerRadius(*)", {radius})
1274 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
1275 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1276 },
1277 Q_FUNC_INFO);
1278}
1279
1280bool QOhosWindowProxy::isWindowRectAutoSave() const
1281{
1282 return QOhosJsThreadGateway::evalWithPromise<bool>(
1283 [&](QOhosJsState &, QOhosTaskPromise<bool> evalPromise) {
1284 if (m_jsScopeData->isWindowClosing()) {
1285 evalPromise(false);
1286 return;
1287 }
1288 auto optQUiAbilityPeer = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
1289 if (!optQUiAbilityPeer) {
1290 evalPromise(false);
1291 return;
1292 }
1293
1294 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1295 optQUiAbilityPeer->windowStage()
1296 .evalToPromiseOrRejectOnThrow("isWindowRectAutoSave()")
1297 .onThen(
1298 [thenPromise = std::move(thenCatchPromises.first)](const QtOhos::CallbackInfo &cbInfo) {
1299 bool windowRectAutoSaveEnabled = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1300 thenPromise(windowRectAutoSaveEnabled);
1301 })
1302 .onCatch(
1303 [catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
1304 QtOhos::logJsCallbackError(cbInfo, "isWindowRectAutoSave()");
1305 catchPromise(false);
1306 });
1307 },
1308 Q_FUNC_INFO);
1309}
1310
1311void QOhosWindowProxy::setFollowParentMultiScreenPolicy(bool enabled, JsCallBatch &jsCallBatch)
1312{
1313 if (qtIsMainWindow())
1314 return;
1315
1316 jsCallBatch.submit(
1317 [this, enabled](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1318 if (m_jsScopeData->isWindowClosing()) {
1319 taskPromise();
1320 return;
1321 }
1322 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setFollowParentMultiScreenPolicy(*)", {enabled})
1323 .onCatch(QtOhos::makeErrorLoggingJsCallback("setFollowParentMultiScreenPolicy()"))
1324 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1325 },
1326 Q_FUNC_INFO);
1327}
1328
1329void QOhosWindowProxy::setWindowKeepScreenOn(bool keepScreenOn, JsCallBatch &jsCallBatch)
1330{
1331 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, QtOhos::mapBoolToTrueFalseStr(keepScreenOn));
1332
1333 jsCallBatch.submit(
1334 [this, keepScreenOn](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1335 if (m_jsScopeData->isWindowClosing()) {
1336 taskPromise();
1337 return;
1338 }
1339
1340 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("setWindowKeepScreenOn(*)", {keepScreenOn})
1341 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowKeepScreenOn()"))
1342 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1343 },
1344 Q_FUNC_INFO);
1345}
1346
1347void QOhosWindowProxy::setSupportedWindowModes(
1348 const std::set<SupportWindowMode> &supportedWindowModes, JsCallBatch &jsCallBatch)
1349{
1350 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, mapEnumsToLogString(supportedWindowModes).c_str());
1351
1352 jsCallBatch.submit(
1353 [this, supportedWindowModes](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1354 if (m_jsScopeData->isWindowClosing()) {
1355 taskPromise();
1356 return;
1357 }
1358
1359 auto jsSupportedWindowModes = QNapi::makeArray(
1360 jsState.env(), supportedWindowModes,
1361 [&](auto mode) {
1362 return jsState.mapOhosEnumToJs(mode);
1363 });
1364
1365 QNapi::Promise evalPromise;
1366 if (m_windowProxyType != WindowProxyType::MainWindow) {
1367 evalPromise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
1368 "setSupportedWindowModes(*)", {jsSupportedWindowModes});
1369 } else if (auto qUiAbilityPeer = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(
1370 m_jsScopeData->qAbilityPeer)) {
1371 evalPromise = qUiAbilityPeer->windowStage().evalToPromiseOrRejectOnThrow(
1372 "setSupportedWindowModes(*)", {jsSupportedWindowModes});
1373 } else {
1374 qOhosPrintfWarning(
1375 "%s: ability has no window stage, supported window modes not applied",
1376 Q_FUNC_INFO);
1377 evalPromise = QtOhos::makeResolvedPromise(Napi::Env(jsState.env()).Undefined());
1378 }
1379
1380 evalPromise
1381 .onCatch(QtOhos::makeErrorLoggingJsCallback("setSupportedWindowModes()"))
1382 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1383 },
1384 Q_FUNC_INFO);
1385}
1386
1387void QOhosWindowProxy::setWindowRectAutoSave(bool enabled, JsCallBatch &jsCallBatch)
1388{
1389 jsCallBatch.submit(
1390 [this, enabled](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1391 if (m_jsScopeData->isWindowClosing()) {
1392 taskPromise();
1393 return;
1394 }
1395 auto optQUiAbilityPeer = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
1396 if (!optQUiAbilityPeer) {
1397 taskPromise();
1398 return;
1399 }
1400
1401 constexpr bool isSaveBySpecifiedFlag = true;
1402 optQUiAbilityPeer->windowStage()
1403 .evalToPromiseOrRejectOnThrow("setWindowRectAutoSave(*)", {enabled, isSaveBySpecifiedFlag})
1404 .onCatch(QtOhos::makeErrorLoggingJsCallback("setWindowRectAutoSave()"))
1405 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1406 },
1407 Q_FUNC_INFO);
1408}
1409
1410void QOhosWindowProxy::setSubWindowCloseHandler(
1411 std::function<void()> handler, bool handlerReturnValue)
1412{
1413 m_subWindowCloseRegistrationHandle =
1414 registerSubWindowCloseHandler(std::move(handler), handlerReturnValue);
1415}
1416
1417void QOhosWindowProxy::resetSubWindowCloseHandler()
1418{
1419 m_subWindowCloseRegistrationHandle.reset();
1420}
1421
1422std::shared_ptr<void> QOhosWindowProxy::registerSubWindowCloseHandler(
1423 std::function<void()> handler, bool handlerReturnValue)
1424{
1425 auto sharedHandler = QtOhos::moveToSharedPtr(std::move(handler));
1426 auto jsWindowRegistrationHandle = QOhosJsThreadGateway::eval(
1427 [&](QOhosJsState &jsState) {
1428 return QtOhos::makeProxyWithJsThreadDeleter(
1429 m_jsScopeData->registerSubWindowCloseHandler(
1430 jsState,
1431 [weakHandler = QtOhos::makeWeakPtr(sharedHandler), handlerReturnValue]() {
1432 QtOhos::invokeInQtThread(
1433 [weakHandler]() {
1434 auto sharedHandler = weakHandler.lock();
1435 if (sharedHandler)
1436 (*sharedHandler)();
1437 });
1438 return handlerReturnValue;
1439 }));
1440 },
1441 Q_FUNC_INFO);
1442
1443 return QtOhos::moveToSharedPtr(
1444 std::make_tuple(sharedHandler, jsWindowRegistrationHandle));
1445}
1446
1447std::shared_ptr<QOhosWindowProxy>
1449{
1450 return std::shared_ptr<QOhosWindowProxy>(
1451 new QOhosWindowProxy(
1452 [&](QtOhos::JsState &jsState, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData> windowProxyDataConsumer) {
1453 makeWindowProxyDataForExistingMainWindowInJsThread(jsState, createInfo, std::move(windowProxyDataConsumer));
1454 }));
1455}
1456
1457std::shared_ptr<QOhosWindowProxy>
1458QOhosWindowProxy::createFloatWindow(const FloatWindowCreateInfo &createInfo)
1459{
1460 return std::shared_ptr<QOhosWindowProxy>(
1461 new QOhosWindowProxy(
1462 [&](QtOhos::JsState &jsState, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData> windowProxyDataConsumer) {
1463 makeWindowProxyDataForFloatWindowInJsThread(jsState, createInfo, std::move(windowProxyDataConsumer));
1464 }));
1465}
1466
1467std::shared_ptr<QOhosWindowProxy>
1468QOhosWindowProxy::createMainWindow(const MainWindowCreateInfo &createInfo)
1469{
1470 return std::shared_ptr<QOhosWindowProxy>(
1471 new QOhosWindowProxy(
1472 [&](QtOhos::JsState &jsState, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData> windowProxyDataConsumer) {
1473 makeWindowProxyDataForMainWindowInJsThread(jsState, createInfo, std::move(windowProxyDataConsumer));
1474 }));
1475}
1476
1477std::shared_ptr<QXComponentNode> QOhosWindowProxy::nodeXComponent() const
1478{
1479 return m_nodeXComponent;
1480}
1481
1482std::string QOhosWindowProxy::qAbilityInstanceId() const
1483{
1484 return m_qAbilityInstanceId;
1485}
1486
1487QHarmonyJsObjectRef QOhosWindowProxy::abilityObjectRef() const
1488{
1489 return m_abilityObjectRef;
1490}
1491
1493{
1494 return m_jsWindowObjectRef;
1495}
1496
1497std::shared_ptr<QOhosWindowProxy>
1498QOhosWindowProxy::createSubWindow(const SubWindowCreateInfo &createInfo)
1499{
1500 return std::shared_ptr<QOhosWindowProxy>(
1501 new QOhosWindowProxy(
1502 [&](QtOhos::JsState &jsState, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData> windowProxyDataConsumer) {
1503 // HACK - outside free window mode, the platform shows a maximize button that does
1504 // not work, although maximizeSupported is documented to have no effect there
1505 auto subWindowCreateInfo = createInfo;
1506 subWindowCreateInfo.maximizeSupported = createInfo.maximizeSupported
1507 && !m_jsScopeData->isWindowClosing()
1508 && isJsWindowInFreeWindowMode(*m_jsScopeData->jsWindowRef);
1509
1510 // HACK - calling createSubWindow from window may throw while the context is termination
1511 // This is only a problem because we currenlty do not properly handle main window closing
1512 // Remove this hacky branch after QTFOROH-1080 issues are resolved.
1513 if (m_jsScopeData->isWindowClosing()) {
1514 makeWindowProxyDataForSubWindowInJsThread(
1515 jsState, subWindowCreateInfo, std::move(windowProxyDataConsumer));
1516 } else {
1517 makeWindowProxyDataForSubWindowInJsThread(
1518 jsState, m_jsScopeData->jsWindowRef->jsObject(), subWindowCreateInfo,
1519 std::move(windowProxyDataConsumer));
1520 }
1521 }));
1522}
1523
1524QOhosWindowProxy::JsScopeData::JsScopeData() = default;
1525
1526QOhosWindowProxy::JsScopeData::JsScopeData(
1527 WindowProxyType windowProxyType, QNapi::Reference<QNapi::Object> jsWindow,
1528 std::shared_ptr<void> optKeepAliveData,
1529 std::shared_ptr<QtOhos::QAbilityPeer> qAbilityPeer,
1530 QtOhos::QObjectThreadSafeRef owningQWindowRef)
1531 : windowProxyType(windowProxyType)
1532 , windowCallbackReceiver(nullptr)
1533 , windowDestroyedFromSystem(false)
1534 , optKeepAliveData(optKeepAliveData)
1535 , qAbilityPeer(qAbilityPeer)
1536 , nonClientAreaEventsDispatcher(std::make_shared<NonClientAreaEventsDispatcher>())
1537 , m_windowFrameMouseFilterHandle(
1538 QArkUi::registerMouseEventsConsumer(
1539 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1540 [dispatcher = nonClientAreaEventsDispatcher](const QArkUi::MouseEvent &event) {
1541 dispatcher->onMouseEventFromArkUi(event);
1542 }))
1543 , m_windowFrameTouchFilterHandle(
1544 QArkUi::registerTouchEventsConsumer(
1545 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1546 [dispatcher = nonClientAreaEventsDispatcher](const QArkUi::TouchEvent &event) {
1547 dispatcher->onTouchEventFromArkUi(event);
1548 }))
1549 , jsWindowRef(
1550 std::make_shared<QArkUi::JsWindowRef>(
1551 qAbilityPeer->instanceId(),
1552 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1553 jsWindow.Value(),
1554 owningQWindowRef))
1555{
1556}
1557
1558QOhosWindowProxy::JsScopeData::~JsScopeData()
1559{
1560 if (jsWindowRef) {
1561 if (isWindowClosingFromSystem(jsWindowRef->jsObject(), windowProxyType, qAbilityPeer)) {
1562 windowDestroyedFromSystem = true;
1563 return;
1564 }
1565
1566 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(), "QOhosWindowProxy::JsScopeData destructor");
1567
1568 if (windowProxyType == WindowProxyType::MainWindow) {
1569 // NOTE - Set the windowDestroyedFromSystem flag here early
1570 // to avoid callbacks being invoked directly as a result of
1571 // calling terminate
1572 windowDestroyedFromSystem = true;
1573 qOhosPrintfWarning(
1574 "Attempting to terminate qAbility with instance id: %s",
1575 jsWindowRef->owningQAbilityInstanceId().c_str());
1576 qAbilityPeer->qAbility().eval("context.terminateSelf()");
1577 } else if (!windowDestroyedFromSystem) {
1578 // FIXME - destroyWindow usually does and returns nothing
1579 // once the actual implementation is provided wait for the proomise that this function should return
1580 jsWindowRef->eval("destroyWindow()");
1581 }
1582 }
1583}
1584
1585std::shared_ptr<void> QOhosWindowProxy::JsScopeData::registerEventListener(
1586 const std::string &eventName,
1587 void (QOhosWindowProxy::JsScopeData::*handleFunction)(const QtOhos::CallbackInfo &),
1588 QFlags<EventHandlerFlagBits> eventHandlerFlags)
1589{
1590
1591 std::weak_ptr<JsScopeData> weakSelf = shared_from_this();
1592 bool ignoreWhenAbilityIsTerminating = !eventHandlerFlags.testFlag(EventHandlerFlagBits::allowCallWhenAbilityIsTerminating);
1593
1594 return registerQOhosOnOffMethodsBasedEventHandler(
1595 jsWindowRef->jsObject(), eventName,
1596 [weakSelf, handleFunction, eventName, ignoreWhenAbilityIsTerminating](const QtOhos::CallbackInfo &cbInfo) {
1597 auto self = weakSelf.lock();
1598 if (Q_UNLIKELY(!self)) {
1599 qOhosPrintfWarning(
1600 "callback '%s' called for destroyed QOhosWindowProxy::JsScopeData, ignoring",
1601 eventName.c_str());
1602 return;
1603 }
1604
1605 if (self->isWindowClosing() && ignoreWhenAbilityIsTerminating) {
1606 qOhosPrintfError(
1607 "QOhosWindowProxy: Received callback for event '%s' during termination of the related QAbility.",
1608 eventName.c_str());
1609 return;
1610 }
1611
1612 if (Q_UNLIKELY(self->windowDestroyedFromSystem)) {
1613 qOhosPrintfError(
1614 "QOhosWindowProxy: Received callback for event '%s' after WINDOW_DESTROYED",
1615 eventName.c_str());
1616 return;
1617 }
1618
1619 ((*self).*handleFunction)(cbInfo);
1620 },
1621 {
1622 .optEventSourceAliveCheckFunc = {},
1623 .extraOnArg = {},
1624 .extraOffArg = {},
1625 .optOnCallExceptionHandler = [&](const Napi::Error &error) {
1626 constexpr std::uint32_t capabilityNotSupportedErrorCode = 801;
1627 constexpr std::uint32_t windowStateIsAbnormalErrorCode = 1300002;
1628
1629 const QSet<std::uint32_t> ignorableErrorCodes = {
1630 capabilityNotSupportedErrorCode,
1631 windowStateIsAbnormalErrorCode,
1632 };
1633
1634 auto errorCode = QtOhos::tryGetCodeFromJsBusinessError(error);
1635
1636 auto ignorableError =
1637 eventHandlerFlags.testFlag(EventHandlerFlagBits::allowEventHandlerRegistrationFailure)
1638 && errorCode.has_value()
1639 && ignorableErrorCodes.contains(errorCode.value());
1640
1641 if (!ignorableError)
1642 throw;
1643
1644 qOhosPrintfWarning(
1645 "%s: Ignored error %u while registering for window event '%s'",
1646 Q_FUNC_INFO, errorCode.value(), eventName.c_str());
1647 },
1648 });
1649}
1650
1651std::shared_ptr<void> QOhosWindowProxy::JsScopeData::registerSubWindowCloseHandler(
1652 QOhosJsState &, std::function<bool()> handler)
1653{
1654 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
1655 return registerQOhosOnOffMethodsBasedEventHandler(
1656 jsWindowRef->jsObject(), "subWindowClose",
1657 [weakSelf, handler = std::move(handler)](const QtOhos::CallbackInfo &cbInfo) {
1658 bool deferClose = handler();
1659 auto self = weakSelf.lock();
1660 if (self && !deferClose)
1661 QtOhos::JsWindowsTracker::tagWindowAsClosing(self->jsWindowRef->jsObject(), "subWindowClose => false");
1662 return QNapi::Boolean::New(cbInfo.Env(), deferClose);
1663 });
1664}
1665
1666void QOhosWindowProxy::JsScopeData::handleWindowEventCallback(const QtOhos::CallbackInfo &cbInfo)
1667{
1668 auto eventType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1669 // NOTE - All windowEvents should be handled by qt but currently
1670 // some are not exposed as a part of public api.
1671 WindowEvent event;
1672 try {
1673 event.type = cbInfo.jsState().mapOhosEnumFromJs<WindowEventType>(eventType);
1674 } catch (const Napi::Error &err) {
1675 qOhosPrintfError(
1676 "Error converting WindowEventType to known value: %s. Event will be ignored.", err.what());
1677 return;
1678 }
1679
1680 if (isWindowClosing() && event.type != WindowEventType::WINDOW_DESTROYED) {
1681 qOhosPrintfError(
1682 "Received WindowEvent for window when it's closing. WindowEventType: %d",
1683 event.type);
1684 return;
1685 }
1686
1687 onWindowEvent(cbInfo.jsState(), event);
1688}
1689
1690void QOhosWindowProxy::JsScopeData::handleWindowStatusCallback(const QtOhos::CallbackInfo &cbInfo)
1691{
1692 auto windowStatusType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1693 if (windowCallbackReceiver != nullptr) {
1694 windowCallbackReceiver->onWindowStatusChange(
1695 WindowStatus {
1696 .type = cbInfo.jsState().mapOhosEnumFromJs<WindowStatusType>(windowStatusType),
1697 });
1698 }
1699}
1700
1701void QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback(const QtOhos::CallbackInfo &cbInfo)
1702{
1703 auto windowVisibility = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1704 if (windowCallbackReceiver != nullptr)
1705 windowCallbackReceiver->onWindowVisibilityChange(windowVisibility);
1706}
1707
1708void QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback(const QtOhos::CallbackInfo &)
1709{
1710 if (windowCallbackReceiver != nullptr)
1711 windowCallbackReceiver->onTouchOutside();
1712}
1713
1714void QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback(const QtOhos::CallbackInfo &cbInfo)
1715{
1716 if (windowCallbackReceiver != nullptr) {
1717 auto callbackArg = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1718 windowCallbackReceiver->onAvoidAreaChange(
1719 cbInfo.jsState().mapOhosEnumFromJs<AvoidAreaType>(callbackArg.get<QNapi::Number>("type")),
1720 mapAvoidAreaFromJs(callbackArg.get<QNapi::Object>("area")));
1721 }
1722}
1723
1724void QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback(const QtOhos::CallbackInfo &cbInfo)
1725{
1726 auto rectChangeOptionsObjectArg = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1727 auto rectChangeOptions = RectChangeOptions {
1728 .rect = ohosWindowRectToQRect(rectChangeOptionsObjectArg.get<QNapi::Object>("rect")),
1729 .reason = cbInfo.jsState().mapOhosEnumFromJs<RectChangeReason>(rectChangeOptionsObjectArg.get<QNapi::Number>("reason")),
1730 };
1731
1732 if (windowCallbackReceiver != nullptr)
1733 windowCallbackReceiver->onWindowRectChange(rectChangeOptions);
1734}
1735
1736void QOhosWindowProxy::JsScopeData::handleWindowRectChangeInGlobalDisplayCallback(const QtOhos::CallbackInfo &cbInfo)
1737{
1738 auto rectChangeOptionsObjectArg = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1739 auto rectChangeOptions = RectChangeOptions {
1740 .rect = ohosWindowRectToQRect(rectChangeOptionsObjectArg.get<QNapi::Object>("rect")),
1741 .reason = cbInfo.jsState().mapOhosEnumFromJs<RectChangeReason>(rectChangeOptionsObjectArg.get<QNapi::Number>("reason")),
1742 };
1743
1744 if (windowCallbackReceiver != nullptr)
1745 windowCallbackReceiver->onWindowRectChangeInGlobalDisplay(rectChangeOptions);
1746}
1747
1748void QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback(const QtOhos::CallbackInfo &cbInfo)
1749{
1750 auto displayIdNumber = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1751 auto displayId = QOhosDisplayInfo::JsDisplayId(displayIdNumber);
1752
1753 if (windowCallbackReceiver != nullptr)
1754 windowCallbackReceiver->onWindowDisplayIdChange(displayId);
1755}
1756
1757void QOhosWindowProxy::JsScopeData::onWindowEvent(QtOhos::JsState &, const WindowEvent &windowEvent)
1758{
1759 if (windowEvent.type == WindowEventType::WINDOW_DESTROYED) {
1760 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(), "WINDOW_DESTROYED");
1761 windowDestroyedFromSystem = true;
1762 }
1763
1764 if (windowCallbackReceiver != nullptr)
1765 windowCallbackReceiver->onWindowEvent(windowEvent);
1766}
1767
1768bool QOhosWindowProxy::JsScopeData::isWindowClosing() const
1769{
1770 return isWindowClosingFromSystem(jsWindowRef->jsObject(), windowProxyType, qAbilityPeer);
1771}
1772
1773void QOhosWindowProxy::JsScopeData::NonClientAreaEventsDispatcher::onMouseEventFromArkUi(const QArkUi::MouseEvent &event) const
1774{
1775 if (mouseEventsConsumer == nullptr)
1776 return;
1777
1778 auto optAction = tryMapMouseEventActionToNonClientAreaEventType(event.action);
1779 if (!optAction.has_value())
1780 return;
1781
1782 auto optWindowProperties = QArkUi::tryGetWindowProperties(event.jsWindowId);
1783 if (!optWindowProperties.has_value()) {
1784 qOhosPrintfError(
1785 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1786 Q_FUNC_INFO, event.jsWindowId.value());
1787 return;
1788 }
1789
1790 const auto &windowProperties = optWindowProperties.value();
1791 if (!isPointInNonClientArea(event.displayPosition, windowProperties))
1792 return;
1793
1794 auto windowOrigin = windowProperties.windowRect.topLeft() + windowProperties.drawableRect.topLeft();
1795 NonClientAreaMouseEvent nonClientAreaMouseEvent = {
1796 .timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(event.actionTime),
1797 .action = optAction.value(),
1798 .button = tryMapMouseEventButtonToQt(event.button).value_or(Qt::NoButton),
1799 .displayPosition = event.displayPosition,
1800 .localPosition = event.displayPosition - windowOrigin,
1801 .globalPosition = event.globalPosition,
1802 };
1803
1804 mouseEventsConsumer(nonClientAreaMouseEvent);
1805}
1806
1807void QOhosWindowProxy::JsScopeData::NonClientAreaEventsDispatcher::onTouchEventFromArkUi(const QArkUi::TouchEvent &event) const
1808{
1809 if (touchEventsConsumer == nullptr)
1810 return;
1811
1812 auto optAction = tryMapTouchEventActionToNonClientAreaEventType(event.action);
1813 if (!optAction.has_value())
1814 return;
1815
1816 auto optWindowProperties = QArkUi::tryGetWindowProperties(event.jsWindowId);
1817 if (!optWindowProperties.has_value()) {
1818 qOhosPrintfError(
1819 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1820 Q_FUNC_INFO, event.jsWindowId.value());
1821 return;
1822 }
1823
1824 const auto &windowProperties = optWindowProperties.value();
1825 if (!isPointInNonClientArea(event.displayPosition, windowProperties))
1826 return;
1827
1828 auto windowOrigin = windowProperties.windowRect.topLeft() + windowProperties.drawableRect.topLeft();
1829 NonClientAreaTouchEvent nonClientAreaTouchEvent = {
1830 .id = event.fingerId,
1831 .timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(event.actionTime),
1832 .action = optAction.value(),
1833 .displayPosition = event.displayPosition,
1834 .localPosition = event.displayPosition - windowOrigin,
1835 .globalPosition = event.globalPosition,
1836 };
1837
1838 touchEventsConsumer(nonClientAreaTouchEvent);
1839}
1840
1841QPixmap QOhosWindowProxy::snapshot() const
1842{
1843 return QOhosJsThreadGateway::evalWithPromise<QPixmap>(
1844 [&](QOhosJsState &, QOhosTaskPromise<QPixmap> evalPromise) {
1845 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1846 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("snapshot()")
1847 .onThen(
1848 [thenPromise = std::move(thenCatchPromises.first)](const QtOhos::CallbackInfo &cbInfo) {
1849 auto napiPixmap = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1850
1851 ::OH_PixelmapNative *pixelMapNativePtr;
1852 QArkUi::callArkUiOrFailOnErrorResult(
1853 Q_OHOS_NAMED_FUNC(::OH_PixelmapNative_ConvertPixelmapNativeFromNapi),
1854 cbInfo.Env(), napiPixmap, &pixelMapNativePtr);
1855 auto pixelMap = wrapOhosNativePixelMapPtr(pixelMapNativePtr);
1856
1857 thenPromise(
1858 QPixmap::fromImage(createQImageFromNativePixelMap(pixelMap.get())));
1859 })
1860 .onCatch(
1861 [catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
1862 QtOhos::logJsCallbackError(cbInfo, "Got error from snapshot()");
1863 catchPromise(QPixmap());
1864 });
1865 },
1866 Q_FUNC_INFO);
1867}
1868
1869QList<QRect> QOhosWindowProxy::getDisplayCutoutRects() const
1870{
1871 // The display cutout (e.g. camera hole) is not in getWindowAvoidArea(); read
1872 // it from the display. Returns the bounding rects in display coordinates.
1873 return QOhosJsThreadGateway::evalWithPromise<QList<QRect>>(
1874 [&](QOhosJsState &jsState, QOhosTaskPromise<QList<QRect>> evalPromise) {
1875 if (m_jsScopeData->isWindowClosing()) {
1876 evalPromise(QList<QRect>());
1877 return;
1878 }
1879
1880 auto optWindowDisplay = qAndThen(
1881 getWindowPropertiesFromJsWindow(
1882 m_jsScopeData->jsWindowRef->jsObject()).displayId,
1883 [&](QOhosDisplayInfo::JsDisplayId id) {
1884 return QOhosDisplayInfo::tryGetDisplayById(jsState, id);
1885 });
1886 auto display = optWindowDisplay.has_value()
1887 ? optWindowDisplay.value()
1888 : jsState.eval<QNapi::Object>("@ohos.display.getDefaultDisplaySync()");
1889
1890 auto branches = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1891 display
1892 .evalToPromiseOrRejectOnThrow("getCutoutInfo()")
1893 .onThen(
1894 [thenPromise = std::move(branches.first)](const QtOhos::CallbackInfo &cbInfo) {
1895 auto cutoutInfo = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
1896 auto cutoutRects = QNapi::getArrayElements<QList<QRect>, QNapi::Object>(
1897 cutoutInfo.get<QNapi::Array>("boundingRects"), [](QNapi::Object r) {
1898 return QRect(r.get<QNapi::Number>("left"),
1899 r.get<QNapi::Number>("top"),
1900 r.get<QNapi::Number>("width"),
1901 r.get<QNapi::Number>("height"));
1902 });
1903 thenPromise(cutoutRects);
1904 })
1905 .onCatch(
1906 [catchPromise = std::move(branches.second)](const QtOhos::CallbackInfo &cbInfo) {
1907 QtOhos::logJsCallbackError(cbInfo, "getCutoutInfo() failed");
1908 catchPromise(QList<QRect>());
1909 });
1910 },
1911 Q_FUNC_INFO);
1912}
1913
1914bool QOhosWindowProxy::startMoving()
1915{
1916 QOhosJsThreadGateway::invokeAndWaitForContinue(
1917 [&](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1918 if (m_jsScopeData->isWindowClosing()) {
1919 taskPromise();
1920 return;
1921 }
1922
1923 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("startMoving()")
1924 .onCatch(QtOhos::makeErrorLoggingJsCallback("startMoving()"))
1925 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1926 },
1927 Q_FUNC_INFO);
1928
1929 return true;
1930}
1931
1932void QOhosWindowProxy::enableDrag(bool enable, JsCallBatch &jsCallBatch)
1933{
1934 qCDebug(QtForOhos, "%s: %s", Q_FUNC_INFO, QtOhos::mapBoolToTrueFalseStr(enable));
1935
1936 if (qtIsMainWindow()) {
1937 qCWarning(QtForOhos(), "%s: enableDrag is not supported on main windows", Q_FUNC_INFO);
1938 return;
1939 }
1940
1941 jsCallBatch.submit(
1942 [this, enable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1943 if (m_jsScopeData->isWindowClosing()) {
1944 taskPromise();
1945 return;
1946 }
1947 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow("enableDrag(*)", {enable})
1948 .onCatch(QtOhos::makeErrorLoggingJsCallback("enableDrag()"))
1949 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1950 },
1951 Q_FUNC_INFO);
1952}
1953
1954std::optional<bool> QOhosWindowProxy::isFocused() const
1955{
1956 return QOhosJsThreadGateway::eval(
1957 [&](QOhosJsState &) -> std::optional<bool> {
1958 if (m_jsScopeData->isWindowClosing())
1959 return std::nullopt;
1960
1961 return m_jsScopeData->jsWindowRef->eval<QNapi::Boolean>("isFocused()");
1962 },
1963 Q_FUNC_INFO);
1964}
1965
1966std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryWindowIdsByCoordinate(
1967 QOhosDisplayInfo::JsDisplayId displayId, const QPoint &queryLocation, std::uint32_t queryLimit)
1968{
1969 return QOhosJsThreadGateway::evalWithPromise<std::vector<QArkUi::JsWindowId>>(
1970 [&](QOhosJsState &jsState, auto evalPromise) {
1971 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1972 jsState.evalToPromiseOrRejectOnThrow("@ohos.window.getWindowsByCoordinate(*)", {
1973 displayId.value(),
1974 queryLimit,
1975 queryLocation.x(),
1976 queryLocation.y()
1977 })
1978 .onThen([thenPromise = std::move(thenCatchPromises.first)](const QtOhos::CallbackInfo &cbInfo) {
1979 auto windowsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
1980 thenPromise(
1981 QNapi::getArrayElements<std::vector<QArkUi::JsWindowId>, QNapi::Object>(
1982 windowsArray,
1983 [&](QNapi::Object jsWindow) {
1984 return getWindowPropertiesFromJsWindow(jsWindow).id;
1985 }));
1986 })
1987 .onCatch([catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
1988 QtOhos::logJsCallbackError(
1989 cbInfo, "got error from @ohos.window.getWindowsByCoordinate()");
1990 catchPromise({});
1991 });
1992 },
1993 Q_FUNC_INFO);
1994}
1995
1996std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryQtManagedWindowIdsByPredicate(
1997 const std::function<bool(QOhosJsState &, const QArkUi::JsWindowRef &)> &predicate)
1998{
1999 return QOhosJsThreadGateway::eval([&](QOhosJsState &jsState) {
2000 return QOhosJsWindowRegistry::instance(jsState).queryByPredicate(jsState, predicate);
2001 },
2002 Q_FUNC_INFO);
2003}
2004
2005void QOhosWindowProxy::moveWindowToGlobal(
2006 const QPoint &position, const MoveConfiguration &moveConfiguration, JsCallBatch &jsCallBatch)
2007{
2008 jsCallBatch.submit(
2009 [this, position, moveConfiguration](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
2010 if (m_jsScopeData->isWindowClosing()) {
2011 taskPromise();
2012 return;
2013 }
2014
2015 auto moveConfigurationObject = toNapiObject(jsState.env(), moveConfiguration);
2016 auto moveConfigurationObjectStr = QNapi::toJsonString(moveConfigurationObject);
2017 qOhosPrintfDebug(
2018 "%s: %d,%d,%s",
2019 Q_FUNC_INFO, position.x(), position.y(),
2020 moveConfigurationObjectStr.c_str());
2021
2022 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
2023 "moveWindowToGlobal(*)", {position.x(), position.y(), moveConfigurationObject})
2024 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
2025 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
2026 },
2027 Q_FUNC_INFO);
2028}
2029
2030std::optional<QOhosDisplayInfo::JsDisplayId> QOhosWindowProxy::tryGetMainWindowJsDisplayId() const
2031{
2032 return qtIsMainWindow()
2033 ? getWindowProperties().displayId
2034 : QOhosJsThreadGateway::eval(
2035 [&](QOhosJsState &) {
2036 auto qUiAbilityPeer
2037 = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
2038 return qUiAbilityPeer
2039 ? getWindowPropertiesFromJsWindow(qUiAbilityPeer->window()).displayId
2040 : std::nullopt;
2041 },
2042 Q_FUNC_INFO);
2043}
2044
2045bool QOhosWindowProxy::tryShiftAppWindowFocus(QOhosWindowProxy &targetProxy)
2046{
2047 return QOhosJsThreadGateway::evalWithPromise<bool>(
2048 [&](QOhosJsState &jsState, QOhosTaskPromise<bool> evalPromise) {
2049 if (m_jsScopeData->isWindowClosing() || targetProxy.m_jsScopeData->isWindowClosing()) {
2050 evalPromise(false);
2051 return;
2052 }
2053
2054 auto srcWindowId = getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject()).id;
2055 auto targetWindowId = getWindowPropertiesFromJsWindow(targetProxy.m_jsScopeData->jsWindowRef->jsObject()).id;
2056 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
2057 jsState.evalToPromiseOrRejectOnThrow(
2058 "@ohos.window.shiftAppWindowFocus(*)", {srcWindowId.value(), targetWindowId.value()})
2059 .onThen(
2060 [thenPromise = std::move(thenCatchPromises.first)]() {
2061 thenPromise(true);
2062 })
2063 .onCatch(
2064 [catchPromise = std::move(thenCatchPromises.second)](const QtOhos::CallbackInfo &cbInfo) {
2065 QtOhos::logJsCallbackError(cbInfo, "Got error from @ohos.window.shiftAppWindowFocus()");
2066 catchPromise(false);
2067 });
2068 },
2069 Q_FUNC_INFO);
2070}
2071
2072QT_END_NAMESPACE
bool isWindowPcModeEnabled() const
static QOhosSettings & instance()
void setWindowKeepScreenOn(bool keepScreenOn, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setFollowParentMultiScreenPolicy(bool enabled, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setNonClientAreaMouseWindowCallbackReceiver(QObject *contextObject, QOhosConsumer< std::vector< NonClientAreaMouseEvent > > mouseEventBatchConsumer, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QHarmonyJsObjectRef jsWindowObjectRef() const
QtOhosQpa::enums::ohos::window::MaximizePresentation MaximizePresentation
bool isSubWindowMaximizeSupported() const
void moveWindowToGlobalOrGlobalDisplay(const QPoint &position, std::optional< QOhosDisplayInfo::JsDisplayId > optDisplayId, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setTitle(const QString &title, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
static std::shared_ptr< QOhosWindowProxy > createFloatWindow(const FloatWindowCreateInfo &createInfo)
void moveWindowToGlobal(const QPoint &position, const MoveConfiguration &moveConfiguration, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QArkUi::WindowProperties getWindowProperties() const
void setWindowBackgroundColor(const QColor &color, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowRectAutoSave(bool enabed, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowMask(const WindowMask &windowMask, const std::optional< QSize > &ohosMaskSizeOverride={}, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowShadowRadius(double radius, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void recover(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QtOhosQpa::enums::ohos::window::WindowEventType WindowEventType
void minimize(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
AvoidArea getWindowAvoidArea(AvoidAreaType type) const
void setWindowTitleButtonVisible(bool maximizeVisible, bool minimizeVisible, bool closeVisible, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowLayoutFullScreen(bool isLayoutFullScreen, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
std::optional< QOhosDisplayInfo::JsDisplayId > tryGetMainWindowJsDisplayId() const
void setWindowTouchable(bool touchable, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QOhosWindowProxyExistingMainWindowCreateInfo ExistingMainWindowCreateInfo
void setWindowCallbackReceiver(std::unique_ptr< WindowCallbacks > receiver, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
bool tryMaximize(MaximizePresentation maximizePresentation)
void setWindowDecorVisible(bool visible, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
std::shared_ptr< QOhosWindowProxy > createSubWindow(const SubWindowCreateInfo &createInfo)
QPixmap snapshot() const
static std::shared_ptr< QOhosWindowProxy > createForExistingMainWindow(const ExistingMainWindowCreateInfo &createInfo)
void setWindowCornerRadius(double radius, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setSupportedWindowModes(const std::set< SupportWindowMode > &supportedWindowModes, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowSystemBarEnable(const QStringList &names, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void enableDrag(bool enable, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
std::shared_ptr< QXComponentNode > nodeXComponent() const
void showWindow(const ShowWindowOptions &options=ShowWindowOptions(), JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setNonClientAreaTouchWindowCallbackReceiver(QObject *contextObject, QOhosConsumer< std::vector< NonClientAreaTouchEvent > > touchEventBatchConsumer, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowFocusable(bool focusable, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowTitleMoveEnabled(bool enabled, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setCustomCursor(const QImage &customCursorImage, const QPoint &hotSpot, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void restore(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setSubWindowCloseHandler(std::function< void()> handler, bool handlerReturnValue)
std::optional< bool > isFocused() const
QtOhosQpa::enums::ohos::window::ModalityType ModalityType
bool isWindowRectAutoSave() const
QOhosWindowProxySubWindowCreateInfo SubWindowCreateInfo
QtOhosQpa::enums::ohos::window::AvoidAreaType AvoidAreaType
void raiseToAppTop(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setWindowTopmost(bool topmost, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QOhosWindowProxyMainWindowCreateInfo MainWindowCreateInfo
QtOhos::JsCallBatch JsCallBatch
bool qtIsMainWindow() const
void setWindowPrivacyMode(bool privacyMode, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QOhosWindowProxyFloatWindowCreateInfo FloatWindowCreateInfo
void setSize(const QSize &size, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setSubWindowModalDisabled(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QList< QRect > getDisplayCutoutRects() const
void setSubWindowModalEnabled(ModalityType ModalityType, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
bool tryShiftAppWindowFocus(QOhosWindowProxy &targetProxy)
void removeStartingWindow(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
WindowLimits getWindowLimits() const
std::string qAbilityInstanceId() const
void showAbility(JsCallBatch &jsCallBatch=JsCallBatch::immediate())
QHarmonyJsObjectRef abilityObjectRef() const
void setWindowLimits(const QSize &minSize, const QSize &maxSize, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
void setPointerStyleSync(const QCursor &cursor, JsCallBatch &jsCallBatch=JsCallBatch::immediate())
static std::shared_ptr< QOhosWindowProxy > createMainWindow(const MainWindowCreateInfo &createInfo)
JsState & jsState() const
static std::shared_ptr< QUiAbilityPeer > tryCastFromQAbilityPeerOrNull(std::shared_ptr< QAbilityPeer > qAbilityPeer)
std::optional< WindowProperties > tryGetWindowProperties(JsWindowId jsWindowId)
Definition window.cpp:28
Combined button and popup list for selecting options.
QRect ohosWindowRectToQRect(const QNapi::Object &ohosWindowRect)
bool isPointInNonClientArea(const QPoint &point, const QArkUi::WindowProperties &windowProperties)
bool isJsWindowInFreeWindowMode(const QArkUi::JsWindowRef &jsWindowRef)
std::optional< QEvent::Type > tryMapMouseEventActionToNonClientAreaEventType(::Input_MouseEventAction action)
std::optional< double > getOptionalNumberPropAsOptionalDouble(const QNapi::Object &object, const std::string &propertyName)
QOhosPointerStyle convertToOhosCursor(Qt::CursorShape shape)
QOhosWindowProxy::AvoidArea mapAvoidAreaFromJs(const QNapi::Object &avoidAreaObject)
std::string mapEnumsToLogString(const EnumsContainer &enums)
std::optional< Qt::MouseButton > tryMapMouseEventButtonToQt(::Input_MouseEventButton button)
bool isWindowClosingFromSystem(QNapi::Object jsWindow, WindowProxyType windowType, std::shared_ptr< QtOhos::QAbilityPeer > abilityPeer)
bool isAbilityTerminating(QNapi::Object ability)
QtOhosQpa::enums::ohos::multimodalInput::pointer::PointerStyle QOhosPointerStyle
QArkUi::WindowProperties getWindowPropertiesFromJsWindow(QNapi::Object jsWindow)
std::function< void(Args...)> makeQtThreadWindowCallbackDelegate(std::function< void(Args...)> QOhosWindowProxy::WindowCallbacks::*memberPtr, std::shared_ptr< QOhosWindowProxy::WindowCallbacks > qtWindowCallbacks)
std::function< void(T)> makeCompressingQtThreadWindowCallbackDelegate(std::function< void(T)> QOhosWindowProxy::WindowCallbacks::*memberPtr, std::shared_ptr< QOhosWindowProxy::WindowCallbacks > qtWindowCallbacks)
QNapi::Object toNapiObject(napi_env env, const QOhosWindowProxy::MoveConfiguration &moveConfiguration)
std::optional< QEvent::Type > tryMapTouchEventActionToNonClientAreaEventType(::Input_TouchEventAction action)
std::string const char * mapBoolToTrueFalseStr(bool value)
bool isEmulatorQuirkWorkaroundsEnabled()
bool runIgnoringJsBusinessError(QOhosJsState &, const std::vector< std::uint32_t > &suppressedErrorCodes, const char *callerContextName, const std::function< void()> &action)
QXComponent< QXComponentType::Node > QXComponentNode
Definition qxcomponent.h:44
std::int32_t fingerId
Definition input.h:54
bool isDisplayMainOrExtended() const
void onTouchEventFromArkUi(const QArkUi::TouchEvent &event) const
void onMouseEventFromArkUi(const QArkUi::MouseEvent &event) const