2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-05-31 07:23:12 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-05-31 07:23:12 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-05-31 07:23:12 +00:00
|
|
|
#include "mock_libinput.h"
|
2021-02-09 18:18:36 +00:00
|
|
|
|
2021-10-27 09:13:09 +00:00
|
|
|
#include "backends/libinput/device.h"
|
|
|
|
#include "backends/libinput/events.h"
|
2016-05-31 07:23:12 +00:00
|
|
|
|
2018-06-05 10:52:57 +00:00
|
|
|
#include <QtTest>
|
2016-05-31 07:23:12 +00:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(libinput_event_type)
|
|
|
|
Q_DECLARE_METATYPE(libinput_button_state)
|
|
|
|
|
|
|
|
using namespace KWin::LibInput;
|
|
|
|
|
|
|
|
class TestLibinputPointerEvent : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
|
|
|
void testType_data();
|
|
|
|
void testType();
|
|
|
|
void testButton_data();
|
|
|
|
void testButton();
|
2022-10-11 10:33:04 +00:00
|
|
|
void testScrollWheel_data();
|
|
|
|
void testScrollWheel();
|
|
|
|
void testScrollFinger_data();
|
|
|
|
void testScrollFinger();
|
|
|
|
void testScrollContinuous_data();
|
|
|
|
void testScrollContinuous();
|
2016-05-31 07:23:12 +00:00
|
|
|
void testMotion();
|
|
|
|
void testAbsoluteMotion();
|
|
|
|
|
|
|
|
private:
|
|
|
|
libinput_device *m_nativeDevice = nullptr;
|
|
|
|
Device *m_device = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::init()
|
|
|
|
{
|
|
|
|
m_nativeDevice = new libinput_device;
|
|
|
|
m_nativeDevice->pointer = true;
|
|
|
|
m_nativeDevice->deviceSize = QSizeF(12.5, 13.8);
|
|
|
|
m_device = new Device(m_nativeDevice);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::cleanup()
|
|
|
|
{
|
|
|
|
delete m_device;
|
|
|
|
m_device = nullptr;
|
|
|
|
|
|
|
|
delete m_nativeDevice;
|
|
|
|
m_nativeDevice = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testType_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<libinput_event_type>("type");
|
|
|
|
|
|
|
|
QTest::newRow("motion") << LIBINPUT_EVENT_POINTER_MOTION;
|
|
|
|
QTest::newRow("absolute motion") << LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE;
|
|
|
|
QTest::newRow("button") << LIBINPUT_EVENT_POINTER_BUTTON;
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::newRow("scroll wheel") << LIBINPUT_EVENT_POINTER_SCROLL_WHEEL;
|
|
|
|
QTest::newRow("scroll finger") << LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
|
|
|
|
QTest::newRow("scroll continuous") << LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS;
|
2016-05-31 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testType()
|
|
|
|
{
|
|
|
|
// this test verifies the initialization of a PointerEvent and the parent Event class
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
QFETCH(libinput_event_type, type);
|
|
|
|
pointerEvent->type = type;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
|
2022-06-01 10:13:34 +00:00
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
2016-05-31 07:23:12 +00:00
|
|
|
// API of event
|
|
|
|
QCOMPARE(event->type(), type);
|
|
|
|
QCOMPARE(event->device(), m_device);
|
|
|
|
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
2022-06-01 10:13:34 +00:00
|
|
|
QCOMPARE((libinput_event *)(*event.get()), pointerEvent);
|
2016-05-31 07:23:12 +00:00
|
|
|
// verify it's a pointer event
|
2022-06-01 10:13:34 +00:00
|
|
|
QVERIFY(dynamic_cast<PointerEvent *>(event.get()));
|
|
|
|
QCOMPARE((libinput_event_pointer *)(*dynamic_cast<PointerEvent *>(event.get())), pointerEvent);
|
2016-05-31 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testButton_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<libinput_button_state>("buttonState");
|
|
|
|
QTest::addColumn<KWin::InputRedirection::PointerButtonState>("expectedButtonState");
|
|
|
|
QTest::addColumn<quint32>("button");
|
|
|
|
QTest::addColumn<quint32>("time");
|
|
|
|
|
|
|
|
QTest::newRow("pressed") << LIBINPUT_BUTTON_STATE_RELEASED << KWin::InputRedirection::PointerButtonReleased << quint32(BTN_RIGHT) << 100u;
|
|
|
|
QTest::newRow("released") << LIBINPUT_BUTTON_STATE_PRESSED << KWin::InputRedirection::PointerButtonPressed << quint32(BTN_LEFT) << 200u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testButton()
|
|
|
|
{
|
|
|
|
// this test verifies the button press/release
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_BUTTON;
|
|
|
|
QFETCH(libinput_button_state, buttonState);
|
|
|
|
pointerEvent->buttonState = buttonState;
|
|
|
|
QFETCH(quint32, button);
|
|
|
|
pointerEvent->button = button;
|
|
|
|
QFETCH(quint32, time);
|
|
|
|
pointerEvent->time = time;
|
|
|
|
|
2022-06-01 10:13:34 +00:00
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
2016-05-31 07:23:12 +00:00
|
|
|
QVERIFY(pe);
|
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_BUTTON);
|
|
|
|
QTEST(pe->buttonState(), "expectedButtonState");
|
|
|
|
QCOMPARE(pe->button(), button);
|
|
|
|
QCOMPARE(pe->time(), time);
|
2016-10-07 12:47:25 +00:00
|
|
|
QCOMPARE(pe->timeMicroseconds(), quint64(time * 1000));
|
2016-05-31 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 10:33:04 +00:00
|
|
|
void TestLibinputPointerEvent::testScrollWheel_data()
|
2016-05-31 07:23:12 +00:00
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("horizontal");
|
|
|
|
QTest::addColumn<bool>("vertical");
|
|
|
|
QTest::addColumn<QPointF>("value");
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::addColumn<QPoint>("valueV120");
|
2016-05-31 07:23:12 +00:00
|
|
|
QTest::addColumn<quint32>("time");
|
|
|
|
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::newRow("wheel/horizontal") << true << false << QPointF(3.0, 0.0) << QPoint(120, 0) << 100u;
|
|
|
|
QTest::newRow("wheel/vertical") << false << true << QPointF(0.0, 2.5) << QPoint(0, 120) << 200u;
|
|
|
|
QTest::newRow("wheel/both") << true << true << QPointF(1.1, 4.2) << QPoint(120, 120) << 300u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testScrollWheel()
|
|
|
|
{
|
|
|
|
// this test verifies pointer axis functionality
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_SCROLL_WHEEL;
|
|
|
|
QFETCH(bool, horizontal);
|
|
|
|
QFETCH(bool, vertical);
|
|
|
|
QFETCH(QPointF, value);
|
|
|
|
QFETCH(QPoint, valueV120);
|
|
|
|
QFETCH(quint32, time);
|
|
|
|
pointerEvent->horizontalAxis = horizontal;
|
|
|
|
pointerEvent->verticalAxis = vertical;
|
|
|
|
pointerEvent->horizontalScrollValue = value.x();
|
|
|
|
pointerEvent->verticalScrollValue = value.y();
|
|
|
|
pointerEvent->horizontalScrollValueV120 = valueV120.x();
|
|
|
|
pointerEvent->verticalScrollValueV120 = valueV120.y();
|
|
|
|
pointerEvent->time = time;
|
|
|
|
|
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
|
|
|
QVERIFY(pe);
|
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_WHEEL);
|
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal);
|
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisVertical), vertical);
|
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisHorizontal), value.x());
|
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisVertical), value.y());
|
|
|
|
QCOMPARE(pe->scrollValueV120(KWin::InputRedirection::PointerAxisHorizontal), valueV120.x());
|
|
|
|
QCOMPARE(pe->scrollValueV120(KWin::InputRedirection::PointerAxisVertical), valueV120.y());
|
|
|
|
QCOMPARE(pe->time(), time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testScrollFinger_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("horizontal");
|
|
|
|
QTest::addColumn<bool>("vertical");
|
|
|
|
QTest::addColumn<QPointF>("value");
|
|
|
|
QTest::addColumn<quint32>("time");
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::newRow("finger/horizontal") << true << false << QPointF(3.0, 0.0) << 400u;
|
|
|
|
QTest::newRow("stop finger/horizontal") << true << false << QPointF(0.0, 0.0) << 500u;
|
|
|
|
QTest::newRow("finger/vertical") << false << true << QPointF(0.0, 2.5) << 600u;
|
|
|
|
QTest::newRow("stop finger/vertical") << false << true << QPointF(0.0, 0.0) << 700u;
|
|
|
|
QTest::newRow("finger/both") << true << true << QPointF(1.1, 4.2) << 800u;
|
|
|
|
QTest::newRow("stop finger/both") << true << true << QPointF(0.0, 0.0) << 900u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testScrollFinger()
|
|
|
|
{
|
|
|
|
// this test verifies pointer axis functionality
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_SCROLL_FINGER;
|
|
|
|
QFETCH(bool, horizontal);
|
|
|
|
QFETCH(bool, vertical);
|
|
|
|
QFETCH(QPointF, value);
|
|
|
|
QFETCH(quint32, time);
|
|
|
|
pointerEvent->horizontalAxis = horizontal;
|
|
|
|
pointerEvent->verticalAxis = vertical;
|
|
|
|
pointerEvent->horizontalScrollValue = value.x();
|
|
|
|
pointerEvent->verticalScrollValue = value.y();
|
|
|
|
pointerEvent->time = time;
|
|
|
|
|
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
|
|
|
QVERIFY(pe);
|
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
|
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal);
|
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisVertical), vertical);
|
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisHorizontal), value.x());
|
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisVertical), value.y());
|
|
|
|
QCOMPARE(pe->time(), time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testScrollContinuous_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<bool>("horizontal");
|
|
|
|
QTest::addColumn<bool>("vertical");
|
|
|
|
QTest::addColumn<QPointF>("value");
|
|
|
|
QTest::addColumn<quint32>("time");
|
Send axis_source, axis_discrete, and axis_stop
Summary:
So far KWin didn't send axis_source, axis_discrete, and axis_stop. Even
though most of those events are optional, clients need them to work as
expected. For example, one needs axis_source and axis_stop to implement
kinetic scrolling; Xwayland needs axis_discrete to prevent multiple
scroll events when the compositor sends axis deltas greater than 10, etc.
BUG: 404152
FIXED-IN: 5.17.0
Test Plan:
* Content of a webpage in Firefox is moved by one line per each mouse
wheel "click";
* Scrolled gedit using 2 fingers on GNOME Shell, sway, and KDE Plasma;
in all three cases wayland debug looked the same (except diagonal scroll
motions).
Reviewers: #kwin, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: davidedmundson, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D19000
2019-02-12 09:14:51 +00:00
|
|
|
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::newRow("continuous/horizontal") << true << false << QPointF(3.0, 0.0) << 1000u;
|
|
|
|
QTest::newRow("continuous/vertical") << false << true << QPointF(0.0, 2.5) << 1100u;
|
|
|
|
QTest::newRow("continuous/both") << true << true << QPointF(1.1, 4.2) << 1200u;
|
2016-05-31 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
2022-10-11 10:33:04 +00:00
|
|
|
void TestLibinputPointerEvent::testScrollContinuous()
|
2016-05-31 07:23:12 +00:00
|
|
|
{
|
|
|
|
// this test verifies pointer axis functionality
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
2022-10-11 10:33:04 +00:00
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS;
|
2016-05-31 07:23:12 +00:00
|
|
|
QFETCH(bool, horizontal);
|
|
|
|
QFETCH(bool, vertical);
|
|
|
|
QFETCH(QPointF, value);
|
|
|
|
QFETCH(quint32, time);
|
|
|
|
pointerEvent->horizontalAxis = horizontal;
|
|
|
|
pointerEvent->verticalAxis = vertical;
|
2022-10-11 10:33:04 +00:00
|
|
|
pointerEvent->horizontalScrollValue = value.x();
|
|
|
|
pointerEvent->verticalScrollValue = value.y();
|
2016-05-31 07:23:12 +00:00
|
|
|
pointerEvent->time = time;
|
|
|
|
|
2022-06-01 10:13:34 +00:00
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
2016-05-31 07:23:12 +00:00
|
|
|
QVERIFY(pe);
|
2022-10-11 10:33:04 +00:00
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS);
|
2016-05-31 07:23:12 +00:00
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisHorizontal), horizontal);
|
|
|
|
QCOMPARE(pe->axis().contains(KWin::InputRedirection::PointerAxisVertical), vertical);
|
2022-10-11 10:33:04 +00:00
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisHorizontal), value.x());
|
|
|
|
QCOMPARE(pe->scrollValue(KWin::InputRedirection::PointerAxisVertical), value.y());
|
2016-05-31 07:23:12 +00:00
|
|
|
QCOMPARE(pe->time(), time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testMotion()
|
|
|
|
{
|
|
|
|
// this test verifies pointer motion (delta)
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_MOTION;
|
2022-10-25 08:18:45 +00:00
|
|
|
pointerEvent->delta = QPointF(2.1, 4.5);
|
2016-05-31 07:23:12 +00:00
|
|
|
pointerEvent->time = 500u;
|
|
|
|
|
2022-06-01 10:13:34 +00:00
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
2016-05-31 07:23:12 +00:00
|
|
|
QVERIFY(pe);
|
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION);
|
|
|
|
QCOMPARE(pe->time(), 500u);
|
2022-10-25 08:18:45 +00:00
|
|
|
QCOMPARE(pe->delta(), QPointF(2.1, 4.5));
|
2016-05-31 07:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TestLibinputPointerEvent::testAbsoluteMotion()
|
|
|
|
{
|
|
|
|
// this test verifies absolute pointer motion
|
|
|
|
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
|
|
|
pointerEvent->device = m_nativeDevice;
|
|
|
|
pointerEvent->type = LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE;
|
|
|
|
pointerEvent->absolutePos = QPointF(6.25, 6.9);
|
|
|
|
pointerEvent->time = 500u;
|
|
|
|
|
2022-06-01 10:13:34 +00:00
|
|
|
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
|
|
|
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
2016-05-31 07:23:12 +00:00
|
|
|
QVERIFY(pe);
|
|
|
|
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
|
|
|
|
QCOMPARE(pe->time(), 500u);
|
|
|
|
QCOMPARE(pe->absolutePos(), QPointF(6.25, 6.9));
|
|
|
|
QCOMPARE(pe->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
|
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(TestLibinputPointerEvent)
|
|
|
|
#include "pointer_event_test.moc"
|