diff --git a/virtualkeyboard.h b/virtualkeyboard.h --- a/virtualkeyboard.h +++ b/virtualkeyboard.h @@ -25,6 +25,8 @@ #include #include +#include + class QQuickView; class QWindow; class KStatusNotifierItem; @@ -53,10 +55,12 @@ 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 @@ -30,10 +30,13 @@ #include #include #include +#include #include #include +#include + #include #include #include @@ -146,8 +149,15 @@ 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,15 @@ 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)); - } - } - } - ); + + //TODO: move to method + auto adjustInputWindow = [this] { + + }; + + connect(qApp->inputMethod(), &QInputMethod::visibleChanged, this, &VirtualKeyboard::updateInputPanelState); + + connect(m_inputWindow->rootObject(), &QQuickItem::childrenRectChanged, this, &VirtualKeyboard::updateInputPanelState); } void VirtualKeyboard::setEnabled(bool enabled) @@ -226,6 +231,31 @@ } } +void VirtualKeyboard::updateInputPanelState() +{ + 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()) { + QRect activeWindowGeom = m_trackedClient->geometry(); + const QRect inputPanelGeom = m_inputWindow->rootObject()->childrenRect().toRect().translated(m_inputWindow->geometry().topLeft()); + + auto *dec = m_trackedClient->decoration(); + if (dec) { + activeWindowGeom.adjust(dec->borderLeft(), dec->borderTop(), -dec->borderRight(), -dec->borderBottom()); + } + + t->setInputPanelState(true, activeWindowGeom.intersected(inputPanelGeom)); + } else { + t->setInputPanelState(false, QRect(0, 0, 0, 0)); + } + } + } +} + void VirtualKeyboard::show() { if (m_inputWindow.isNull() || !m_enabled) {