From 93305f6041c7e522bb05bdee0f11ba0d4534218f Mon Sep 17 00:00:00 2001 From: Julius Zint Date: Thu, 10 Mar 2022 11:15:26 +0100 Subject: [PATCH] Add all required input simulation methods [4/6] Make autotests create fake input devices This translates all required input simulating methods from kwinApp()->platform()->... to seperate functions in the Test namespace. --- autotests/integration/kwin_wayland_test.h | 14 +++++ autotests/integration/test_helpers.cpp | 74 +++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/autotests/integration/kwin_wayland_test.h b/autotests/integration/kwin_wayland_test.h index 3fc7206d25..db3303003e 100644 --- a/autotests/integration/kwin_wayland_test.h +++ b/autotests/integration/kwin_wayland_test.h @@ -516,6 +516,20 @@ private: bool m_touch = false; }; +void keyboardKeyPressed(quint32 key, quint32 time); +void keyboardKeyReleased(quint32 key, quint32 time); +void pointerAxisHorizontal(qreal delta, quint32 time, qint32 discreteDelta = 0, + InputRedirection::PointerAxisSource source = InputRedirection::PointerAxisSourceUnknown); +void pointerAxisVertical(qreal delta, quint32 time, qint32 discreteDelta = 0, + InputRedirection::PointerAxisSource source = InputRedirection::PointerAxisSourceUnknown); +void pointerButtonPressed(quint32 button, quint32 time); +void pointerButtonReleased(quint32 button, quint32 time); +void pointerMotion(const QPointF &position, quint32 time); +void touchCancel(); +void touchDown(qint32 id, const QPointF &pos, quint32 time); +void touchMotion(qint32 id, const QPointF &pos, quint32 time); +void touchUp(qint32 id, quint32 time); + /** * Creates a Wayland Connection in a dedicated thread and creates various * client side objects which can be used to create windows. diff --git a/autotests/integration/test_helpers.cpp b/autotests/integration/test_helpers.cpp index 5ac4527bcb..fdc5e2f0ba 100644 --- a/autotests/integration/test_helpers.cpp +++ b/autotests/integration/test_helpers.cpp @@ -1371,5 +1371,79 @@ bool VirtualInputDevice::isLidSwitch() const { return false; } + +void keyboardKeyPressed(quint32 key, quint32 time) +{ + auto virtualKeyboard = static_cast(kwinApp())->virtualKeyboard(); + Q_EMIT virtualKeyboard->keyChanged(key, InputRedirection::KeyboardKeyState::KeyboardKeyPressed, time, virtualKeyboard); +} + +void keyboardKeyReleased(quint32 key, quint32 time) +{ + auto virtualKeyboard = static_cast(kwinApp())->virtualKeyboard(); + Q_EMIT virtualKeyboard->keyChanged(key, InputRedirection::KeyboardKeyState::KeyboardKeyReleased, time, virtualKeyboard); +} + +void pointerAxisHorizontal(qreal delta, quint32 time, qint32 discreteDelta, + InputRedirection::PointerAxisSource source) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerAxisChanged(InputRedirection::PointerAxis::PointerAxisHorizontal, + delta, discreteDelta, source, time, virtualPointer); +} + +void pointerAxisVertical(qreal delta, quint32 time, qint32 discreteDelta, + InputRedirection::PointerAxisSource source) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerAxisChanged(InputRedirection::PointerAxis::PointerAxisVertical, + delta, discreteDelta, source, time, virtualPointer); +} + +void pointerButtonPressed(quint32 button, quint32 time) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerButtonChanged(button, + InputRedirection::PointerButtonState::PointerButtonPressed, + time, virtualPointer); +} + +void pointerButtonReleased(quint32 button, quint32 time) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerButtonChanged(button, + InputRedirection::PointerButtonState::PointerButtonReleased, + time, virtualPointer); +} + +void pointerMotion(const QPointF &position, quint32 time) +{ + auto virtualPointer = static_cast(kwinApp())->virtualPointer(); + Q_EMIT virtualPointer->pointerMotionAbsolute(position, time, virtualPointer); +} + +void touchCancel() +{ + auto virtualTouch = static_cast(kwinApp())->virtualTouch(); + Q_EMIT virtualTouch->touchCanceled(virtualTouch); +} + +void touchDown(qint32 id, const QPointF &pos, quint32 time) +{ + auto virtualTouch = static_cast(kwinApp())->virtualTouch(); + Q_EMIT virtualTouch->touchDown(id, pos, time, virtualTouch); +} + +void touchMotion(qint32 id, const QPointF &pos, quint32 time) +{ + auto virtualTouch = static_cast(kwinApp())->virtualTouch(); + Q_EMIT virtualTouch->touchMotion(id, pos, time, virtualTouch); +} + +void touchUp(qint32 id, quint32 time) +{ + auto virtualTouch = static_cast(kwinApp())->virtualTouch(); + Q_EMIT virtualTouch->touchUp(id, time, virtualTouch); +} } }