Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
androidjniinput.cpp
Go to the documentation of this file.
1// Copyright (C) 2012 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtGui/qtguiglobal.h>
6
7#include "androidjniinput.h"
8#include "androidjnimain.h"
10
11#include <qpa/qwindowsysteminterface.h>
12#include <QTouchEvent>
13#include <QPointer>
14
15#include <QGuiApplication>
16#include <QtMath>
17
19
20Q_LOGGING_CATEGORY(lcQpaInputMethods, "qt.qpa.input.methods");
21
22using namespace QtAndroid;
23
25{
26 static bool m_ignoreMouseEvents = false;
28
30
32
33 void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)
34 {
35 qCDebug(lcQpaInputMethods) << ">>> UPDATESELECTION" << selStart << selEnd << candidatesStart << candidatesEnd;
36 QJniObject::callStaticMethod<void>(applicationClass(),
37 "updateSelection",
38 "(IIII)V",
39 selStart,
40 selEnd,
41 candidatesStart,
42 candidatesEnd);
43 }
44
45 void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints, int enterKeyType)
46 {
47 QJniObject::callStaticMethod<void>(applicationClass(),
48 "showSoftwareKeyboard",
49 "(IIIIII)V",
50 left,
51 top,
52 width,
53 height,
54 inputHints,
55 enterKeyType);
56 qCDebug(lcQpaInputMethods) << "@@@ SHOWSOFTWAREKEYBOARD" << left << top << width << height << inputHints << enterKeyType;
57 }
58
60 {
61 QJniObject::callStaticMethod<void>(applicationClass(), "resetSoftwareKeyboard");
62 qCDebug(lcQpaInputMethods) << "@@@ RESETSOFTWAREKEYBOARD";
63 }
64
66 {
67 QJniObject::callStaticMethod<void>(applicationClass(), "hideSoftwareKeyboard");
68 qCDebug(lcQpaInputMethods) << "@@@ HIDESOFTWAREKEYBOARD";
69 }
70
72 {
73 return QJniObject::callStaticMethod<jboolean>(applicationClass(), "isSoftwareKeyboardVisible");
74 }
75
77 {
79 }
80
82 {
83 return QJniObject::callStaticMethod<jint>(applicationClass(), "getSelectHandleWidth");
84 }
85
86 void updateHandles(int mode, QPoint editMenuPos, uint32_t editButtons, QPoint cursor, QPoint anchor, bool rtl)
87 {
88 QJniObject::callStaticMethod<void>(applicationClass(), "updateHandles", "(IIIIIIIIZ)V",
89 mode, editMenuPos.x(), editMenuPos.y(), editButtons,
90 cursor.x(), cursor.y(),
91 anchor.x(), anchor.y(), rtl);
92 }
93
94 static void mouseDown(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
95 {
97 return;
98
99 QPoint globalPos(x,y);
100 QWindow *tlw = topLevelWindowAt(globalPos);
101 m_mouseGrabber = tlw;
102 QPoint localPos = tlw ? (globalPos - tlw->position()) : globalPos;
103 QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos,
104 Qt::MouseButtons(Qt::LeftButton),
106 }
107
108 static void mouseUp(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
109 {
110 QPoint globalPos(x,y);
111 QWindow *tlw = m_mouseGrabber.data();
112 if (!tlw)
113 tlw = topLevelWindowAt(globalPos);
114 QPoint localPos = tlw ? (globalPos -tlw->position()) : globalPos;
115 QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos,
116 Qt::MouseButtons(Qt::NoButton),
118 m_ignoreMouseEvents = false;
119 m_mouseGrabber = 0;
120 }
121
122 static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
123 {
124
126 return;
127
128 QPoint globalPos(x,y);
129 QWindow *tlw = m_mouseGrabber.data();
130 if (!tlw)
131 tlw = topLevelWindowAt(globalPos);
132 QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos;
133 QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos,
134 Qt::MouseButtons(m_mouseGrabber ? Qt::LeftButton : Qt::NoButton),
136 }
137
138 static void mouseWheel(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y, jfloat hdelta, jfloat vdelta)
139 {
141 return;
142
143 QPoint globalPos(x,y);
144 QWindow *tlw = m_mouseGrabber.data();
145 if (!tlw)
146 tlw = topLevelWindowAt(globalPos);
147 QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos;
148 QPoint angleDelta(hdelta * 120, vdelta * 120);
149
151 localPos,
152 globalPos,
153 QPoint(),
154 angleDelta);
155 }
156
157 static void longPress(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint x, jint y)
158 {
160 if (inputContext && qGuiApp)
161 QMetaObject::invokeMethod(inputContext, "longPress", Q_ARG(int, x), Q_ARG(int, y));
162
163 //### TODO: add proper API for Qt 5.2
164 static bool rightMouseFromLongPress = qEnvironmentVariableIntValue("QT_ANDROID_ENABLE_RIGHT_MOUSE_FROM_LONG_PRESS");
165 if (!rightMouseFromLongPress)
166 return;
167 m_ignoreMouseEvents = true;
168 QPoint globalPos(x,y);
169 QWindow *tlw = topLevelWindowAt(globalPos);
170 QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos;
171
172 // Click right button if no other button is already pressed.
173 if (!m_mouseGrabber) {
174 QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos,
175 Qt::MouseButtons(Qt::RightButton), Qt::RightButton,
177 QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos,
178 Qt::MouseButtons(Qt::NoButton), Qt::RightButton,
180 }
181 }
182
183 static void touchBegin(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/)
184 {
186 }
187
188 static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y,
189 jfloat major, jfloat minor, jfloat rotation, jfloat pressure)
190 {
192 switch (action) {
193 case 0:
195 break;
196 case 1:
198 break;
199 case 2:
201 break;
202 case 3:
204 break;
205 }
206
207 const int dw = availableWidthPixels();
208 const int dh = availableHeightPixels();
210 touchPoint.id = id;
211 touchPoint.pressure = pressure;
212 touchPoint.rotation = qRadiansToDegrees(rotation);
213 touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh));
214 touchPoint.state = state;
215 touchPoint.area = QRectF(x - double(minor),
216 y - double(major),
217 double(minor * 2),
218 double(major * 2));
219 m_touchPoints.push_back(touchPoint);
220
223 if (inputContext && qGuiApp)
224 QMetaObject::invokeMethod(inputContext, "touchDown", Q_ARG(int, x), Q_ARG(int, y));
225 }
226 }
227
229 {
231 if (!platformIntegration)
232 return nullptr;
233
234 QPointingDevice *touchDevice = platformIntegration->touchDevice();
235 if (!touchDevice) {
236 touchDevice = new QPointingDevice("Android touchscreen", 1,
243 10, 0);
245 platformIntegration->setTouchDevice(touchDevice);
246 }
247
248 return touchDevice;
249 }
250
251 static void touchEnd(JNIEnv * /*env*/, jobject /*thiz*/, jint /*winId*/, jint /*action*/)
252 {
254 return;
255
257 QPointingDevice *touchDevice = getTouchDevice();
258 if (!touchDevice)
259 return;
260
263 }
264
265 static void touchCancel(JNIEnv * /*env*/, jobject /*thiz*/, jint /*winId*/)
266 {
268 return;
269
271 QPointingDevice *touchDevice = getTouchDevice();
272 if (!touchDevice)
273 return;
274
277 }
278
279 static bool isTabletEventSupported(JNIEnv */*env*/, jobject /*thiz*/)
280 {
281#if QT_CONFIG(tabletevent)
282 return true;
283#else
284 return false;
285#endif // QT_CONFIG(tabletevent)
286 }
287
288 static void tabletEvent(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint deviceId, jlong time, jint action,
289 jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure)
290 {
291#if QT_CONFIG(tabletevent)
292 QPointF globalPosF(x, y);
293 QPoint globalPos((int)x, (int)y);
294 QWindow *tlw = topLevelWindowAt(globalPos);
295 QPointF localPos = tlw ? (globalPosF - tlw->position()) : globalPosF;
296
297 // Galaxy Note with plain Android:
298 // 0 1 0 stylus press
299 // 2 1 0 stylus drag
300 // 1 1 0 stylus release
301 // 0 1 2 stylus press with side-button held
302 // 2 1 2 stylus drag with side-button held
303 // 1 1 2 stylus release with side-button held
304 // Galaxy Note 4 with Samsung firmware:
305 // 0 1 0 stylus press
306 // 2 1 0 stylus drag
307 // 1 1 0 stylus release
308 // 211 1 2 stylus press with side-button held
309 // 213 1 2 stylus drag with side-button held
310 // 212 1 2 stylus release with side-button held
311 // when action == ACTION_UP (1) it's a release; otherwise we say which button is pressed
312 Qt::MouseButtons buttons = Qt::NoButton;
313 switch (action) {
314 case 1: // ACTION_UP
315 case 212: // stylus release while side-button held on Galaxy Note 4
316 buttons = Qt::NoButton;
317 break;
318 default: // action is press or drag
319 if (buttonState == 0)
320 buttons = Qt::LeftButton;
321 else // 2 means RightButton
322 buttons = Qt::MouseButtons(buttonState);
323 break;
324 }
325
326 qCDebug(lcQpaInputMethods) << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << ": buttons" << buttons;
327
329 localPos, globalPosF, int(QInputDevice::DeviceType::Stylus), pointerType,
330 buttons, pressure, 0, 0, 0., 0., 0, deviceId, Qt::NoModifier);
331#endif // QT_CONFIG(tabletevent)
332 }
333
335 {
336 // 0--9 0x00000007 -- 0x00000010
337 if (key >= 0x00000007 && key <= 0x00000010)
338 return QKeyCombination::fromCombined(Qt::Key_0 + key - 0x00000007);
339
340 // A--Z 0x0000001d -- 0x00000036
341 if (key >= 0x0000001d && key <= 0x00000036)
342 return QKeyCombination::fromCombined(Qt::Key_A + key - 0x0000001d);
343
344 // F1--F12 0x00000083 -- 0x0000008e
345 if (key >= 0x00000083 && key <= 0x0000008e)
346 return QKeyCombination::fromCombined(Qt::Key_F1 + key - 0x00000083);
347
348 // NUMPAD_0--NUMPAD_9 0x00000090 -- 0x00000099
349 if (key >= 0x00000090 && key <= 0x00000099)
351
352 // BUTTON_1--KEYCODE_BUTTON_16 0x000000bc -- 0x000000cb
353
354 switch (key) {
355 case 0x00000000: // KEYCODE_UNKNOWN
356 return Qt::Key_unknown;
357
358 case 0x00000001: // KEYCODE_SOFT_LEFT
359 return Qt::Key_Left;
360
361 case 0x00000002: // KEYCODE_SOFT_RIGHT
362 return Qt::Key_Right;
363
364 // 0x00000003: // KEYCODE_HOME is never delivered to applications.
365
366 case 0x00000004: // KEYCODE_BACK
367 return Qt::Key_Back;
368
369 case 0x00000005: // KEYCODE_CALL
370 return Qt::Key_Call;
371
372 case 0x00000006: // KEYCODE_ENDCALL
373 return Qt::Key_Hangup;
374
375 // 0--9 0x00000007 -- 0x00000010
376
377 case 0x00000011: // KEYCODE_STAR
378 return Qt::Key_Asterisk;
379
380 case 0x00000012: // KEYCODE_POUND
381 return Qt::Key_NumberSign;
382
383 case 0x00000013: //KEYCODE_DPAD_UP
384 return Qt::Key_Up;
385
386 case 0x00000014: // KEYCODE_DPAD_DOWN
387 return Qt::Key_Down;
388
389 case 0x00000015: //KEYCODE_DPAD_LEFT
390 return Qt::Key_Left;
391
392 case 0x00000016: //KEYCODE_DPAD_RIGHT
393 return Qt::Key_Right;
394
395 case 0x00000017: // KEYCODE_DPAD_CENTER
396 return Qt::Key_Enter;
397
398 case 0x00000018: // KEYCODE_VOLUME_UP
399 return Qt::Key_VolumeUp;
400
401 case 0x00000019: // KEYCODE_VOLUME_DOWN
402 return Qt::Key_VolumeDown;
403
404 case 0x0000001a:
405 return Qt::Key_PowerOff;
406
407 case 0x0000001b: // KEYCODE_CAMERA
408 return Qt::Key_Camera;
409
410 case 0x0000001c: // KEYCODE_CLEAR
411 return Qt::Key_Clear;
412
413 // A--Z 0x0000001d -- 0x00000036
414
415 case 0x00000037: // KEYCODE_COMMA
416 return Qt::Key_Comma;
417
418 case 0x00000038: // KEYCODE_PERIOD
419 return Qt::Key_Period;
420
421 case 0x00000039: // KEYCODE_ALT_LEFT
422 case 0x0000003a: // KEYCODE_ALT_RIGHT
423 return Qt::Key_Alt;
424
425 case 0x0000003b: // KEYCODE_SHIFT_LEFT
426 case 0x0000003c: // KEYCODE_SHIFT_RIGHT
427 return Qt::Key_Shift;
428
429 case 0x0000003d: // KEYCODE_TAB
430 return Qt::Key_Tab;
431
432 case 0x0000003e: // KEYCODE_SPACE
433 return Qt::Key_Space;
434
435 case 0x0000003f: // KEYCODE_SYM
436 return Qt::Key_Meta;
437
438 case 0x00000040: // KEYCODE_EXPLORER
439 return Qt::Key_Explorer;
440
441 case 0x00000041: //KEYCODE_ENVELOPE
442 return Qt::Key_LaunchMail;
443
444 case 0x00000042: // KEYCODE_ENTER
445 return Qt::Key_Return;
446
447 case 0x00000043: // KEYCODE_DEL
448 return Qt::Key_Backspace;
449
450 case 0x00000044: // KEYCODE_GRAVE
451 return Qt::Key_QuoteLeft;
452
453 case 0x00000045: // KEYCODE_MINUS
454 return Qt::Key_Minus;
455
456 case 0x00000046: // KEYCODE_EQUALS
457 return Qt::Key_Equal;
458
459 case 0x00000047: // KEYCODE_LEFT_BRACKET
460 return Qt::Key_BracketLeft;
461
462 case 0x00000048: // KEYCODE_RIGHT_BRACKET
464
465 case 0x00000049: // KEYCODE_BACKSLASH
466 return Qt::Key_Backslash;
467
468 case 0x0000004a: // KEYCODE_SEMICOLON
469 return Qt::Key_Semicolon;
470
471 case 0x0000004b: // KEYCODE_APOSTROPHE
472 return Qt::Key_Apostrophe;
473
474 case 0x0000004c: // KEYCODE_SLASH
475 return Qt::Key_Slash;
476
477 case 0x0000004d: // KEYCODE_AT
478 return Qt::Key_At;
479
480 case 0x0000004e: // KEYCODE_NUM
481 return Qt::Key_Alt;
482
483 case 0x0000004f: // KEYCODE_HEADSETHOOK
485
486 case 0x00000050: // KEYCODE_FOCUS
487 return Qt::Key_CameraFocus;
488
489 case 0x00000051: // KEYCODE_PLUS
490 return Qt::Key_Plus;
491
492 case 0x00000052: // KEYCODE_MENU
493 return Qt::Key_Menu;
494
495 case 0x00000053: // KEYCODE_NOTIFICATION
497
498 case 0x00000054: // KEYCODE_SEARCH
499 return Qt::Key_Search;
500
501 case 0x00000055: // KEYCODE_MEDIA_PLAY_PAUSE
503
504 case 0x00000056: // KEYCODE_MEDIA_STOP
505 return Qt::Key_MediaStop;
506
507 case 0x00000057: // KEYCODE_MEDIA_NEXT
508 return Qt::Key_MediaNext;
509
510 case 0x00000058: // KEYCODE_MEDIA_PREVIOUS
512
513 case 0x00000059: // KEYCODE_MEDIA_REWIND
514 return Qt::Key_AudioRewind;
515
516 case 0x0000005a: // KEYCODE_MEDIA_FAST_FORWARD
518
519 case 0x0000005b: // KEYCODE_MUTE
520 return Qt::Key_MicMute;
521
522 case 0x0000005c: // KEYCODE_PAGE_UP
523 return Qt::Key_PageUp;
524
525 case 0x0000005d: // KEYCODE_PAGE_DOWN
526 return Qt::Key_PageDown;
527
528 case 0x0000005e: // KEYCODE_PICTSYMBOLS
530
531 case 0x00000060: // KEYCODE_BUTTON_A
532 case 0x00000061: // KEYCODE_BUTTON_B
533 case 0x00000062: // KEYCODE_BUTTON_B
534 case 0x00000063: // KEYCODE_BUTTON_X
535 case 0x00000064: // KEYCODE_BUTTON_Y
536 case 0x00000065: // KEYCODE_BUTTON_Z
537 case 0x00000066: // KEYCODE_BUTTON_L1
538 case 0x00000067: // KEYCODE_BUTTON_R1
539 case 0x00000068: // KEYCODE_BUTTON_L2
540 case 0x00000069: // KEYCODE_BUTTON_R2
541 case 0x0000006a: // KEYCODE_BUTTON_THUMBL
542 case 0x0000006b: // KEYCODE_BUTTON_THUMBR
543 case 0x0000006c: // KEYCODE_BUTTON_START
544 case 0x0000006d: // KEYCODE_BUTTON_SELECT
545 case 0x0000006e: // KEYCODE_BUTTON_MODE
547
548 case 0x0000006f: // KEYCODE_ESCAPE
549 return Qt::Key_Escape;
550
551 case 0x00000070: // KEYCODE_FORWARD_DEL
552 return Qt::Key_Delete;
553
554 case 0x00000071: // KEYCODE_CTRL_LEFT
555 case 0x00000072: // KEYCODE_CTRL_RIGHT
556 return Qt::Key_Control;
557
558 case 0x00000073: // KEYCODE_CAPS_LOCK
559 return Qt::Key_CapsLock;
560
561 case 0x00000074: // KEYCODE_SCROLL_LOCK
562 return Qt::Key_ScrollLock;
563
564 case 0x00000075: // KEYCODE_META_LEFT
565 case 0x00000076: // KEYCODE_META_RIGHT
566 return Qt::Key_Meta;
567
568 case 0x00000077: // KEYCODE_FUNCTION
570
571 case 0x00000078: // KEYCODE_SYSRQ
572 return Qt::Key_Print;
573
574 case 0x00000079: // KEYCODE_BREAK
575 return Qt::Key_Pause;
576
577 case 0x0000007a: // KEYCODE_MOVE_HOME
578 return Qt::Key_Home;
579
580 case 0x0000007b: // KEYCODE_MOVE_END
581 return Qt::Key_End;
582
583 case 0x0000007c: // KEYCODE_MOVE_INSERT
584 return Qt::Key_Insert;
585
586 case 0x0000007d: // KEYCODE_FORWARD
587 return Qt::Key_Forward;
588
589 case 0x0000007e: // KEYCODE_MEDIA_PLAY
590 return Qt::Key_MediaPlay;
591
592 case 0x0000007f: // KEYCODE_MEDIA_PAUSE
593 return Qt::Key_MediaPause;
594
595 case 0x00000080: // KEYCODE_MEDIA_CLOSE
596 case 0x00000081: // KEYCODE_MEDIA_EJECT
597 return Qt::Key_Eject;
598
599 case 0x00000082: // KEYCODE_MEDIA_RECORD
600 return Qt::Key_MediaRecord;
601
602 // F1--F12 0x00000083 -- 0x0000008e
603
604 case 0x0000008f: // KEYCODE_NUM_LOCK
605 return Qt::Key_NumLock;
606
607 // NUMPAD_0--NUMPAD_9 0x00000090 -- 0x00000099
608
609 case 0x0000009a: // KEYCODE_NUMPAD_DIVIDE
611
612 case 0x0000009b: // KEYCODE_NUMPAD_MULTIPLY
614
615 case 0x0000009c: // KEYCODE_NUMPAD_SUBTRACT
617
618 case 0x0000009d: // KEYCODE_NUMPAD_ADD
620
621 case 0x0000009e: // KEYCODE_NUMPAD_DOT
623
624 case 0x0000009f: // KEYCODE_NUMPAD_COMMA
626
627 case 0x000000a0: // KEYCODE_NUMPAD_ENTER
628 return Qt::Key_Enter;
629
630 case 0x000000a1: // KEYCODE_NUMPAD_EQUALS
632
633 case 0x000000a2: // KEYCODE_NUMPAD_LEFT_PAREN
634 return Qt::Key_ParenLeft;
635
636 case 0x000000a3: // KEYCODE_NUMPAD_RIGHT_PAREN
637 return Qt::Key_ParenRight;
638
639 case 0x000000a4: // KEYCODE_VOLUME_MUTE
640 return Qt::Key_VolumeMute;
641
642 case 0x000000a5: // KEYCODE_INFO
643 return Qt::Key_Info;
644
645 case 0x000000a6: // KEYCODE_CHANNEL_UP
646 return Qt::Key_ChannelUp;
647
648 case 0x000000a7: // KEYCODE_CHANNEL_DOWN
649 return Qt::Key_ChannelDown;
650
651 case 0x000000a8: // KEYCODE_ZOOM_IN
652 return Qt::Key_ZoomIn;
653
654 case 0x000000a9: // KEYCODE_ZOOM_OUT
655 return Qt::Key_ZoomOut;
656
657 case 0x000000aa: // KEYCODE_TV
658 case 0x000000ab: // KEYCODE_WINDOW
660
661 case 0x000000ac: // KEYCODE_GUIDE
662 return Qt::Key_Guide;
663
664 case 0x000000ad: // KEYCODE_DVR
666
667 case 0x000000ae: // KEYCODE_BOOKMARK
668 return Qt::Key_AddFavorite;
669
670 case 0x000000af: // KEYCODE_CAPTIONS
671 return Qt::Key_Subtitle;
672
673 case 0x000000b0: // KEYCODE_SETTINGS
674 return Qt::Key_Settings;
675
676 case 0x000000b1: // KEYCODE_TV_POWER
677 case 0x000000b2: // KEYCODE_TV_INPUT
678 case 0x000000b3: // KEYCODE_STB_POWER
679 case 0x000000b4: // KEYCODE_STB_INPUT
680 case 0x000000b5: // KEYCODE_AVR_POWER
681 case 0x000000b6: // KEYCODE_AVR_INPUT
683
684 case 0x000000b7: // KEYCODE_PROG_RED
685 return Qt::Key_Red;
686
687 case 0x000000b8: // KEYCODE_PROG_GREEN
688 return Qt::Key_Green;
689
690 case 0x000000b9: // KEYCODE_PROG_YELLOW
691 return Qt::Key_Yellow;
692
693 case 0x000000ba: // KEYCODE_PROG_BLUE
694 return Qt::Key_Blue;
695
696 // 0x000000bb: // KEYCODE_APP_SWITCH is not sent by the Android O.S.
697
698 // BUTTON_1--KEYCODE_BUTTON_16 0x000000bc -- 0x000000cb
699
700 case 0x000000cc: // KEYCODE_LANGUAGE_SWITCH
701 case 0x000000cd: // KEYCODE_MANNER_MODE do we need such a thing?
702 case 0x000000ce: // KEYCODE_3D_MODE
703 case 0x000000cf: // KEYCODE_CONTACTS
705
706 case 0x000000d0: // KEYCODE_CALENDAR
707 return Qt::Key_Calendar;
708
709 case 0x000000d1: // KEYCODE_MUSIC
710 return Qt::Key_Music;
711
712 case 0x000000d2: // KEYCODE_CALCULATOR
713 return Qt::Key_Calculator;
714
715 // 0x000000d3 -- 0x000000da some japanese specific keys, someone who understand what is about should check !
716
717 // 0x000000db: // KEYCODE_ASSIST not delivered to applications.
718
719 case 0x000000dc: // KEYCODE_BRIGHTNESS_DOWN
721
722 case 0x000000dd: // KEYCODE_BRIGHTNESS_UP
724
725 case 0x000000de: // KEYCODE_MEDIA_AUDIO_TRACK
727
728 default:
729 qWarning() << "Unhandled key code " << key << '!';
731 }
732 }
733
734 static Qt::KeyboardModifiers mapAndroidModifiers(jint modifiers)
735 {
736 Qt::KeyboardModifiers qmodifiers;
737
738 if (modifiers & 0x00000001) // META_SHIFT_ON
739 qmodifiers |= Qt::ShiftModifier;
740
741 if (modifiers & 0x00000002) // META_ALT_ON
742 qmodifiers |= Qt::AltModifier;
743
744 if (modifiers & 0x00000004) // META_SYM_ON
745 qmodifiers |= Qt::MetaModifier;
746
747 if (modifiers & 0x00001000) // META_CTRL_ON
748 qmodifiers |= Qt::ControlModifier;
749
750 return qmodifiers;
751 }
752
753 // maps 0 to the empty string, and anything else to a single-character string
754 static inline QString toString(jint unicode)
755 {
756 return unicode ? QString(QChar(unicode)) : QString();
757 }
758
759 static void keyDown(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier, jboolean autoRepeat)
760 {
763 mapAndroidKey(key).toCombined(),
764 mapAndroidModifiers(modifier),
765 toString(unicode),
766 autoRepeat);
767 }
768
769 static void keyUp(JNIEnv */*env*/, jobject /*thiz*/, jint key, jint unicode, jint modifier, jboolean autoRepeat)
770 {
773 mapAndroidKey(key).toCombined(),
774 mapAndroidModifiers(modifier),
775 toString(unicode),
776 autoRepeat);
777 }
778
779 static void keyboardVisibilityChanged(JNIEnv */*env*/, jobject /*thiz*/, jboolean visibility)
780 {
781 if (!visibility)
783
785 if (inputContext && qGuiApp) {
786 inputContext->emitInputPanelVisibleChanged();
787 if (!visibility) {
788 inputContext->emitKeyboardRectChanged();
789 QMetaObject::invokeMethod(inputContext, "hideSelectionHandles", Qt::QueuedConnection);
790 }
791 }
792 qCDebug(lcQpaInputMethods) << "@@@ KEYBOARDVISIBILITYCHANGED" << inputContext;
793 }
794
795 static void keyboardGeometryChanged(JNIEnv */*env*/, jobject /*thiz*/, jint x, jint y, jint w, jint h)
796 {
797 QRect r = QRect(x, y, w, h);
799 return;
802 if (inputContext && qGuiApp)
803 inputContext->emitKeyboardRectChanged();
804
805 qCDebug(lcQpaInputMethods) << "@@@ KEYBOARDRECTCHANGED" << m_softwareKeyboardRect;
806 }
807
808 static void handleLocationChanged(JNIEnv */*env*/, jobject /*thiz*/, int id, int x, int y)
809 {
810 qCDebug(lcQpaInputMethods) << "@@@ handleLocationChanged" << id << x << y;
812 if (inputContext && qGuiApp)
813 QMetaObject::invokeMethod(inputContext, "handleLocationChanged", Qt::BlockingQueuedConnection,
814 Q_ARG(int, id), Q_ARG(int, x), Q_ARG(int, y));
815
816 }
817
818 static JNINativeMethod methods[] = {
819 {"touchBegin","(I)V",(void*)touchBegin},
820 {"touchAdd","(IIIZIIFFFF)V",(void*)touchAdd},
821 {"touchEnd","(II)V",(void*)touchEnd},
822 {"touchCancel", "(I)V", (void *)touchCancel},
823 {"mouseDown", "(III)V", (void *)mouseDown},
824 {"mouseUp", "(III)V", (void *)mouseUp},
825 {"mouseMove", "(III)V", (void *)mouseMove},
826 {"mouseWheel", "(IIIFF)V", (void *)mouseWheel},
827 {"longPress", "(III)V", (void *)longPress},
828 {"isTabletEventSupported", "()Z", (void *)isTabletEventSupported},
829 {"tabletEvent", "(IIJIIIFFF)V", (void *)tabletEvent},
830 {"keyDown", "(IIIZ)V", (void *)keyDown},
831 {"keyUp", "(IIIZ)V", (void *)keyUp},
832 {"keyboardVisibilityChanged", "(Z)V", (void *)keyboardVisibilityChanged},
833 {"keyboardGeometryChanged", "(IIII)V", (void *)keyboardGeometryChanged},
834 {"handleLocationChanged", "(III)V", (void *)handleLocationChanged}
835 };
836
837 bool registerNatives(JNIEnv *env)
838 {
839 jclass appClass = QtAndroid::applicationClass();
840
841 if (env->RegisterNatives(appClass, methods, sizeof(methods) / sizeof(methods[0])) < 0) {
842 __android_log_print(ANDROID_LOG_FATAL,"Qt", "RegisterNatives failed");
843 return false;
844 }
845
846 return true;
847 }
848}
849
static QAndroidInputContext * androidInputContext()
void setTouchDevice(QPointingDevice *touchDevice)
\inmodule QtCore
Definition qchar.h:48
State
Specifies the state of this event point.
Definition qeventpoint.h:49
@ KeyRelease
Definition qcoreevent.h:65
@ MouseMove
Definition qcoreevent.h:63
@ KeyPress
Definition qcoreevent.h:64
@ MouseButtonPress
Definition qcoreevent.h:60
@ MouseButtonRelease
Definition qcoreevent.h:61
static constexpr QKeyCombination fromCombined(int combined)
Definition qlist.h:74
bool isEmpty() const noexcept
Definition qlist.h:390
void push_back(parameter_type t)
Definition qlist.h:672
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void clear()
Definition qlist.h:417
\inmodule QtCore
Definition qmutex.h:317
void emitInputPanelVisibleChanged()
Active QPlatformInputContext is responsible for providing visible property to QInputMethod.
void emitKeyboardRectChanged()
Active QPlatformInputContext is responsible for providing keyboardRectangle property to QInputMethod.
\inmodule QtCore\reentrant
Definition qpoint.h:214
constexpr QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
Definition qpoint.h:394
\inmodule QtCore\reentrant
Definition qpoint.h:23
constexpr int x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:127
constexpr int y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:132
\inmodule QtCore
Definition qpointer.h:18
T * data() const
Definition qpointer.h:56
The QPointingDevice class describes a device from which mouse, touch or tablet events originate.
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr QPointF center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:685
\inmodule QtCore\reentrant
Definition qrect.h:30
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static bool handleTouchEvent(QWindow *window, const QPointingDevice *device, const QList< struct TouchPoint > &points, Qt::KeyboardModifiers mods=Qt::NoModifier)
static bool handleTabletEvent(QWindow *window, ulong timestamp, const QPointingDevice *device, const QPointF &local, const QPointF &global, Qt::MouseButtons buttons, qreal pressure, int xTilt, int yTilt, qreal tangentialPressure, qreal rotation, int z, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
static bool handleTouchCancelEvent(QWindow *window, const QPointingDevice *device, Qt::KeyboardModifiers mods=Qt::NoModifier)
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
static void registerInputDevice(const QInputDevice *device)
static bool handleKeyEvent(QWindow *window, QEvent::Type t, int k, Qt::KeyboardModifiers mods, const QString &text=QString(), bool autorep=false, ushort count=1)
static bool handleWheelEvent(QWindow *window, const QPointF &local, const QPointF &global, QPoint pixelDelta, QPoint angleDelta, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::ScrollPhase phase=Qt::NoScrollPhase, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
\inmodule QtGui
Definition qwindow.h:63
EGLImageKHR int int EGLuint64KHR * modifiers
QCursor cursor
else opt state
[0]
static bool registerNatives()
Combined button and popup list for selecting options.
static void mouseDown(JNIEnv *, jobject, jint, jint x, jint y)
static bool isTabletEventSupported(JNIEnv *, jobject)
void updateSelection(int selStart, int selEnd, int candidatesStart, int candidatesEnd)
static void touchBegin(JNIEnv *, jobject, jint)
static QString toString(jint unicode)
static bool m_ignoreMouseEvents
static QKeyCombination mapAndroidKey(int key)
static QRect m_softwareKeyboardRect
static void mouseWheel(JNIEnv *, jobject, jint, jint x, jint y, jfloat hdelta, jfloat vdelta)
static void tabletEvent(JNIEnv *, jobject, jint, jint deviceId, jlong time, jint action, jint pointerType, jint buttonState, jfloat x, jfloat y, jfloat pressure)
static void keyUp(JNIEnv *, jobject, jint key, jint unicode, jint modifier, jboolean autoRepeat)
static void longPress(JNIEnv *, jobject, jint, jint x, jint y)
void showSoftwareKeyboard(int left, int top, int width, int height, int inputHints, int enterKeyType)
static QPointingDevice * getTouchDevice()
static Qt::KeyboardModifiers mapAndroidModifiers(jint modifiers)
bool isSoftwareKeyboardVisible()
static void touchAdd(JNIEnv *, jobject, jint, jint id, jint action, jboolean, jint x, jint y, jfloat major, jfloat minor, jfloat rotation, jfloat pressure)
static QList< QWindowSystemInterface::TouchPoint > m_touchPoints
static QPointer< QWindow > m_mouseGrabber
static void keyboardGeometryChanged(JNIEnv *, jobject, jint x, jint y, jint w, jint h)
static void keyboardVisibilityChanged(JNIEnv *, jobject, jboolean visibility)
static void mouseUp(JNIEnv *, jobject, jint, jint x, jint y)
static void keyDown(JNIEnv *, jobject, jint key, jint unicode, jint modifier, jboolean autoRepeat)
static void touchCancel(JNIEnv *, jobject, jint)
void updateHandles(int mode, QPoint editMenuPos, uint32_t editButtons, QPoint cursor, QPoint anchor, bool rtl)
static void handleLocationChanged(JNIEnv *, jobject, int id, int x, int y)
QRect softwareKeyboardRect()
static JNINativeMethod methods[]
static void mouseMove(JNIEnv *, jobject, jint, jint x, jint y)
static void touchEnd(JNIEnv *, jobject, jint, jint)
QBasicMutex * platformInterfaceMutex()
QWindow * topLevelWindowAt(const QPoint &globalPos)
QAndroidPlatformIntegration * androidPlatformIntegration()
int availableWidthPixels()
jclass applicationClass()
int availableHeightPixels()
@ LeftButton
Definition qnamespace.h:57
@ RightButton
Definition qnamespace.h:58
@ NoButton
Definition qnamespace.h:56
@ Key_Escape
Definition qnamespace.h:658
@ Key_MediaPrevious
Definition qnamespace.h:855
@ Key_Tab
Definition qnamespace.h:659
@ Key_ZoomIn
Definition qnamespace.h:951
@ Key_LaunchMail
Definition qnamespace.h:865
@ Key_ZoomOut
Definition qnamespace.h:952
@ Key_ParenRight
Definition qnamespace.h:522
@ Key_Yellow
Definition qnamespace.h:988
@ Key_Plus
Definition qnamespace.h:524
@ Key_Shift
Definition qnamespace.h:678
@ Key_Return
Definition qnamespace.h:662
@ Key_KeyboardBrightnessUp
Definition qnamespace.h:886
@ Key_QuoteLeft
Definition qnamespace.h:577
@ Key_Right
Definition qnamespace.h:674
@ Key_Enter
Definition qnamespace.h:663
@ Key_PageUp
Definition qnamespace.h:676
@ Key_Space
Definition qnamespace.h:512
@ Key_ChannelDown
Definition qnamespace.h:992
@ Key_MediaTogglePlayPause
Definition qnamespace.h:859
@ Key_Hangup
@ Key_Music
Definition qnamespace.h:958
@ Key_At
Definition qnamespace.h:545
@ Key_PowerOff
Definition qnamespace.h:888
@ Key_Backspace
Definition qnamespace.h:661
@ Key_VolumeUp
Definition qnamespace.h:847
@ Key_VolumeDown
Definition qnamespace.h:845
@ Key_Insert
Definition qnamespace.h:664
@ Key_BracketRight
Definition qnamespace.h:574
@ Key_Guide
Definition qnamespace.h:994
@ Key_Subtitle
Definition qnamespace.h:966
@ Key_Left
Definition qnamespace.h:672
@ Key_BracketLeft
Definition qnamespace.h:572
@ Key_A
Definition qnamespace.h:546
@ Key_NumberSign
Definition qnamespace.h:516
@ Key_0
Definition qnamespace.h:529
@ Key_Control
Definition qnamespace.h:679
@ Key_AddFavorite
Definition qnamespace.h:897
@ Key_AudioRewind
Definition qnamespace.h:902
@ Key_Alt
Definition qnamespace.h:681
@ Key_VolumeMute
Definition qnamespace.h:846
@ Key_Equal
Definition qnamespace.h:542
@ Key_ChannelUp
Definition qnamespace.h:991
@ Key_Print
Definition qnamespace.h:667
@ Key_Pause
Definition qnamespace.h:666
@ Key_AudioCycleTrack
Definition qnamespace.h:967
@ Key_Calendar
Definition qnamespace.h:933
@ Key_Up
Definition qnamespace.h:673
@ Key_Minus
Definition qnamespace.h:526
@ Key_Info
Definition qnamespace.h:995
@ Key_CameraFocus
@ Key_Down
Definition qnamespace.h:675
@ Key_ParenLeft
Definition qnamespace.h:521
@ Key_Red
Definition qnamespace.h:986
@ Key_MediaPause
Definition qnamespace.h:858
@ Key_Delete
Definition qnamespace.h:665
@ Key_NumLock
Definition qnamespace.h:683
@ Key_Meta
Definition qnamespace.h:680
@ Key_Backslash
Definition qnamespace.h:573
@ Key_Forward
Definition qnamespace.h:842
@ Key_Settings
Definition qnamespace.h:996
@ Key_ScrollLock
Definition qnamespace.h:684
@ Key_Eject
Definition qnamespace.h:890
@ Key_MediaRecord
Definition qnamespace.h:857
@ Key_F1
Definition qnamespace.h:685
@ Key_Semicolon
Definition qnamespace.h:540
@ Key_Green
Definition qnamespace.h:987
@ Key_Calculator
Definition qnamespace.h:908
@ Key_Slash
Definition qnamespace.h:528
@ Key_Period
Definition qnamespace.h:527
@ Key_Menu
Definition qnamespace.h:722
@ Key_PageDown
Definition qnamespace.h:677
@ Key_Back
Definition qnamespace.h:841
@ Key_Home
Definition qnamespace.h:670
@ Key_KeyboardBrightnessDown
Definition qnamespace.h:887
@ Key_Camera
@ Key_Clear
Definition qnamespace.h:669
@ Key_Comma
Definition qnamespace.h:525
@ Key_MediaStop
Definition qnamespace.h:854
@ Key_Call
@ Key_CapsLock
Definition qnamespace.h:682
@ Key_MicMute
Definition qnamespace.h:984
@ Key_MediaPlay
Definition qnamespace.h:853
@ Key_Search
Definition qnamespace.h:862
@ Key_Asterisk
Definition qnamespace.h:523
@ Key_Blue
Definition qnamespace.h:989
@ Key_Apostrophe
Definition qnamespace.h:520
@ Key_unknown
@ Key_Explorer
Definition qnamespace.h:918
@ Key_AudioForward
Definition qnamespace.h:963
@ Key_MediaNext
Definition qnamespace.h:856
@ Key_End
Definition qnamespace.h:671
@ ShiftModifier
@ ControlModifier
@ MetaModifier
@ KeypadModifier
@ NoModifier
@ AltModifier
@ BlockingQueuedConnection
@ QueuedConnection
#define qGuiApp
#define qWarning
Definition qlogging.h:162
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr float qRadiansToDegrees(float radians)
Definition qmath.h:281
#define Q_ARG(Type, data)
Definition qobjectdefs.h:62
GLint GLint GLint GLint GLint x
[0]
GLenum mode
GLuint64 key
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean r
[2]
GLenum GLuint id
[7]
GLdouble GLdouble GLdouble GLdouble top
GLint GLsizei width
GLint left
GLint y
GLfloat GLfloat GLfloat GLfloat h
Q_CORE_EXPORT int qEnvironmentVariableIntValue(const char *varName, bool *ok=nullptr) noexcept
unsigned long ulong
Definition qtypes.h:30
static QPointingDevice::PointerType pointerType(unsigned currentCursor)
QReadWriteLock lock
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(nullptr), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
\threadsafe This is an overloaded member function, provided for convenience. It differs from the abov...