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,6 +30,7 @@ #include #include #include +#include #include #include @@ -112,6 +113,17 @@ connect(dbus, &VirtualKeyboardDBus::activateRequested, this, &VirtualKeyboard::setEnabled); connect(this, &VirtualKeyboard::enabledChanged, dbus, &VirtualKeyboardDBus::setEnabled); + m_trackedClient = Workspace::self()->activeClient(); + connect(Workspace::self(), &Workspace::clientActivated, this, + [this] { + disconnect(m_trackedClient, 0, this, 0); + m_trackedClient = Workspace::self()->activeClient(); + if (m_trackedClient) { + connect(m_trackedClient.data(), &AbstractClient::geometryChanged, this, &VirtualKeyboard::updateInputPanelState); + } + } + ); + if (waylandServer()) { // we can announce support for the text input interface auto t = waylandServer()->display()->createTextInputManager(TextInputInterfaceVersion::UnstableV0, waylandServer()->display()); @@ -146,8 +158,7 @@ qApp->inputMethod()->update(Qt::ImQueryAll); } ); - // TODO: calculate overlap - t->setInputPanelState(m_inputWindow->isVisible(), QRect(0, 0, 0, 0)); + updateInputPanelState(); } else { m_waylandShowConnection = QMetaObject::Connection(); m_waylandHideConnection = QMetaObject::Connection(); @@ -176,20 +187,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 +232,26 @@ } } +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() && Workspace::self()->activeClient() && m_inputWindow->rootObject()) { + const QRect activeWindowGeom = Workspace::self()->activeClient()->geometry(); + const QRect inputPanelGeom = m_inputWindow->rootObject()->childrenRect().toRect().translated(m_inputWindow->geometry().topLeft()); + + t->setInputPanelState(true, activeWindowGeom.intersected(inputPanelGeom)); + } else { + t->setInputPanelState(false, QRect(0, 0, 0, 0)); + } + } + } +} + void VirtualKeyboard::show() { if (m_inputWindow.isNull() || !m_enabled) {