From 5b9deafa14b2b375f0c10008a2195df5c0cca79b Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 13 Oct 2021 13:14:21 +0200 Subject: [PATCH] InputMethod: only activate virtual keyboard when used with touch --- src/input.cpp | 5 +++++ src/input.h | 4 ++++ src/inputmethod.cpp | 5 +++++ src/keyboard_input.cpp | 1 + src/keyboard_input.h | 5 +++++ src/pointer_input.cpp | 11 +++++++++++ src/tablet_input.cpp | 1 + src/touch_input.cpp | 3 +++ 8 files changed, 35 insertions(+) diff --git a/src/input.cpp b/src/input.cpp index 87d9751952..82d45cd3f4 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -2950,6 +2950,11 @@ QWindow *InputDeviceHandler::internalWindow() const return m_focus.internalWindow; } +uint32_t InputDeviceHandler::lastEventTime() const +{ + return m_lastEventTime; +} + } // namespace #include "input.moc" diff --git a/src/input.h b/src/input.h index faf872fd67..2ef0b841f9 100644 --- a/src/input.h +++ b/src/input.h @@ -462,6 +462,8 @@ public: void setDecoration(Decoration::DecoratedClientImpl *decoration); void setInternalWindow(QWindow *window); + uint32_t lastEventTime() const; + Q_SIGNALS: void atChanged(Toplevel *old, Toplevel *now); void decorationChanged(); @@ -493,6 +495,8 @@ protected: m_inited = set; } + uint32_t m_lastEventTime = 0; + private: bool setAt(Toplevel *toplevel); void updateFocus(); diff --git a/src/inputmethod.cpp b/src/inputmethod.cpp index cba809d3a6..5e2e62c1d2 100644 --- a/src/inputmethod.cpp +++ b/src/inputmethod.cpp @@ -18,6 +18,8 @@ #include "workspace.h" #include "screenlockerwatcher.h" #include "deleted.h" +#include "touch_input.h" +#include "pointer_input.h" #include #include @@ -118,6 +120,9 @@ void InputMethod::hide() void InputMethod::setActive(bool active) { + active &= input()->touch() + && input()->touch()->lastEventTime() > input()->keyboard()->lastEventTime() + && input()->touch()->lastEventTime() > input()->pointer()->lastEventTime(); const bool wasActive = waylandServer()->inputMethod()->context(); if (wasActive && !active) { waylandServer()->inputMethod()->sendDeactivate(); diff --git a/src/keyboard_input.cpp b/src/keyboard_input.cpp index b195d24b35..77dff95e5d 100644 --- a/src/keyboard_input.cpp +++ b/src/keyboard_input.cpp @@ -218,6 +218,7 @@ void KeyboardInputRedirection::processKey(uint32_t key, InputRedirection::Keyboa if (!m_inited) { return; } + m_lastEventTime = time; m_input->processFilters(std::bind(&InputEventFilter::keyEvent, std::placeholders::_1, &event)); m_xkb->forwardModifiers(); diff --git a/src/keyboard_input.h b/src/keyboard_input.h index b439760a32..43f1e19176 100644 --- a/src/keyboard_input.h +++ b/src/keyboard_input.h @@ -76,6 +76,10 @@ public: return m_xkb->modifiersRelevantForGlobalShortcuts(); } + uint32_t lastEventTime() const { + return m_lastEventTime; + } + Q_SIGNALS: void ledsChanged(KWin::LEDs); @@ -86,6 +90,7 @@ private: QMetaObject::Connection m_activeClientSurfaceChangedConnection; ModifiersChangedSpy *m_modifiersChangedSpy = nullptr; KeyboardLayout *m_keyboardLayout = nullptr; + uint32_t m_lastEventTime = 0; }; } diff --git a/src/pointer_input.cpp b/src/pointer_input.cpp index 5e361f92e9..813acaaed4 100644 --- a/src/pointer_input.cpp +++ b/src/pointer_input.cpp @@ -249,6 +249,7 @@ QVector PositionUpdateBlocker::s_sched void PointerInputRedirection::processMotion(const QPointF &pos, const QSizeF &delta, const QSizeF &deltaNonAccelerated, uint32_t time, quint64 timeUsec, LibInput::Device *device) { + m_lastEventTime = time; if (!inited()) { return; } @@ -271,6 +272,7 @@ void PointerInputRedirection::processMotion(const QPointF &pos, const QSizeF &de void PointerInputRedirection::processButton(uint32_t button, InputRedirection::PointerButtonState state, uint32_t time, LibInput::Device *device) { + m_lastEventTime = time; QEvent::Type type; switch (state) { case InputRedirection::PointerButtonReleased: @@ -308,6 +310,7 @@ void PointerInputRedirection::processButton(uint32_t button, InputRedirection::P void PointerInputRedirection::processAxis(InputRedirection::PointerAxis axis, qreal delta, qint32 discreteDelta, InputRedirection::PointerAxisSource source, uint32_t time, LibInput::Device *device) { + m_lastEventTime = time; update(); Q_EMIT input()->pointerAxisChanged(axis, delta); @@ -327,6 +330,7 @@ void PointerInputRedirection::processAxis(InputRedirection::PointerAxis axis, qr void PointerInputRedirection::processSwipeGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -338,6 +342,7 @@ void PointerInputRedirection::processSwipeGestureBegin(int fingerCount, quint32 void PointerInputRedirection::processSwipeGestureUpdate(const QSizeF &delta, quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -350,6 +355,7 @@ void PointerInputRedirection::processSwipeGestureUpdate(const QSizeF &delta, qui void PointerInputRedirection::processSwipeGestureEnd(quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -362,6 +368,7 @@ void PointerInputRedirection::processSwipeGestureEnd(quint32 time, KWin::LibInpu void PointerInputRedirection::processSwipeGestureCancelled(quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -374,6 +381,7 @@ void PointerInputRedirection::processSwipeGestureCancelled(quint32 time, KWin::L void PointerInputRedirection::processPinchGestureBegin(int fingerCount, quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -386,6 +394,7 @@ void PointerInputRedirection::processPinchGestureBegin(int fingerCount, quint32 void PointerInputRedirection::processPinchGestureUpdate(qreal scale, qreal angleDelta, const QSizeF &delta, quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -398,6 +407,7 @@ void PointerInputRedirection::processPinchGestureUpdate(qreal scale, qreal angle void PointerInputRedirection::processPinchGestureEnd(quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; @@ -410,6 +420,7 @@ void PointerInputRedirection::processPinchGestureEnd(quint32 time, KWin::LibInpu void PointerInputRedirection::processPinchGestureCancelled(quint32 time, KWin::LibInput::Device *device) { + m_lastEventTime = time; Q_UNUSED(device) if (!inited()) { return; diff --git a/src/tablet_input.cpp b/src/tablet_input.cpp index d6569bdfc6..5f3d66e4f3 100644 --- a/src/tablet_input.cpp +++ b/src/tablet_input.cpp @@ -53,6 +53,7 @@ void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEvent if (!inited()) { return; } + m_lastEventTime = time; m_lastPosition = pos; QEvent::Type t; diff --git a/src/touch_input.cpp b/src/touch_input.cpp index 6c676b3a33..36af3d57af 100644 --- a/src/touch_input.cpp +++ b/src/touch_input.cpp @@ -147,6 +147,7 @@ void TouchInputRedirection::processDown(qint32 id, const QPointF &pos, quint32 t if (m_activeTouchPoints.count() == 1) { update(); } + m_lastEventTime = time; input()->processSpies(std::bind(&InputEventSpy::touchDown, std::placeholders::_1, id, pos, time)); input()->processFilters(std::bind(&InputEventFilter::touchDown, std::placeholders::_1, id, pos, time)); m_windowUpdatedInCycle = false; @@ -161,6 +162,7 @@ void TouchInputRedirection::processUp(qint32 id, quint32 time, LibInput::Device if (!m_activeTouchPoints.remove(id)) { return; } + m_lastEventTime = time; m_windowUpdatedInCycle = false; input()->processSpies(std::bind(&InputEventSpy::touchUp, std::placeholders::_1, id, time)); input()->processFilters(std::bind(&InputEventFilter::touchUp, std::placeholders::_1, id, time)); @@ -179,6 +181,7 @@ void TouchInputRedirection::processMotion(qint32 id, const QPointF &pos, quint32 if (!m_activeTouchPoints.contains(id)) { return; } + m_lastEventTime = time; m_lastPosition = pos; m_windowUpdatedInCycle = false; input()->processSpies(std::bind(&InputEventSpy::touchMotion, std::placeholders::_1, id, pos, time));