diff --git a/abstract_client.h b/abstract_client.h --- a/abstract_client.h +++ b/abstract_client.h @@ -727,6 +727,9 @@ QRect inputGeometry() const override; + QRect virtualKeyboardGeometry() const; + void setVirtualKeyboardGeometry(const QRect &geo); + /** * Restores the AbstractClient after it had been hidden due to show on screen edge functionality. * The AbstractClient also gets raised (e.g. Panel mode windows can cover) and the AbstractClient @@ -957,6 +960,7 @@ int borderBottom() const; virtual void changeMaximize(bool horizontal, bool vertical, bool adjust) = 0; virtual void setGeometryRestore(const QRect &geo) = 0; + /** * Called from move after updating the geometry. Can be reimplemented to perform specific tasks. * The base implementation does nothing. @@ -1201,6 +1205,8 @@ friend class GeometryUpdatesBlocker; QRect m_visibleRectBeforeGeometryUpdate; QRect m_geometryBeforeUpdateBlocking; + QRect m_virtualKeyboardGeometry; + QRect m_keyboardGeometryRestore; struct { bool enabled = false; diff --git a/abstract_client.cpp b/abstract_client.cpp --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -72,6 +72,14 @@ connect(Decoration::DecorationBridge::self(), &QObject::destroyed, this, &AbstractClient::destroyDecoration); + // If the user manually moved the window, don't restore it after the keyboard closes + connect(this, &AbstractClient::clientFinishUserMovedResized, this, [this] () { + m_keyboardGeometryRestore = QRect(); + }); + connect(this, qOverload(&AbstractClient::clientMaximizedStateChanged), this, [this] () { + m_keyboardGeometryRestore = QRect(); + }); + // replace on-screen-display on size changes connect(this, &AbstractClient::geometryShapeChanged, this, [this] (Toplevel *c, const QRect &old) { @@ -1871,6 +1879,38 @@ return Toplevel::inputGeometry(); } +QRect AbstractClient::virtualKeyboardGeometry() const +{ + return m_virtualKeyboardGeometry; +} + +void AbstractClient::setVirtualKeyboardGeometry(const QRect &geo) +{ + // No keyboard anymore + if (geo.isEmpty() && !m_keyboardGeometryRestore.isEmpty()) { + setGeometry(m_keyboardGeometryRestore); + m_keyboardGeometryRestore = QRect(); + } else if (geo.isEmpty()) { + return; + // The keyboard has just been opened (rather than resized) save client geometry for a restore + } else if (m_keyboardGeometryRestore.isEmpty()) { + m_keyboardGeometryRestore = geometry(); + } + + m_virtualKeyboardGeometry = geo; + + if (!geo.intersects(m_keyboardGeometryRestore)) { + return; + } + + const QRect availableArea = workspace()->clientArea(MaximizeArea, this); + QRect newWindowGeometry = m_keyboardGeometryRestore; + + newWindowGeometry.moveBottom(geo.top()); + newWindowGeometry.setTop(qMax(newWindowGeometry.top(), availableArea.top())); + setGeometry(newWindowGeometry); +} + bool AbstractClient::dockWantsInput() const { return false; diff --git a/virtualkeyboard.h b/virtualkeyboard.h --- a/virtualkeyboard.h +++ b/virtualkeyboard.h @@ -25,7 +25,10 @@ #include #include +#include + class QQuickView; +class QTimer; class QWindow; class KStatusNotifierItem; @@ -53,10 +56,14 @@ void hide(); void setEnabled(bool enable); void updateSni(); + void updateInputPanelState(); bool m_enabled = false; KStatusNotifierItem *m_sni = nullptr; QScopedPointer m_inputWindow; + QPointer m_trackedClient; + QTimer *m_floodTimer; + QMetaObject::Connection m_waylandShowConnection; QMetaObject::Connection m_waylandHideConnection; QMetaObject::Connection m_waylandHintsConnection; diff --git a/virtualkeyboard.cpp b/virtualkeyboard.cpp --- a/virtualkeyboard.cpp +++ b/virtualkeyboard.cpp @@ -26,10 +26,12 @@ #include "wayland_server.h" #include "workspace.h" #include "xkb.h" +#include "shell_client.h" #include #include #include +#include #include #include @@ -44,6 +46,7 @@ #include #include #include +#include // xkbcommon #include @@ -57,6 +60,9 @@ VirtualKeyboard::VirtualKeyboard(QObject *parent) : QObject(parent) { + m_floodTimer = new QTimer(this); + m_floodTimer->setSingleShot(true); + m_floodTimer->setInterval(250); // this is actually too late. Other processes are started before init, // so might miss the availability of text input // but without Workspace we don't have the window listed at all @@ -146,8 +152,14 @@ qApp->inputMethod()->update(Qt::ImQueryAll); } ); - // TODO: calculate overlap - t->setInputPanelState(m_inputWindow->isVisible(), QRect(0, 0, 0, 0)); + + // Reset the old client virtual keybaord geom if necessary + if (m_trackedClient) { + m_trackedClient->setVirtualKeyboardGeometry(QRect()); + } + m_trackedClient = waylandServer()->findAbstractClient(waylandServer()->seat()->focusedTextInputSurface()); + + updateInputPanelState(); } else { m_waylandShowConnection = QMetaObject::Connection(); m_waylandHideConnection = QMetaObject::Connection(); @@ -176,20 +188,10 @@ m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); } ); - connect(qApp->inputMethod(), &QInputMethod::visibleChanged, m_inputWindow.data(), - [this] { - m_inputWindow->setVisible(qApp->inputMethod()->isVisible()); - if (qApp->inputMethod()->isVisible()) { - m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); - } - if (waylandServer()) { - if (auto t = waylandServer()->seat()->focusedTextInput()) { - // TODO: calculate overlap - t->setInputPanelState(m_inputWindow->isVisible(), QRect(0, 0, 0, 0)); - } - } - } - ); + + connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this, &VirtualKeyboard::updateInputPanelState); + + connect(m_inputWindow->rootObject(), &QQuickItem::childrenRectChanged, this, &VirtualKeyboard::updateInputPanelState); } void VirtualKeyboard::setEnabled(bool enabled) @@ -226,6 +228,46 @@ } } +void VirtualKeyboard::updateInputPanelState() +{ + if (!waylandServer()) { + return; + } + + auto t = waylandServer()->seat()->focusedTextInput(); + + if (!t) { + return; + } + + const bool inputPanelHasBeenClosed = m_inputWindow->isVisible() && !qApp->inputMethod()->isVisible(); + if (inputPanelHasBeenClosed && m_floodTimer->isActive()) { + return; + } + m_floodTimer->start(); + + m_inputWindow->setVisible(qApp->inputMethod()->isVisible()); + + if (qApp->inputMethod()->isVisible()) { + m_inputWindow->setMask(m_inputWindow->rootObject()->childrenRect().toRect()); + } + + 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); + + t->setInputPanelState(true, QRect(0, 0, 0, 0)); + + } else { + if (inputPanelHasBeenClosed && m_trackedClient) { + m_trackedClient->setVirtualKeyboardGeometry(QRect()); + } + + t->setInputPanelState(false, QRect(0, 0, 0, 0)); + } +} + void VirtualKeyboard::show() { if (m_inputWindow.isNull() || !m_enabled) {