4#include <render/qohoswindowproxy.h>
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>
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>
48 ohosWindowRect.get<QNapi::Number>(
"left"),
49 ohosWindowRect.get<QNapi::Number>(
"top"),
50 ohosWindowRect.get<QNapi::Number>(
"width"),
51 ohosWindowRect.get<QNapi::Number>(
"height"),
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")),
71 case Qt::UpArrowCursor:
79 case Qt::SizeVerCursor:
81 case Qt::SizeHorCursor:
83 case Qt::SizeBDiagCursor:
85 case Qt::SizeFDiagCursor:
87 case Qt::SizeAllCursor:
92 case Qt::SplitVCursor:
94 case Qt::SplitHCursor:
96 case Qt::PointingHandCursor:
98 case Qt::ForbiddenCursor:
100 case Qt::WhatsThisCursor:
104 case Qt::OpenHandCursor:
106 case Qt::ClosedHandCursor:
108 case Qt::DragCopyCursor:
110 case Qt::DragMoveCursor:
112 case Qt::DragLinkCursor:
115 case Qt::BitmapCursor:
118 case Qt::CustomCursor:
128 auto propOrEmpty = QNapi::getOptionalPropOrEmpty<QNapi::Number>(object, propertyName);
129 return !propOrEmpty.IsEmpty()
130 ?
std::optional<
double>(propOrEmpty)
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()})
150 auto moveConfigurationObject = QNapi::makeObject(env);
151 if (moveConfiguration.displayId.has_value()) {
152 moveConfigurationObject.set(
153 "displayId", moveConfiguration.displayId.value().value());
155 return moveConfigurationObject;
158template<
typename ...Args>
160 std::function<
void(Args...)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
163 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
165 return [memberPtr, weakQtWindowCallbacks](Args ...args) {
166 QtOhos::invokeInQtThread([memberPtr, weakQtWindowCallbacks, args...]() {
167 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
168 if (qtWindowCallbacks)
169 (*qtWindowCallbacks.*memberPtr)(args...);
176 std::function<
void(T)> QOhosWindowProxy::WindowCallbacks::*memberPtr,
179 auto weakQtWindowCallbacks = QtOhos::makeWeakPtr(qtWindowCallbacks);
181 return QtOhos::makeCompressingAsyncConsumer<T>(
182 [memberPtr, weakQtWindowCallbacks](T value) {
183 auto qtWindowCallbacks = weakQtWindowCallbacks.lock();
184 if (qtWindowCallbacks)
185 (*qtWindowCallbacks.*memberPtr)(value);
187 QtOhos::invokeInQtThread);
192 constexpr bool containsPolicyExcludeEdgeValue =
true;
194 auto drawableRectInScreenSpace =
195 windowProperties.drawableRect.translated(windowProperties.windowRect.topLeft());
196 return !drawableRectInScreenSpace.contains(point, containsPolicyExcludeEdgeValue);
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:
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:
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:
251template<
typename EnumsContainer>
255 for (
auto enumValue : enums) {
258 output +=
std::to_string(
static_cast<std::underlying_type_t<
decltype(enumValue)>>(enumValue));
265 return ability.eval<QNapi::Boolean>(
"context.isTerminating()");
271 return jsWindowRef.eval<QNapi::Boolean>(
"isInFreeWindowMode()");
272 }
catch (
const Napi::Error &error) {
273 qOhosPrintfWarning(
"isInFreeWindowMode() failed (%s), assuming it is not", error.what());
282 return QtOhos::JsWindowsTracker::isWindowClosing(jsWindow) || (boundToAbility && isAbilityTerminating(abilityPeer->qAbility()));
287const QOhosWindowProxy::EventHandlerDescriptor QOhosWindowProxy::eventHandlerDescriptors[] = {
289 .eventName =
"avoidAreaChange",
290 .eventHandler = &QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback,
291 .eventHandlerFlags = {},
294 .eventName =
"touchOutside",
295 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback,
296 .eventHandlerFlags = {},
299 .eventName =
"windowEvent",
300 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowEventCallback,
301 .eventHandlerFlags = EventHandlerFlagBits::allowCallWhenAbilityIsTerminating,
304 .eventName =
"windowRectChange",
305 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback,
306 .eventHandlerFlags = {},
309 .eventName =
"rectChangeInGlobalDisplay",
310 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowRectChangeInGlobalDisplayCallback,
311 .eventHandlerFlags = {},
314 .eventName =
"windowStatusChange",
315 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowStatusCallback,
316 .eventHandlerFlags = {},
319 .eventName =
"windowVisibilityChange",
320 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback,
321 .eventHandlerFlags = {},
324 .eventName =
"displayIdChange",
325 .eventHandler = &QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback,
326 .eventHandlerFlags = EventHandlerFlagBits::allowEventHandlerRegistrationFailure,
330QOhosWindowProxy::QOhosWindowProxy(
331 const std::function<
void(
QtOhos::
JsState &, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData>)> &makeWindowProxyDataInJsThread)
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)));
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);
352QOhosWindowProxy::JsThreadInitResult QOhosWindowProxy::initInJsThread(
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);
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));
369 m_jsScopeData->m_eventListenersHandle = QtOhos::moveToSharedPtr(std::move(eventListenersHandles));
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),
391 m_jsWindowRegistrationHandle.reset();
392 m_subWindowCloseRegistrationHandle.reset();
398 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
399 if (m_jsScopeData->isWindowClosing()) {
403 auto optQUiAbilityPeer
405 if (!optQUiAbilityPeer) {
409 auto promise = optQUiAbilityPeer->windowStage().evalToPromiseOrRejectOnThrow(
410 "removeStartingWindow()");
412 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
413 .onFinally(
std::move(taskPromise).makeChained(Q_FUNC_INFO));
421 auto displayIdValue = optMoveToTargetDisplay.value_or(QOhosDisplayInfo::JsDisplayId(-1)).value();
422 qOhosPrintfDebug(
"%s: %d,%d,%f", Q_FUNC_INFO, point.x(), point.y(), displayIdValue);
425 [
this, point, optMoveToTargetDisplay](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
426 if (m_jsScopeData->isWindowClosing()) {
431 const auto primaryJsDisplayId = QOhosDisplayInfo::JsDisplayId(0);
433 auto targetDisplayId = optMoveToTargetDisplay.has_value()
434 ? optMoveToTargetDisplay.value()
437 auto optDisplayInfo = qTransform(
438 QOhosDisplayInfo::tryGetDisplayById(jsState, targetDisplayId),
439 [&](
auto displayObject) {
440 return QOhosDisplayInfo::makeFromOhosDisplayObject(jsState, displayObject);
443 auto optIsDisplayMainOrExtended = qTransform(
449 bool isDisplayMainOrExtended;
450 if (optIsDisplayMainOrExtended.has_value()) {
451 isDisplayMainOrExtended = optIsDisplayMainOrExtended.value();
454 "%s: no display source mode detected. Assumming main/extended screen", Q_FUNC_INFO);
455 isDisplayMainOrExtended =
true;
458 QNapi::Promise promise;
459 if (!isDisplayMainOrExtended) {
460 auto optDisplayOffset = qAndThen(
463 return displayInfo.topLeftOffsetPixels;
466 const QPoint defaultDisplayOffset(0, 0);
467 auto targetCoordinates = point - optDisplayOffset.value_or(defaultDisplayOffset);
469 if (!optMoveToTargetDisplay.has_value())
470 qOhosPrintfWarning(
"%s: trying to move window to not valid target display", Q_FUNC_INFO);
472 auto moveConfigurationObject = toNapiObject(
475 .displayId = optMoveToTargetDisplay,
478 promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
479 "moveWindowToGlobal(*)", {targetCoordinates.x(), targetCoordinates.y(), moveConfigurationObject});
481 promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
482 "moveWindowToGlobalDisplay(*)", {point.x(), point.y()});
485 const char *errorMessagePrefix = !isDisplayMainOrExtended
486 ?
"Got error from moveWindowToGlobal()"
487 :
"Got error from moveWindowToGlobalDisplay()";
488 auto weakWindowCallbackReceiver = QtOhos::makeWeakPtr(m_jsScopeData->windowCallbackReceiver);
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);
497 .onFinally(
std::move(taskPromise));
504 qOhosPrintfDebug(
"%s: %d,%d", Q_FUNC_INFO, size.width(), size.height());
507 [
this, size](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
508 if (m_jsScopeData->isWindowClosing()) {
513 const auto currentSize = getWindowPropertiesFromJsWindow(
514 m_jsScopeData->jsWindowRef->jsObject()).windowRect.size();
515 if (currentSize == size) {
520 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
521 "resizeAsync(*)", {size.width(), size.height()});
522 auto weakWindowCallbackReceiver = QtOhos::makeWeakPtr(m_jsScopeData->windowCallbackReceiver);
526 QtOhos::logJsCallbackError(cbInfo,
"Got error from resizeAsync()");
527 auto windowCallbackReceiver = weakWindowCallbackReceiver.lock();
528 if (windowCallbackReceiver)
529 windowCallbackReceiver->onWindowResizeRejected(size);
531 .onFinally(
std::move(taskPromise).makeChained(Q_FUNC_INFO));
538 qCDebug(QtForOhos) << Q_FUNC_INFO << color;
541 [
this, color](QOhosJsState &) {
542 if (m_jsScopeData->isWindowClosing())
544 m_jsScopeData->jsWindowRef->eval(
"setWindowBackgroundColor(*)", {color.name(QColor::HexArgb).toStdString()});
551 const auto maxOhosCustomCursorSize = QSize(256, 256);
552 const auto customCursorSize = customCursorImage.size();
553 if (customCursorSize.width() > maxOhosCustomCursorSize.width()
554 || customCursorSize.height() > maxOhosCustomCursorSize.height()) {
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());
562 auto convertedImage = customCursorImage.convertToFormat(QImage::Format_RGBA8888);
564 [
this, convertedImage, hotSpot](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
565 if (m_jsScopeData->isWindowClosing()) {
569 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>(
"getWindowProperties().id");
571 auto jsCursor = QNapi::makeObject(
574 {
"pixelMap", makeOhosNapiPixelMapFromQImage(jsState, convertedImage)},
575 {
"focusX", hotSpot.x()},
576 {
"focusY", hotSpot.y()},
579 auto jsCursorConfig = QNapi::makeObject(
582 {
"followSystem",
false},
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));
595 const auto cursorShape = cursor.shape();
597 [
this, cursorShape](QOhosJsState &jsState) {
598 if (m_jsScopeData->isWindowClosing())
600 auto windowId = m_jsScopeData->jsWindowRef->jsObject().get<QNapi::Number>(
"getWindowProperties().id");
603 "@ohos.multimodalInput.pointer.setPointerStyleSync(*)",
604 {windowId, jsState.mapOhosEnumToJs(convertToOhosCursor(cursorShape))});
611 return QOhosJsThreadGateway::eval(
612 [&](QOhosJsState &) {
613 if (m_jsScopeData->isWindowClosing())
614 return QArkUi::WindowProperties {};
615 return getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject());
621 std::unique_ptr<WindowCallbacks> callbackReceiver,
JsCallBatch &jsCallBatch)
624 m_qtWindowCallbacksReceiverHandle = sharedWindowCallbackReceiver;
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),
645 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaMouseEvent>> mouseEventBatchConsumer,
648 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(mouseEventBatchConsumer));
649 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
652 QtOhos::QObjectThreadSafeRef(contextObject),
653 [weakQtConsumer](std::vector<NonClientAreaMouseEvent> &&batch) {
654 auto qtConsumer = weakQtConsumer.lock();
656 (*qtConsumer)(
std::move(batch));
659 m_qtNonClientAreaMouseWindowCallbackReceiverHandle = qtConsumer;
662 [
this, jsConsumer = std::move(jsConsumer)](QOhosJsState &)
mutable {
663 m_jsScopeData->nonClientAreaEventsDispatcher->mouseEventsConsumer = std::move(jsConsumer);
669 QObject *contextObject, QOhosConsumer<std::vector<NonClientAreaTouchEvent>> touchEventBatchConsumer,
672 auto qtConsumer = QtOhos::moveToSharedPtr(std::move(touchEventBatchConsumer));
673 auto weakQtConsumer = QtOhos::makeWeakPtr(qtConsumer);
676 QtOhos::QObjectThreadSafeRef(contextObject),
677 [weakQtConsumer](std::vector<NonClientAreaTouchEvent> &&batch) {
678 auto qtConsumer = weakQtConsumer.lock();
680 (*qtConsumer)(
std::move(batch));
683 m_qtNonClientAreaTouchWindowCallbackReceiverHandle = qtConsumer;
686 [
this, jsConsumer = std::move(jsConsumer)](QOhosJsState &)
mutable {
687 m_jsScopeData->nonClientAreaEventsDispatcher->touchEventsConsumer = std::move(jsConsumer);
699 return m_subWindowMaximizeSupported;
704 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
706 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
707 if (m_jsScopeData->isWindowClosing()) {
711 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"raiseToAppTop()");
713 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
714 .onFinally(
std::move(taskPromise).makeChained(Q_FUNC_INFO));
721 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
723 [
this, options](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
724 if (m_jsScopeData->isWindowClosing()) {
729 std::vector<std::pair<std::string, QNapi::ValueWrapper>> jsOptionsProps;
731 if (options.focusOnShow.has_value())
732 jsOptionsProps.emplace_back(
"focusOnShow", options.focusOnShow.value());
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));
739 auto promise = m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"showWindow(*)", showWindowArgs);
741 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
742 .onFinally(
std::move(taskPromise).makeChained(Q_FUNC_INFO));
749 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
751 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
752 if (m_jsScopeData->isWindowClosing()) {
757 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"recover()")
758 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"recover()"))
759 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
766 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
768 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
769 if (m_jsScopeData->isWindowClosing()) {
773 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"restore()")
774 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
775 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
782 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
784 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
785 if (m_jsScopeData->isWindowClosing()) {
789 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"minimize()")
790 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
791 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
798 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
801 qCWarning(QtForOhos(),
"%s: Maximize is currently supported only on main and sub windows", Q_FUNC_INFO);
805 return QOhosJsThreadGateway::evalWithPromise<
bool>(
806 [&](QOhosJsState &jsState, QOhosTaskPromise<
bool> evalPromise) {
807 if (m_jsScopeData->isWindowClosing()) {
812 if (m_windowProxyType == WindowProxyType::SubWindow
813 && !isJsWindowInFreeWindowMode(*m_jsScopeData->jsWindowRef)) {
815 "%s: maximize request ignored: the sub window is not in free window mode",
821 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
822 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
823 "maximize(*)", {jsState.mapOhosEnumToJs(maximizePresentation)})
825 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &) {
829 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
830 QtOhos::logJsCallbackError(cbInfo,
"Got error from maximize()");
839 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, isLayoutFullScreen ?
"true" :
"false");
841 [
this, isLayoutFullScreen](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
842 if (m_jsScopeData->isWindowClosing()) {
846 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
847 "setWindowLayoutFullScreen(*)", {isLayoutFullScreen})
848 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowLayoutFullScreen()"))
849 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
856 qCDebug(QtForOhos) << Q_FUNC_INFO << names;
858 [
this, names](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
859 if (m_jsScopeData->isWindowClosing()) {
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));
874 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
877 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
878 if (m_jsScopeData->isWindowClosing()) {
883 m_jsScopeData->qAbilityPeer->qAbility().evalToPromiseOrRejectOnThrow(
"context.showAbility()")
884 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"showAbility()"))
885 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
892 qCDebug(QtForOhos,
"%s", Q_FUNC_INFO);
894 return QOhosJsThreadGateway::evalWithPromise<
bool>([&](QOhosJsState &, QOhosTaskPromise<
bool> evalPromise) {
895 if (m_jsScopeData->isWindowClosing()) {
900 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
901 m_jsScopeData->qAbilityPeer->qAbility().evalToPromiseOrRejectOnThrow(
"context.hideAbility()")
903 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &) {
907 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
908 QtOhos::logJsCallbackError(cbInfo,
"got error from hideAbility()");
917 return QOhosJsThreadGateway::eval(
918 [&](QOhosJsState &) {
919 if (m_jsScopeData->isWindowClosing())
921 return m_jsScopeData->jsWindowRef->eval<QNapi::Boolean>(
"getImmersiveModeEnabledState()").Value();
928 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, privacyMode ?
"true" :
"false");
931 [
this, privacyMode](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
932 if (m_jsScopeData->isWindowClosing()) {
937 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowPrivacyMode(*)", {privacyMode})
938 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setPrivacyMode()"))
939 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
946 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, focusable ?
"true" :
"false");
948 [
this, focusable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
949 if (m_jsScopeData->isWindowClosing()) {
954 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowFocusable(*)", {focusable})
955 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowFocusable()"))
956 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
963 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, touchable ?
"true" :
"false");
965 [
this, touchable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
966 if (m_jsScopeData->isWindowClosing()) {
971 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowTouchable(*)", {touchable})
972 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowTouchable()"))
973 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
981 QtForOhos,
"%s: (%d x %d)-(%d x %d)", Q_FUNC_INFO, minSize.width(), minSize.height(),
982 maxSize.width(), maxSize.height());
984 [
this, minSize, maxSize](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
985 if (m_jsScopeData->isWindowClosing()) {
989 auto windowLimits = QNapi::makeObject(
992 {
"minWidth", minSize.width()},
993 {
"minHeight", minSize.height()},
994 {
"maxWidth", maxSize.width()},
995 {
"maxHeight", maxSize.height()},
998 std::vector<QNapi::ValueWrapper> setWindowLimitsArgs = {windowLimits};
1000 constexpr bool isForcible =
true;
1001 setWindowLimitsArgs.push_back(isForcible);
1003 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
1004 "setWindowLimits(*)", setWindowLimitsArgs)
1005 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowLimits()"))
1006 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
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"),
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);
1044 const WindowMask &windowMask,
const std::optional<QSize> &ohosMaskSizeOverride,
JsCallBatch &jsCallBatch)
1050 [
this, windowMask, ohosMaskSizeOverride](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1051 if (m_jsScopeData->isWindowClosing()) {
1056 auto ohosMaskSize = ohosMaskSizeOverride.has_value()
1057 ? ohosMaskSizeOverride.value()
1058 : getWindowPropertiesFromJsWindow(m_jsScopeData->jsWindowRef->jsObject()).windowRect.size();
1060 if (ohosMaskSize.isEmpty()) {
1061 if (ohosMaskSizeOverride.has_value()) {
1063 "QOhosWindowProxy::setWindowMask failed - overridden mask source size is 0x0");
1069 auto *env = jsState.env();
1071 QNapi::Array maskRowsArray = QNapi::Array::New(env, ohosMaskSize.height());
1072 const int defaultValue = windowMask.windowMaskRegion.isEmpty() ? 1 : 0;
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;
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);
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;
1094 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowMask(*)", {maskRowsArray})
1095 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowMask()"))
1096 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1107 [
this](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1108 if (m_jsScopeData->isWindowClosing()) {
1112 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setSubWindowModal(*)", {
false})
1113 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setSubWindowModal()"))
1114 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1126 "%s: APPLICATION_MODALITY option can be used only on devices in the freeform window state - skipping",
1132 [
this, modalityType](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1133 if (m_jsScopeData->isWindowClosing()) {
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));
1148 [
this, title](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1149 if (m_jsScopeData->isWindowClosing()) {
1154 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowTitle(*)", {title.toStdString()})
1155 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
1156 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1162 bool maximizeVisible,
bool minimizeVisible,
bool closeVisible,
JsCallBatch &jsCallBatch)
1165 "%s: isMaximizeVisible:%s, isMinimizeVisible:%s, isCloseVisible:%s",
1166 Q_FUNC_INFO, maximizeVisible ?
"true" :
"false", minimizeVisible ?
"true":
"false",
1167 closeVisible ?
"true" :
"false");
1173 [
this, maximizeVisible, minimizeVisible, closeVisible](QOhosJsState &jsState) {
1174 if (m_jsScopeData->isWindowClosing())
1177 constexpr auto capabilityNotSupportedErrorCode = 801;
1178 std::vector<std::uint32_t> ignoredErrorCodes{capabilityNotSupportedErrorCode};
1180 constexpr auto windowStateAbnormalErrorCode = 1300002;
1181 ignoredErrorCodes.push_back(windowStateAbnormalErrorCode);
1184 jsState, ignoredErrorCodes,
"setWindowTitleButtonVisible()",
1186 m_jsScopeData->jsWindowRef->eval(
1187 "setWindowTitleButtonVisible(*)",
1188 {maximizeVisible, minimizeVisible, closeVisible});
1200 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
1204 qOhosPrintfDebug(
"%s: topMost: %s", Q_FUNC_INFO, topmost ?
"true" :
"false");
1207 [
this, topmost](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1208 if (m_jsScopeData->isWindowClosing()) {
1213 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowTopmost(*)", {topmost})
1214 .onCatch(QtOhos::makeErrorLoggingJsCallback(Q_FUNC_INFO))
1215 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1223 [
this, visible](QOhosJsState &) {
1224 if (m_jsScopeData->isWindowClosing())
1227 m_jsScopeData->jsWindowRef->eval(
"setWindowDecorVisible(*)", {visible});
1235 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets in PC mode - skipping", Q_FUNC_INFO);
1240 [
this, enabled](QOhosJsState &) {
1241 if (m_jsScopeData->isWindowClosing())
1244 m_jsScopeData->jsWindowRef->eval(
"setWindowTitleMoveEnabled(*)", {enabled});
1252 qOhosPrintfWarning(
"%s: can be used only on 2-in-1 devices or tablets - skipping", Q_FUNC_INFO);
1260 [
this, radius](QOhosJsState &) {
1261 m_jsScopeData->jsWindowRef->eval(
"setWindowShadowRadius(*)", {radius});
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));
1282 return QOhosJsThreadGateway::evalWithPromise<
bool>(
1283 [&](QOhosJsState &, QOhosTaskPromise<
bool> evalPromise) {
1284 if (m_jsScopeData->isWindowClosing()) {
1288 auto optQUiAbilityPeer = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
1289 if (!optQUiAbilityPeer) {
1294 auto thenCatchPromises = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1295 optQUiAbilityPeer->windowStage()
1296 .evalToPromiseOrRejectOnThrow(
"isWindowRectAutoSave()")
1298 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
1299 bool windowRectAutoSaveEnabled = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1300 thenPromise(windowRectAutoSaveEnabled);
1303 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
1304 QtOhos::logJsCallbackError(cbInfo,
"isWindowRectAutoSave()");
1305 catchPromise(
false);
1317 [
this, enabled](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1318 if (m_jsScopeData->isWindowClosing()) {
1322 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setFollowParentMultiScreenPolicy(*)", {enabled})
1323 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setFollowParentMultiScreenPolicy()"))
1324 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1334 [
this, keepScreenOn](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1335 if (m_jsScopeData->isWindowClosing()) {
1340 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"setWindowKeepScreenOn(*)", {keepScreenOn})
1341 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setWindowKeepScreenOn()"))
1342 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1348 const std::set<SupportWindowMode> &supportedWindowModes,
JsCallBatch &jsCallBatch)
1350 qCDebug(QtForOhos,
"%s: %s", Q_FUNC_INFO, mapEnumsToLogString(supportedWindowModes).c_str());
1353 [
this, supportedWindowModes](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
1354 if (m_jsScopeData->isWindowClosing()) {
1359 auto jsSupportedWindowModes = QNapi::makeArray(
1360 jsState.env(), supportedWindowModes,
1362 return jsState.mapOhosEnumToJs(mode);
1365 QNapi::Promise evalPromise;
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});
1375 "%s: ability has no window stage, supported window modes not applied",
1377 evalPromise = QtOhos::makeResolvedPromise(Napi::Env(jsState.env()).Undefined());
1381 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"setSupportedWindowModes()"))
1382 .onFinally(
std::move(taskPromise).makeChained(Q_FUNC_INFO));
1390 [
this, enabled](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1391 if (m_jsScopeData->isWindowClosing()) {
1396 if (!optQUiAbilityPeer) {
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));
1411 std::function<
void()> handler,
bool handlerReturnValue)
1413 m_subWindowCloseRegistrationHandle =
1414 registerSubWindowCloseHandler(std::move(handler), handlerReturnValue);
1419 m_subWindowCloseRegistrationHandle.reset();
1422std::shared_ptr<
void> QOhosWindowProxy::registerSubWindowCloseHandler(
1423 std::function<
void()> handler,
bool handlerReturnValue)
1425 auto sharedHandler = QtOhos::moveToSharedPtr(std::move(handler));
1426 auto jsWindowRegistrationHandle = QOhosJsThreadGateway::eval(
1427 [&](QOhosJsState &jsState) {
1428 return QtOhos::makeProxyWithJsThreadDeleter(
1429 m_jsScopeData->registerSubWindowCloseHandler(
1431 [weakHandler = QtOhos::makeWeakPtr(sharedHandler), handlerReturnValue]() {
1432 QtOhos::invokeInQtThread(
1434 auto sharedHandler = weakHandler.lock();
1438 return handlerReturnValue;
1443 return QtOhos::moveToSharedPtr(
1444 std::make_tuple(sharedHandler, jsWindowRegistrationHandle));
1447std::shared_ptr<QOhosWindowProxy>
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));
1457std::shared_ptr<QOhosWindowProxy>
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));
1467std::shared_ptr<QOhosWindowProxy>
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));
1479 return m_nodeXComponent;
1484 return m_qAbilityInstanceId;
1489 return m_abilityObjectRef;
1494 return m_jsWindowObjectRef;
1497std::shared_ptr<QOhosWindowProxy>
1500 return std::shared_ptr<QOhosWindowProxy>(
1501 new QOhosWindowProxy(
1502 [&](QtOhos::JsState &jsState, QOhosConsumer<QtOhos::JsState &, QOhosWindowProxyData> windowProxyDataConsumer) {
1505 auto subWindowCreateInfo = createInfo;
1506 subWindowCreateInfo.maximizeSupported = createInfo.maximizeSupported
1507 && !m_jsScopeData->isWindowClosing()
1508 && isJsWindowInFreeWindowMode(*m_jsScopeData->jsWindowRef);
1513 if (m_jsScopeData->isWindowClosing()) {
1514 makeWindowProxyDataForSubWindowInJsThread(
1515 jsState, subWindowCreateInfo, std::move(windowProxyDataConsumer));
1517 makeWindowProxyDataForSubWindowInJsThread(
1518 jsState, m_jsScopeData->jsWindowRef->jsObject(), subWindowCreateInfo,
1519 std::move(windowProxyDataConsumer));
1524QOhosWindowProxy::JsScopeData::JsScopeData() =
default;
1526QOhosWindowProxy::JsScopeData::JsScopeData(
1527 WindowProxyType windowProxyType, QNapi::Reference<QNapi::Object> jsWindow,
1528 std::shared_ptr<
void> optKeepAliveData,
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);
1543 , m_windowFrameTouchFilterHandle(
1544 QArkUi::registerTouchEventsConsumer(
1545 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1546 [dispatcher = nonClientAreaEventsDispatcher](
const QArkUi::TouchEvent &event) {
1547 dispatcher->onTouchEventFromArkUi(event);
1550 std::make_shared<QArkUi::JsWindowRef>(
1551 qAbilityPeer->instanceId(),
1552 getWindowPropertiesFromJsWindow(jsWindow.Value()).id,
1558QOhosWindowProxy::JsScopeData::~JsScopeData()
1561 if (isWindowClosingFromSystem(jsWindowRef->jsObject(), windowProxyType, qAbilityPeer)) {
1562 windowDestroyedFromSystem =
true;
1566 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(),
"QOhosWindowProxy::JsScopeData destructor");
1572 windowDestroyedFromSystem =
true;
1574 "Attempting to terminate qAbility with instance id: %s",
1575 jsWindowRef->owningQAbilityInstanceId().c_str());
1576 qAbilityPeer->qAbility().eval(
"context.terminateSelf()");
1577 }
else if (!windowDestroyedFromSystem) {
1580 jsWindowRef->eval(
"destroyWindow()");
1585std::shared_ptr<
void> QOhosWindowProxy::JsScopeData::registerEventListener(
1586 const std::string &eventName,
1588 QFlags<EventHandlerFlagBits> eventHandlerFlags)
1591 std::weak_ptr<JsScopeData> weakSelf = shared_from_this();
1592 bool ignoreWhenAbilityIsTerminating = !eventHandlerFlags.testFlag(EventHandlerFlagBits::allowCallWhenAbilityIsTerminating);
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)) {
1600 "callback '%s' called for destroyed QOhosWindowProxy::JsScopeData, ignoring",
1605 if (self->isWindowClosing() && ignoreWhenAbilityIsTerminating) {
1607 "QOhosWindowProxy: Received callback for event '%s' during termination of the related QAbility.",
1612 if (Q_UNLIKELY(self->windowDestroyedFromSystem)) {
1614 "QOhosWindowProxy: Received callback for event '%s' after WINDOW_DESTROYED",
1619 ((*self).*handleFunction)(cbInfo);
1622 .optEventSourceAliveCheckFunc = {},
1625 .optOnCallExceptionHandler = [&](
const Napi::Error &error) {
1626 constexpr std::uint32_t capabilityNotSupportedErrorCode = 801;
1627 constexpr std::uint32_t windowStateIsAbnormalErrorCode = 1300002;
1629 const QSet<std::uint32_t> ignorableErrorCodes = {
1630 capabilityNotSupportedErrorCode,
1631 windowStateIsAbnormalErrorCode,
1634 auto errorCode = QtOhos::tryGetCodeFromJsBusinessError(error);
1636 auto ignorableError =
1637 eventHandlerFlags.testFlag(EventHandlerFlagBits::allowEventHandlerRegistrationFailure)
1638 && errorCode.has_value()
1639 && ignorableErrorCodes.contains(errorCode.value());
1641 if (!ignorableError)
1645 "%s: Ignored error %u while registering for window event '%s'",
1646 Q_FUNC_INFO, errorCode.value(), eventName.c_str());
1651std::shared_ptr<
void> QOhosWindowProxy::JsScopeData::registerSubWindowCloseHandler(
1652 QOhosJsState &,
std::function<
bool()> handler)
1654 auto weakSelf = QtOhos::makeWeakPtr(shared_from_this());
1655 return registerQOhosOnOffMethodsBasedEventHandler(
1656 jsWindowRef->jsObject(),
"subWindowClose",
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);
1666void QOhosWindowProxy::JsScopeData::handleWindowEventCallback(
const QtOhos::
CallbackInfo &cbInfo)
1668 auto eventType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1673 event
.type = cbInfo
.jsState().mapOhosEnumFromJs<WindowEventType>(eventType);
1674 }
catch (
const Napi::Error &err) {
1676 "Error converting WindowEventType to known value: %s. Event will be ignored.", err.what());
1682 "Received WindowEvent for window when it's closing. WindowEventType: %d",
1690void QOhosWindowProxy::JsScopeData::handleWindowStatusCallback(
const QtOhos::
CallbackInfo &cbInfo)
1692 auto windowStatusType = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1693 if (windowCallbackReceiver !=
nullptr) {
1694 windowCallbackReceiver->onWindowStatusChange(
1696 .type = cbInfo.jsState().mapOhosEnumFromJs<WindowStatusType>(windowStatusType),
1701void QOhosWindowProxy::JsScopeData::handleWindowVisibilityCallback(
const QtOhos::
CallbackInfo &cbInfo)
1703 auto windowVisibility = cbInfo.getFirstArg<QNapi::Boolean>(Q_FUNC_INFO);
1704 if (windowCallbackReceiver !=
nullptr)
1705 windowCallbackReceiver->onWindowVisibilityChange(windowVisibility);
1708void QOhosWindowProxy::JsScopeData::handleWindowTouchOutsideCallback(
const QtOhos::
CallbackInfo &)
1710 if (windowCallbackReceiver !=
nullptr)
1711 windowCallbackReceiver->onTouchOutside();
1714void QOhosWindowProxy::JsScopeData::handleAvoidAreaChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
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")));
1724void QOhosWindowProxy::JsScopeData::handleWindowRectChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
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")),
1732 if (windowCallbackReceiver !=
nullptr)
1733 windowCallbackReceiver->onWindowRectChange(rectChangeOptions);
1736void QOhosWindowProxy::JsScopeData::handleWindowRectChangeInGlobalDisplayCallback(
const QtOhos::
CallbackInfo &cbInfo)
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")),
1744 if (windowCallbackReceiver !=
nullptr)
1745 windowCallbackReceiver->onWindowRectChangeInGlobalDisplay(rectChangeOptions);
1748void QOhosWindowProxy::JsScopeData::handleWindowDisplayIdChangeCallback(
const QtOhos::
CallbackInfo &cbInfo)
1750 auto displayIdNumber = cbInfo.getFirstArg<QNapi::Number>(Q_FUNC_INFO);
1753 if (windowCallbackReceiver !=
nullptr)
1754 windowCallbackReceiver->onWindowDisplayIdChange(displayId);
1760 QtOhos::JsWindowsTracker::tagWindowAsClosing(jsWindowRef->jsObject(),
"WINDOW_DESTROYED");
1761 windowDestroyedFromSystem =
true;
1764 if (windowCallbackReceiver !=
nullptr)
1765 windowCallbackReceiver->onWindowEvent(windowEvent);
1768bool QOhosWindowProxy::JsScopeData::isWindowClosing()
const
1770 return isWindowClosingFromSystem(jsWindowRef->jsObject(), windowProxyType, qAbilityPeer);
1775 if (mouseEventsConsumer ==
nullptr)
1778 auto optAction = tryMapMouseEventActionToNonClientAreaEventType(event.action);
1779 if (!optAction.has_value())
1783 if (!optWindowProperties.has_value()) {
1785 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1786 Q_FUNC_INFO, event.jsWindowId.value());
1790 const auto &windowProperties = optWindowProperties.value();
1791 if (!isPointInNonClientArea(event.displayPosition, windowProperties))
1794 auto windowOrigin = windowProperties.windowRect.topLeft() + windowProperties.drawableRect.topLeft();
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,
1804 mouseEventsConsumer(nonClientAreaMouseEvent);
1809 if (touchEventsConsumer ==
nullptr)
1812 auto optAction = tryMapTouchEventActionToNonClientAreaEventType(event.action);
1813 if (!optAction.has_value())
1817 if (!optWindowProperties.has_value()) {
1819 "%s: Failed to retrieve window properties for js window: %f. Ignoring event.",
1820 Q_FUNC_INFO, event.jsWindowId.value());
1824 const auto &windowProperties = optWindowProperties.value();
1825 if (!isPointInNonClientArea(event.displayPosition, windowProperties))
1828 auto windowOrigin = windowProperties.windowRect.topLeft() + windowProperties.drawableRect.topLeft();
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,
1838 touchEventsConsumer(nonClientAreaTouchEvent);
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()")
1848 [thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
1849 auto napiPixmap = cbInfo.getFirstArg<QNapi::Object>(Q_FUNC_INFO);
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);
1858 QPixmap::fromImage(createQImageFromNativePixelMap(pixelMap.get())));
1861 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
1862 QtOhos::logJsCallbackError(cbInfo,
"Got error from snapshot()");
1863 catchPromise(QPixmap());
1873 return QOhosJsThreadGateway::evalWithPromise<QList<QRect>>(
1874 [&](QOhosJsState &jsState, QOhosTaskPromise<QList<QRect>> evalPromise) {
1875 if (m_jsScopeData->isWindowClosing()) {
1876 evalPromise(QList<QRect>());
1880 auto optWindowDisplay = qAndThen(
1881 getWindowPropertiesFromJsWindow(
1882 m_jsScopeData->jsWindowRef->jsObject()).displayId,
1883 [&](QOhosDisplayInfo::JsDisplayId id) {
1884 return QOhosDisplayInfo::tryGetDisplayById(jsState, id);
1886 auto display = optWindowDisplay.has_value()
1887 ? optWindowDisplay.value()
1888 : jsState.eval<QNapi::Object>(
"@ohos.display.getDefaultDisplaySync()");
1890 auto branches = std::move(evalPromise).makeThenCatchBranches(Q_FUNC_INFO);
1892 .evalToPromiseOrRejectOnThrow(
"getCutoutInfo()")
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"));
1903 thenPromise(cutoutRects);
1906 [catchPromise = std::move(branches.second)](
const QtOhos::CallbackInfo &cbInfo) {
1907 QtOhos::logJsCallbackError(cbInfo,
"getCutoutInfo() failed");
1908 catchPromise(QList<QRect>());
1916 QOhosJsThreadGateway::invokeAndWaitForContinue(
1917 [&](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1918 if (m_jsScopeData->isWindowClosing()) {
1923 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"startMoving()")
1924 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"startMoving()"))
1925 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1937 qCWarning(QtForOhos(),
"%s: enableDrag is not supported on main windows", Q_FUNC_INFO);
1942 [
this, enable](QOhosJsState &, QOhosTaskPromise<> taskPromise) {
1943 if (m_jsScopeData->isWindowClosing()) {
1947 m_jsScopeData->jsWindowRef->evalToPromiseOrRejectOnThrow(
"enableDrag(*)", {enable})
1948 .onCatch(QtOhos::makeErrorLoggingJsCallback(
"enableDrag()"))
1949 .onFinally(std::move(taskPromise).makeChained(Q_FUNC_INFO));
1956 return QOhosJsThreadGateway::eval(
1957 [&](QOhosJsState &) -> std::optional<
bool> {
1958 if (m_jsScopeData->isWindowClosing())
1959 return std::nullopt;
1961 return m_jsScopeData->jsWindowRef->eval<QNapi::Boolean>(
"isFocused()");
1966std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryWindowIdsByCoordinate(
1967 QOhosDisplayInfo::JsDisplayId displayId,
const QPoint &queryLocation,
std::uint32_t queryLimit)
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(*)", {
1978 .onThen([thenPromise = std::move(thenCatchPromises.first)](
const QtOhos::CallbackInfo &cbInfo) {
1979 auto windowsArray = cbInfo.getFirstArg<QNapi::Array>(Q_FUNC_INFO);
1981 QNapi::getArrayElements<std::vector<QArkUi::JsWindowId>, QNapi::Object>(
1983 [&](QNapi::Object jsWindow) {
1984 return getWindowPropertiesFromJsWindow(jsWindow).id;
1987 .onCatch([catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
1988 QtOhos::logJsCallbackError(
1989 cbInfo,
"got error from @ohos.window.getWindowsByCoordinate()");
1996std::vector<QArkUi::JsWindowId> QOhosWindowProxy::queryQtManagedWindowIdsByPredicate(
1997 const std::function<
bool(QOhosJsState &,
const QArkUi::JsWindowRef &)> &predicate)
1999 return QOhosJsThreadGateway::eval([&](QOhosJsState &jsState) {
2000 return QOhosJsWindowRegistry::instance(jsState).queryByPredicate(jsState, predicate);
2009 [
this, position, moveConfiguration](QOhosJsState &jsState, QOhosTaskPromise<> taskPromise) {
2010 if (m_jsScopeData->isWindowClosing()) {
2015 auto moveConfigurationObject = toNapiObject(jsState.env(), moveConfiguration);
2016 auto moveConfigurationObjectStr = QNapi::toJsonString(moveConfigurationObject);
2019 Q_FUNC_INFO, position.x(), position.y(),
2020 moveConfigurationObjectStr.c_str());
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));
2033 ? getWindowProperties().displayId
2034 : QOhosJsThreadGateway::eval(
2035 [&](QOhosJsState &) {
2037 = QtOhos::QUiAbilityPeer::tryCastFromQAbilityPeerOrNull(m_jsScopeData->qAbilityPeer);
2038 return qUiAbilityPeer
2039 ? getWindowPropertiesFromJsWindow(qUiAbilityPeer->window()).displayId
2047 return QOhosJsThreadGateway::evalWithPromise<
bool>(
2048 [&](QOhosJsState &jsState, QOhosTaskPromise<
bool> evalPromise) {
2049 if (m_jsScopeData->isWindowClosing() || targetProxy.m_jsScopeData->isWindowClosing()) {
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()})
2060 [thenPromise = std::move(thenCatchPromises.first)]() {
2064 [catchPromise = std::move(thenCatchPromises.second)](
const QtOhos::CallbackInfo &cbInfo) {
2065 QtOhos::logJsCallbackError(cbInfo,
"Got error from @ohos.window.shiftAppWindowFocus()");
2066 catchPromise(
false);
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())
void resetSubWindowCloseHandler()
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)
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())
bool getImmersiveModeEnabledState()
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)
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
bool isDisplayMainOrExtended() const
void onTouchEventFromArkUi(const QArkUi::TouchEvent &event) const
void onMouseEventFromArkUi(const QArkUi::MouseEvent &event) const