From 594b1bd20256de146b759aa65d60795ee8542e53 Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Wed, 25 Aug 2021 16:42:32 +0300 Subject: [PATCH 1/3] Avoid reparenting of InputPanel when the window is being destroyed Fixes: QTBUG-95996 Pick-to: 5.15 6.1 6.2 Change-Id: Iac4d06cacf2e672bf4a7676f478798f27ab6f4a2 Reviewed-by: Jarkko Koivikko Reviewed-by: Volker Hilsheimer (cherry picked from commit 0464e1bacca28d7e459f105b07fbea6bb5b20930) --- src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp index a7c0aad9..e04c828d 100644 --- a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp +++ b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp @@ -278,8 +278,10 @@ void QVirtualKeyboardInputContextPrivate::onInputItemChanged() For integrated keyboards, make sure it's a sibling to the overlay. The high z-order will make sure it gets events also during a modal session. */ - if (isDesktopPanel.isValid() && !isDesktopPanel.toBool()) - vkbPanel->setParentItem(quickItem->window()->contentItem()); + if (isDesktopPanel.isValid() && !isDesktopPanel.toBool()) { + if (QQuickWindow *quickWindow = quickItem->window()) + vkbPanel->setParentItem(quickWindow->contentItem()); + } } } } else { -- 2.36.0 From 1c15d4f231c66d3f39f648942b120159fe7a8be0 Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Mon, 7 Jun 2021 14:04:27 +0300 Subject: [PATCH 2/3] Fix high CPU utilization caused by key repeat timer Key repeat timer has been broken since the beginning. The key repeat timer leaked timer instances while processing the event, causing the accumulation of unprocessed timer events and high CPU utilization. Fix the issue by killing the original timer (long press delay 600 ms) and starting the key repeat timer (repeat delay 50 ms) once. [ChangeLog] Fixed high CPU utilization caused by key repeat timer. Pick-to: 5.12 5.15 6.1 6.2 Fixes: QTBUG-94259 Change-Id: Iff47249db27cda3750f497cb02c1cb642261e032 Reviewed-by: Jarkko Koivikko (cherry picked from commit 63a944ff12580f2c333a162ecaecd12419a39c10) --- src/virtualkeyboard/qvirtualkeyboardinputengine.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/virtualkeyboard/qvirtualkeyboardinputengine.cpp b/src/virtualkeyboard/qvirtualkeyboardinputengine.cpp index e64ea4eb..5f74c2a7 100644 --- a/src/virtualkeyboard/qvirtualkeyboardinputengine.cpp +++ b/src/virtualkeyboard/qvirtualkeyboardinputengine.cpp @@ -716,9 +716,11 @@ void QVirtualKeyboardInputEngine::timerEvent(QTimerEvent *timerEvent) { Q_D(QVirtualKeyboardInputEngine); if (timerEvent->timerId() == d->repeatTimer) { - d->repeatTimer = 0; d->virtualKeyClick(d->activeKey, d->activeKeyText, d->activeKeyModifiers, true); - d->repeatTimer = startTimer(50); + if (!d->repeatCount) { + killTimer(d->repeatTimer); + d->repeatTimer = startTimer(50); + } d->repeatCount++; } } -- 2.36.0 From e8ae4757dd32e8dbf69a7c57f2bc5c1e238416db Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Tue, 8 Jun 2021 15:25:09 +0300 Subject: [PATCH 3/3] Fix processing of hard Qt::Key_Backspace and Qt::Key_Delete Even though the virtual keyboard does not support hard keys at the moment, this kind of processing could be possible in the future. In the mean time, fix processing of backspace and delete keys. In particular, if such key is pressed the pre-edit text is not empty: - Reset input method state (should not modify pre-edit) - Clear pre-edit - Return true (to indicate no further processing is required) [ChangeLog] Fix processing of hard backspace and delete keys. Fixes: QTBUG-94017 Pick-to: 5.15 6.1 6.2 Change-Id: I7035f7612e966de6d17d92e754ecd7bdb3a6e530 Reviewed-by: Jarkko Koivikko (cherry picked from commit ca5b712dfc8e67aece0eb7374ffe5921e2aa45e8) --- .../qvirtualkeyboardinputcontext_p.cpp | 14 ++++++++--- tests/auto/inputpanel/data/tst_inputpanel.qml | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp index e04c828d..cacf33f0 100644 --- a/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp +++ b/src/virtualkeyboard/qvirtualkeyboardinputcontext_p.cpp @@ -507,6 +507,7 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) QEvent::Type type = event->type(); if (type == QEvent::KeyPress || type == QEvent::KeyRelease) { const QKeyEvent *keyEvent = static_cast(event); + const int key = keyEvent->key(); // Keep track of pressed keys update key event state if (type == QEvent::KeyPress) @@ -520,7 +521,6 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) setState(State::KeyEvent); #ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION - int key = keyEvent->key(); if ((key >= Qt::Key_Left && key <= Qt::Key_Down) || key == Qt::Key_Return) { if (type == QEvent::KeyPress && platformInputContext->isInputPanelVisible()) { activeNavigationKeys += key; @@ -535,8 +535,16 @@ bool QVirtualKeyboardInputContextPrivate::filterEvent(const QEvent *event) #endif // Break composing text since the virtual keyboard does not support hard keyboard events - if (!preeditText.isEmpty()) - commit(); + if (!preeditText.isEmpty()) { + if (type == QEvent::KeyPress && (key == Qt::Key_Delete || key == Qt::Key_Backspace)) { + reset(); + Q_Q(QVirtualKeyboardInputContext); + q->clear(); + return true; + } else { + commit(); + } + } } #ifdef QT_VIRTUALKEYBOARD_ARROW_KEY_NAVIGATION else if (type == QEvent::ShortcutOverride) { diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml index d814f282..f60acc64 100644 --- a/tests/auto/inputpanel/data/tst_inputpanel.qml +++ b/tests/auto/inputpanel/data/tst_inputpanel.qml @@ -321,6 +321,30 @@ Rectangle { compare(textInput.text, "A") } + function test_hardKeyBackspaceClearsInput_data() { + return [ + { initLocale: "en_GB", initText: "12345", initCursorPosition: 1, inputSequence: "hello", outputText: "12345", expectedCursorPosition: 1 }, + ] + } + + function test_hardKeyBackspaceClearsInput(data) { + prepareTest(data) + + if (!inputPanel.wordCandidateListVisibleHint) + skip("Prediction/spell correction not enabled") + + compare(Qt.inputMethod.locale.name, Qt.locale(data.initLocale).name) + for (var inputIndex in data.inputSequence) { + verify(inputPanel.virtualKeyClick(data.inputSequence[inputIndex])) + } + + keyClick(Qt.Key_Backspace) + waitForRendering(textInput) + + compare(textInput.text, data.outputText) + compare(textInput.cursorPosition, data.expectedCursorPosition) + } + function test_hardKeyInput() { prepareTest() -- 2.36.0