InputMethod: only activate virtual keyboard when used with touch

This commit is contained in:
Xaver Hugl 2021-10-13 13:14:21 +02:00 committed by Aleix Pol Gonzalez
parent f1e99e971f
commit 5b9deafa14
8 changed files with 35 additions and 0 deletions

View file

@ -2950,6 +2950,11 @@ QWindow *InputDeviceHandler::internalWindow() const
return m_focus.internalWindow;
}
uint32_t InputDeviceHandler::lastEventTime() const
{
return m_lastEventTime;
}
} // namespace
#include "input.moc"

View file

@ -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();

View file

@ -18,6 +18,8 @@
#include "workspace.h"
#include "screenlockerwatcher.h"
#include "deleted.h"
#include "touch_input.h"
#include "pointer_input.h"
#include <KWaylandServer/display.h>
#include <KWaylandServer/keyboard_interface.h>
@ -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();

View file

@ -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();

View file

@ -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;
};
}

View file

@ -249,6 +249,7 @@ QVector<PositionUpdateBlocker::ScheduledPosition> 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;

View file

@ -53,6 +53,7 @@ void TabletInputRedirection::tabletToolEvent(KWin::InputRedirection::TabletEvent
if (!inited()) {
return;
}
m_lastEventTime = time;
m_lastPosition = pos;
QEvent::Type t;

View file

@ -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));