diff --git a/abstract_client.h b/abstract_client.h --- a/abstract_client.h +++ b/abstract_client.h @@ -806,6 +806,8 @@ **/ void tabGroupChanged(); + virtual void setGeometryRestore(const QRect &geo) = 0; + protected: AbstractClient(); void setFirstInTabBox(bool enable) { @@ -907,7 +909,7 @@ int borderTop() const; 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. diff --git a/virtualkeyboard.h b/virtualkeyboard.h --- a/virtualkeyboard.h +++ b/virtualkeyboard.h @@ -25,6 +25,11 @@ #include #include +#include + +#include +#include + class QQuickView; class QWindow; class KStatusNotifierItem; @@ -53,10 +58,13 @@ void hide(); void setEnabled(bool enable); void updateSni(); + void updateInputPanelState(); bool m_enabled = false; KStatusNotifierItem *m_sni = nullptr; QScopedPointer m_inputWindow; + QPointer m_trackedClient; + 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 @@ -34,6 +34,8 @@ #include #include +#include + #include #include #include @@ -146,8 +148,16 @@ qApp->inputMethod()->update(Qt::ImQueryAll); } ); - // TODO: calculate overlap - t->setInputPanelState(m_inputWindow->isVisible(), QRect(0, 0, 0, 0)); + + disconnect(m_trackedClient.data(), nullptr, this, nullptr); + m_trackedClient = waylandServer()->findAbstractClient(waylandServer()->seat()->focusedTextInputSurface()); + + + if (m_trackedClient) { + connect(m_trackedClient.data(), &AbstractClient::geometryChanged, this, &VirtualKeyboard::updateInputPanelState); + } + + updateInputPanelState(); } else { m_waylandShowConnection = QMetaObject::Connection(); m_waylandHideConnection = QMetaObject::Connection(); @@ -176,20 +186,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 +226,47 @@ } } +void VirtualKeyboard::updateInputPanelState() +{ + const bool inputPanelHasBeenOpened = !m_inputWindow->isVisible() && qApp->inputMethod()->isVisible(); + const bool inputPanelHasBeenClosed = m_inputWindow->isVisible() && !qApp->inputMethod()->isVisible(); + + 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()) { + if (m_inputWindow->isVisible() && m_trackedClient && m_inputWindow->rootObject()) { + + + const QRect inputPanelGeom = m_inputWindow->rootObject()->childrenRect().toRect().translated(m_inputWindow->geometry().topLeft()); + + if (inputPanelHasBeenOpened) { + m_trackedClient->setGeometryRestore(m_trackedClient->geometry()); + } else if (inputPanelHasBeenClosed && !m_trackedClient->geometryRestore().isNull()) { + m_trackedClient->setGeometry(m_trackedClient->geometryRestore()); + } + if (!inputPanelHasBeenClosed) { + QRect screenArea = workspace()->clientArea(ScreenArea, m_trackedClient); + screenArea.setBottom(screenArea.bottom() - inputPanelGeom.height()); + + QRect newGeom = m_trackedClient->geometry(); + newGeom.moveBottom(qMin(newGeom.bottom(), inputPanelGeom.top())); + newGeom.setTop(qMax(screenArea.top(), newGeom.top())); + m_trackedClient->setGeometry(newGeom); + } + + t->setInputPanelState(true, QRect(0, 0, 0, 0)); + } else { + t->setInputPanelState(false, QRect(0, 0, 0, 0)); + } + } + } +} + void VirtualKeyboard::show() { if (m_inputWindow.isNull() || !m_enabled) {