From d7cfd0012a04cb508c17b59f834242bd804f333c Mon Sep 17 00:00:00 2001 From: Bhushan Shah Date: Fri, 9 Aug 2019 11:40:22 +0530 Subject: [PATCH] Revert "Load the keyboard on-demand" This reverts commit 5c39795b88d33e53153dedd62eeae2a821ccf09d. This unfortuntaely introduces the regression on the phone where there's multiple bugs preset, - Keyboard can no longer be closed using close button, or removing focus. - Opening keyboard makes application get no input events, making it look like it is crashed/stuck or hung. I failed to reproduce this bug on desktop unfortunately. CCMAIL: Aleix Pol --- qml/virtualkeyboard/main.qml | 83 ++++++++++++++---------------------- virtualkeyboard.cpp | 52 +++++++++------------- virtualkeyboard.h | 4 +- 3 files changed, 54 insertions(+), 85 deletions(-) diff --git a/qml/virtualkeyboard/main.qml b/qml/virtualkeyboard/main.qml index 5887e876d0..ef1a967f3d 100644 --- a/qml/virtualkeyboard/main.qml +++ b/qml/virtualkeyboard/main.qml @@ -18,66 +18,47 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ import QtQuick 2.0 -import QtQuick.Window 2.0 import QtQuick.Controls 2.3 import QtQuick.VirtualKeyboard 2.1 import org.kde.kirigami 2.5 as Kirigami -Window { +Item { id: window property real adjustment: 0 property real adjustmentFactor: 0.0 - visible: false + InputPanel { + id: inputPanel + objectName: "inputPanel" + width: parent.width - parent.width * parent.adjustmentFactor + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + } + //NOTE: ToolButton for some reasons breaks the virtual keyboard loading on Plasma Mobile + Button { + id: resizeButton + visible: !Kirigami.Settings.isMobile //don't show on handheld devices + flat: true + display: AbstractButton.IconOnly + icon.name: "transform-scale" + icon.color: "white" + down: mouseArea.pressed - Loader { - anchors.fill: parent + anchors { + right: inputPanel.right + top: inputPanel.top + } - sourceComponent: window.visible ? theKeyboard : null - - Component { - id: theKeyboard - Item { - InputPanel { - id: inputPanel - - readonly property real sideMargin: window.width * window.adjustmentFactor/2 - anchors { - left: parent.left - right: parent.right - bottom: parent.bottom - leftMargin: sideMargin - rightMargin: sideMargin - } - } - //NOTE: ToolButton for some reasons breaks the virtual keyboard loading on Plasma Mobile - Button { - id: resizeButton - visible: !Kirigami.Settings.isMobile //don't show on handheld devices - flat: true - display: AbstractButton.IconOnly - icon.name: "transform-scale" - icon.color: "white" - down: mouseArea.pressed - - anchors { - right: inputPanel.right - top: inputPanel.top - } - - MouseArea { - id: mouseArea - property real startPoint: 0 - anchors.fill: parent - onPressed: { - startPoint = mouse.x; - } - onPositionChanged: { - window.adjustment -= (mouse.x - startPoint); - window.adjustmentFactor = Math.min(Math.max(window.adjustment / window.width, 0.0), 0.66); - startPoint = mouse.x; - } - } - } + MouseArea { + id: mouseArea + property real startPoint: 0 + anchors.fill: parent + onPressed: { + startPoint = mouse.x; + } + onPositionChanged: { + window.adjustment -= (mouse.x - startPoint); + window.adjustmentFactor = Math.min(Math.max(window.adjustment / window.width, 0.0), 0.66); + startPoint = mouse.x; } } } diff --git a/virtualkeyboard.cpp b/virtualkeyboard.cpp index b799c5d948..7ee7e5e2ce 100644 --- a/virtualkeyboard.cpp +++ b/virtualkeyboard.cpp @@ -44,8 +44,8 @@ along with this program. If not, see . #include #include #include +#include #include -#include #include // xkbcommon #include @@ -74,20 +74,17 @@ VirtualKeyboard::~VirtualKeyboard() = default; void VirtualKeyboard::init() { // TODO: need a shared Qml engine - const QUrl source = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME "/virtualkeyboard/main.qml"))); - qCDebug(KWIN_VIRTUALKEYBOARD) << "Initializing window" << source; - QQmlApplicationEngine* engine = new QQmlApplicationEngine(this); - connect(engine, &QQmlEngine::warnings, this, [] (const QList &warnings) { qCWarning(KWIN_VIRTUALKEYBOARD ) << warnings; }); - engine->load(source); - - if (engine->rootObjects().isEmpty()) { - qCWarning(KWIN_VIRTUALKEYBOARD) << "could not load the virtual keyboard"; + qCDebug(KWIN_VIRTUALKEYBOARD) << "Initializing window"; + m_inputWindow.reset(new QQuickView(nullptr)); + m_inputWindow->setFlags(Qt::FramelessWindowHint); + m_inputWindow->setGeometry(screens()->geometry(screens()->current())); + m_inputWindow->setResizeMode(QQuickView::SizeRootObjectToView); + m_inputWindow->setSource(QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME "/virtualkeyboard/main.qml")))); + if (m_inputWindow->status() != QQuickView::Status::Ready) { + qCWarning(KWIN_VIRTUALKEYBOARD) << "window not ready yet"; m_inputWindow.reset(); return; } - - m_inputWindow.reset(qobject_cast(engine->rootObjects().constFirst())); - m_inputWindow->setFlags(Qt::FramelessWindowHint); m_inputWindow->setProperty("__kwin_input_method", true); if (waylandServer()) { @@ -140,27 +137,18 @@ void VirtualKeyboard::init() m_waylandShowConnection = connect(t, &TextInputInterface::requestShowInputPanel, this, &VirtualKeyboard::show); m_waylandHideConnection = connect(t, &TextInputInterface::requestHideInputPanel, this, &VirtualKeyboard::hide); m_waylandSurroundingTextConnection = connect(t, &TextInputInterface::surroundingTextChanged, this, - [this] { - if (m_enabled) { - m_inputWindow->show(); - } + [] { qApp->inputMethod()->update(Qt::ImSurroundingText | Qt::ImCursorPosition | Qt::ImAnchorPosition); } ); m_waylandHintsConnection = connect(t, &TextInputInterface::contentTypeChanged, this, - [this] { - if (m_enabled) { - m_inputWindow->show(); - } + [] { qApp->inputMethod()->update(Qt::ImHints); } ); m_waylandResetConnection = connect(t, &TextInputInterface::requestReset, qApp->inputMethod(), &QInputMethod::reset); m_waylandEnabledConnection = connect(t, &TextInputInterface::enabledChanged, this, - [this] { - if (m_enabled) { - m_inputWindow->show(); - } + [] { qApp->inputMethod()->update(Qt::ImQueryAll); } ); @@ -197,19 +185,19 @@ void VirtualKeyboard::init() } ); m_inputWindow->setColor(Qt::transparent); - m_inputWindow->setMask(m_inputWindow->contentItem()->childrenRect().toRect()); - connect(m_inputWindow->contentItem(), &QQuickItem::childrenRectChanged, m_inputWindow.data(), + m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); + connect(m_inputWindow->rootObject(), &QQuickItem::childrenRectChanged, m_inputWindow.data(), [this] { if (!m_inputWindow) { return; } - m_inputWindow->setMask(m_inputWindow->contentItem()->childrenRect().toRect()); + m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); } ); connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this, &VirtualKeyboard::updateInputPanelState); - connect(m_inputWindow->contentItem(), &QQuickItem::childrenRectChanged, this, &VirtualKeyboard::updateInputPanelState); + connect(m_inputWindow->rootObject(), &QQuickItem::childrenRectChanged, this, &VirtualKeyboard::updateInputPanelState); } void VirtualKeyboard::setEnabled(bool enabled) @@ -268,11 +256,11 @@ void VirtualKeyboard::updateInputPanelState() m_inputWindow->setVisible(qApp->inputMethod()->isVisible()); if (qApp->inputMethod()->isVisible()) { - m_inputWindow->setMask(m_inputWindow->contentItem()->childrenRect().toRect()); + m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); } - if (m_inputWindow->isVisible() && m_trackedClient && m_inputWindow) { - const QRect inputPanelGeom = m_inputWindow->contentItem()->childrenRect().toRect().translated(m_inputWindow->geometry().topLeft()); + if (m_inputWindow->isVisible() && m_trackedClient && m_inputWindow->rootObject()) { + const QRect inputPanelGeom = m_inputWindow->rootObject()->childrenRect().toRect().translated(m_inputWindow->geometry().topLeft()); m_trackedClient->setVirtualKeyboardGeometry(inputPanelGeom); @@ -298,7 +286,7 @@ void VirtualKeyboard::show() void VirtualKeyboard::hide() { - if (!m_inputWindow) { + if (m_inputWindow.isNull()) { return; } qApp->inputMethod()->hide(); diff --git a/virtualkeyboard.h b/virtualkeyboard.h index 641bdfd1c4..21d2bad33b 100644 --- a/virtualkeyboard.h +++ b/virtualkeyboard.h @@ -27,7 +27,7 @@ along with this program. If not, see . #include -class QQuickWindow; +class QQuickView; class QTimer; class QWindow; class KStatusNotifierItem; @@ -60,7 +60,7 @@ private: bool m_enabled = false; KStatusNotifierItem *m_sni = nullptr; - QScopedPointer m_inputWindow; + QScopedPointer m_inputWindow; QPointer m_trackedClient; // If a surface loses focus immediately after being resized by the keyboard, don't react to it to avoid resize loops QTimer *m_floodTimer;