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
qohosnativekeyeventshandler.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/qohosnativekeyeventshandler.h>
5
6#include <arkui/native_key_event.h>
7#include <qarkui/qarkuiutils.h>
8#include <qohoskeymodifiers.h>
9#include <qohosnativenodekeyevent.h>
10
12
13namespace {
14
15bool isModifierKey(::ArkUI_KeyCode keyCode)
16{
17 switch (keyCode) {
18 case ::ArkUI_KeyCode::ARKUI_KEYCODE_SHIFT_LEFT:
19 case ::ArkUI_KeyCode::ARKUI_KEYCODE_SHIFT_RIGHT:
20 case ::ArkUI_KeyCode::ARKUI_KEYCODE_ALT_LEFT:
21 case ::ArkUI_KeyCode::ARKUI_KEYCODE_ALT_RIGHT:
22 case ::ArkUI_KeyCode::ARKUI_KEYCODE_CTRL_LEFT:
23 case ::ArkUI_KeyCode::ARKUI_KEYCODE_CTRL_RIGHT:
24 case ::ArkUI_KeyCode::ARKUI_KEYCODE_META_LEFT:
25 case ::ArkUI_KeyCode::ARKUI_KEYCODE_META_RIGHT:
26 case ::ArkUI_KeyCode::ARKUI_KEYCODE_CAPS_LOCK:
27 case ::ArkUI_KeyCode::ARKUI_KEYCODE_NUM_LOCK:
28 return true;
29 default:
30 return false;
31 }
32}
33
34}
35
37 QtOhos::QThreadSafeRef<QWindow> qWindowRef,
38 QtOhos::QThreadSafeRef<QOhosInputMethodEventHandler> imEventHandlerRef)
39{
40 auto lastNativeKeyEvent = makeEmptyQOhosNativeNodeKeyEvent();
41
42 return [qWindowRef, imEventHandlerRef, lastNativeKeyEvent](::ArkUI_UIInputEvent *uiInputEvent) mutable {
43 const auto keyType = QArkUi::callArkUi(
44 Q_OHOS_NAMED_FUNC(::OH_ArkUI_KeyEvent_GetType), uiInputEvent);
45 const auto keyCode = QArkUi::callArkUi(
46 Q_OHOS_NAMED_FUNC(::OH_ArkUI_KeyEvent_GetKeyCode), uiInputEvent);
47
48 const auto arkuiKeyCode = static_cast<::ArkUI_KeyCode>(keyCode);
49 auto ohosKeyEvent = makeQOhosNativeNodeKeyEvent(keyType, arkuiKeyCode, readKeyModifiersFromOhosUiInputEvent(uiInputEvent));
50 if (isModifierKey(arkuiKeyCode) && lastNativeKeyEvent->equals(*ohosKeyEvent))
51 return;
52 lastNativeKeyEvent = ohosKeyEvent;
53
54 imEventHandlerRef.visitInQtThreadIfAlive(
55 [ohosKeyEvent, qWindowRef](QOhosInputMethodEventHandler &imEventHandler) {
56 imEventHandler.onKeyEvent(*ohosKeyEvent, qWindowRef.data());
57 });
58 };
59}
60
61QT_END_NAMESPACE
Combined button and popup list for selecting options.
bool isModifierKey(::ArkUI_KeyCode keyCode)
QOhosConsumer<::ArkUI_UIInputEvent * > makeQOhosNativeKeyEventsHandler(QtOhos::QThreadSafeRef< QWindow > qWindowRef, QtOhos::QThreadSafeRef< QOhosInputMethodEventHandler > imEventHandlerRef)