2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-05-24 08:57:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-05-24 08:57:57 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-05-24 08:57:57 +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"
|
2021-02-09 18:18:36 +00:00
|
|
|
#include "input_event.h"
|
2016-05-24 08:57:57 +00:00
|
|
|
|
2023-07-03 19:28:19 +00:00
|
|
|
#include <QTest>
|
2016-05-24 08:57:57 +00:00
|
|
|
|
2017-12-27 19:25:36 +00:00
|
|
|
Q_DECLARE_METATYPE(KWin::SwitchEvent::State);
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWin::LibInput;
|
2022-12-21 00:55:20 +00:00
|
|
|
using namespace std::literals;
|
2016-05-24 08:57:57 +00:00
|
|
|
|
|
|
|
class InputEventsTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void testInitMouseEvent_data();
|
|
|
|
void testInitMouseEvent();
|
|
|
|
void testInitKeyEvent_data();
|
|
|
|
void testInitKeyEvent();
|
|
|
|
void testInitWheelEvent_data();
|
|
|
|
void testInitWheelEvent();
|
2017-12-27 19:25:36 +00:00
|
|
|
void testInitSwitchEvent_data();
|
|
|
|
void testInitSwitchEvent();
|
2016-05-24 08:57:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void InputEventsTest::testInitMouseEvent_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QEvent::Type>("type");
|
|
|
|
|
|
|
|
QTest::newRow("Press") << QEvent::MouseButtonPress;
|
|
|
|
QTest::newRow("Release") << QEvent::MouseButtonRelease;
|
|
|
|
QTest::newRow("Move") << QEvent::MouseMove;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitMouseEvent()
|
|
|
|
{
|
|
|
|
// this test verifies that a MouseEvent is constructed correctly
|
|
|
|
|
|
|
|
// first create the test LibInput::Device
|
|
|
|
libinput_device device;
|
|
|
|
Device d(&device);
|
|
|
|
|
|
|
|
QFETCH(QEvent::Type, type);
|
|
|
|
// now create our own event
|
|
|
|
MouseEvent event(type, QPointF(100, 200), Qt::LeftButton, Qt::LeftButton | Qt::RightButton,
|
2024-03-12 22:01:41 +00:00
|
|
|
Qt::ShiftModifier | Qt::ControlModifier, 300ms, QPointF(1, 2), QPointF(3, 4), &d, false);
|
2016-05-24 08:57:57 +00:00
|
|
|
// and verify the contract of QMouseEvent
|
|
|
|
QCOMPARE(event.type(), type);
|
|
|
|
QCOMPARE(event.globalPos(), QPoint(100, 200));
|
|
|
|
QCOMPARE(event.screenPos(), QPointF(100, 200));
|
|
|
|
QCOMPARE(event.localPos(), QPointF(100, 200));
|
|
|
|
QCOMPARE(event.button(), Qt::LeftButton);
|
|
|
|
QCOMPARE(event.buttons(), Qt::LeftButton | Qt::RightButton);
|
|
|
|
QCOMPARE(event.modifiers(), Qt::ShiftModifier | Qt::ControlModifier);
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(event.timestamp(), 300ms);
|
2016-05-24 08:57:57 +00:00
|
|
|
// and our custom argument
|
|
|
|
QCOMPARE(event.device(), &d);
|
2022-10-25 08:18:45 +00:00
|
|
|
QCOMPARE(event.delta(), QPointF(1, 2));
|
|
|
|
QCOMPARE(event.deltaUnaccelerated(), QPointF(3, 4));
|
2016-05-24 08:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitKeyEvent_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QEvent::Type>("type");
|
|
|
|
QTest::addColumn<bool>("autorepeat");
|
|
|
|
|
|
|
|
QTest::newRow("Press") << QEvent::KeyPress << false;
|
|
|
|
QTest::newRow("Repeat") << QEvent::KeyPress << true;
|
|
|
|
QTest::newRow("Release") << QEvent::KeyRelease << false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitKeyEvent()
|
|
|
|
{
|
|
|
|
// this test verifies that a KeyEvent is constructed correctly
|
|
|
|
|
|
|
|
// first create the test LibInput::Device
|
|
|
|
libinput_device device;
|
|
|
|
Device d(&device);
|
|
|
|
|
|
|
|
// setup event
|
|
|
|
QFETCH(QEvent::Type, type);
|
|
|
|
QFETCH(bool, autorepeat);
|
|
|
|
KeyEvent event(type, Qt::Key_Space, Qt::ShiftModifier | Qt::ControlModifier, 200, 300,
|
2022-12-21 00:55:20 +00:00
|
|
|
QStringLiteral(" "), autorepeat, 400ms, &d);
|
2016-05-24 08:57:57 +00:00
|
|
|
// and verify the contract of QKeyEvent
|
|
|
|
QCOMPARE(event.type(), type);
|
|
|
|
QCOMPARE(event.isAutoRepeat(), autorepeat);
|
|
|
|
QCOMPARE(event.key(), int(Qt::Key_Space));
|
|
|
|
QCOMPARE(event.nativeScanCode(), 200u);
|
|
|
|
QCOMPARE(event.nativeVirtualKey(), 300u);
|
|
|
|
QCOMPARE(event.text(), QStringLiteral(" "));
|
|
|
|
QCOMPARE(event.count(), 1);
|
|
|
|
QCOMPARE(event.nativeModifiers(), 0u);
|
|
|
|
QCOMPARE(event.modifiers(), Qt::ShiftModifier | Qt::ControlModifier);
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(event.timestamp(), 400ms);
|
2016-05-24 08:57:57 +00:00
|
|
|
// and our custom argument
|
|
|
|
QCOMPARE(event.device(), &d);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitWheelEvent_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<Qt::Orientation>("orientation");
|
|
|
|
QTest::addColumn<qreal>("delta");
|
2022-10-11 10:33:04 +00:00
|
|
|
QTest::addColumn<qint32>("deltaV120");
|
2016-05-24 08:57:57 +00:00
|
|
|
QTest::addColumn<QPoint>("expectedAngleDelta");
|
|
|
|
|
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
|
|
|
QTest::newRow("horiz") << Qt::Horizontal << 3.3 << 1 << QPoint(3, 0);
|
2022-03-23 10:13:38 +00:00
|
|
|
QTest::newRow("vert") << Qt::Vertical << 2.4 << 2 << QPoint(0, 2);
|
2016-05-24 08:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitWheelEvent()
|
|
|
|
{
|
|
|
|
// this test verifies that a WheelEvent is constructed correctly
|
|
|
|
|
|
|
|
// first create the test LibInput::Device
|
|
|
|
libinput_device device;
|
|
|
|
Device d(&device);
|
|
|
|
|
|
|
|
// setup event
|
|
|
|
QFETCH(Qt::Orientation, orientation);
|
|
|
|
QFETCH(qreal, delta);
|
2022-10-11 10:33:04 +00:00
|
|
|
QFETCH(qint32, deltaV120);
|
|
|
|
WheelEvent event(QPointF(100, 200), delta, deltaV120, orientation, Qt::LeftButton | Qt::RightButton,
|
2022-12-21 00:55:20 +00:00
|
|
|
Qt::ShiftModifier | Qt::ControlModifier, InputRedirection::PointerAxisSourceWheel, 300ms, &d);
|
2016-05-24 08:57:57 +00:00
|
|
|
// compare QWheelEvent contract
|
|
|
|
QCOMPARE(event.type(), QEvent::Wheel);
|
2022-03-09 16:28:31 +00:00
|
|
|
QCOMPARE(event.position(), QPointF(100, 200));
|
|
|
|
QCOMPARE(event.globalPosition(), QPointF(100, 200));
|
2016-05-24 08:57:57 +00:00
|
|
|
QCOMPARE(event.buttons(), Qt::LeftButton | Qt::RightButton);
|
|
|
|
QCOMPARE(event.modifiers(), Qt::ShiftModifier | Qt::ControlModifier);
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(event.timestamp(), 300ms);
|
2016-05-24 08:57:57 +00:00
|
|
|
QTEST(event.angleDelta(), "expectedAngleDelta");
|
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
|
|
|
QTEST(event.orientation(), "orientation");
|
|
|
|
QTEST(event.delta(), "delta");
|
2022-10-11 10:33:04 +00:00
|
|
|
QTEST(event.deltaV120(), "deltaV120");
|
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
|
|
|
QCOMPARE(event.axisSource(), InputRedirection::PointerAxisSourceWheel);
|
2016-05-24 08:57:57 +00:00
|
|
|
// and our custom argument
|
|
|
|
QCOMPARE(event.device(), &d);
|
|
|
|
}
|
|
|
|
|
2017-12-27 19:25:36 +00:00
|
|
|
void InputEventsTest::testInitSwitchEvent_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<KWin::SwitchEvent::State>("state");
|
2022-12-21 00:55:20 +00:00
|
|
|
QTest::addColumn<quint64>("timestamp");
|
2017-12-27 19:25:36 +00:00
|
|
|
|
2022-12-21 00:55:20 +00:00
|
|
|
QTest::newRow("on") << SwitchEvent::State::On << quint64{23456790};
|
|
|
|
QTest::newRow("off") << SwitchEvent::State::Off << quint64{45689235987};
|
2017-12-27 19:25:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputEventsTest::testInitSwitchEvent()
|
|
|
|
{
|
|
|
|
// this test verifies that a SwitchEvent is constructed correctly
|
|
|
|
libinput_device device;
|
|
|
|
Device d(&device);
|
|
|
|
|
|
|
|
QFETCH(SwitchEvent::State, state);
|
2022-12-21 00:55:20 +00:00
|
|
|
QFETCH(quint64, timestamp);
|
|
|
|
SwitchEvent event(state, std::chrono::microseconds(timestamp), &d);
|
2017-12-27 19:25:36 +00:00
|
|
|
|
|
|
|
QCOMPARE(event.state(), state);
|
2022-12-21 00:55:20 +00:00
|
|
|
QCOMPARE(event.timestamp(), std::chrono::microseconds(timestamp));
|
2017-12-27 19:25:36 +00:00
|
|
|
QCOMPARE(event.device(), &d);
|
|
|
|
}
|
|
|
|
|
2016-05-24 08:57:57 +00:00
|
|
|
QTEST_GUILESS_MAIN(InputEventsTest)
|
|
|
|
#include "input_event_test.moc"
|