Advance Wayland and KDE package bring-up
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
include_directories(${Libinput_INCLUDE_DIRS})
|
||||
|
||||
add_definitions(-DKWIN_BUILD_TESTING)
|
||||
add_library(LibInputTestObjects STATIC ../../src/backends/libinput/device.cpp ../../src/backends/libinput/events.cpp ../../src/core/inputdevice.cpp ../../src/mousebuttons.cpp mock_libinput.cpp)
|
||||
target_link_libraries(LibInputTestObjects Qt::Test Qt::Widgets Qt::DBus Qt::Gui KF6::ConfigCore)
|
||||
target_include_directories(LibInputTestObjects PUBLIC ${CMAKE_SOURCE_DIR}/src)
|
||||
|
||||
########################################################
|
||||
# Test Devices
|
||||
########################################################
|
||||
add_executable(testLibinputDevice device_test.cpp)
|
||||
target_link_libraries(testLibinputDevice Qt::Test Qt::DBus Qt::Gui KF6::ConfigCore LibInputTestObjects)
|
||||
add_test(NAME kwin-testLibinputDevice COMMAND testLibinputDevice)
|
||||
ecm_mark_as_test(testLibinputDevice)
|
||||
|
||||
########################################################
|
||||
# Test Key Event
|
||||
########################################################
|
||||
add_executable(testLibinputKeyEvent key_event_test.cpp)
|
||||
target_link_libraries(testLibinputKeyEvent Qt::Test Qt::DBus Qt::Widgets KF6::ConfigCore LibInputTestObjects)
|
||||
add_test(NAME kwin-testLibinputKeyEvent COMMAND testLibinputKeyEvent)
|
||||
ecm_mark_as_test(testLibinputKeyEvent)
|
||||
|
||||
########################################################
|
||||
# Test Pointer Event
|
||||
########################################################
|
||||
add_executable(testLibinputPointerEvent pointer_event_test.cpp)
|
||||
target_link_libraries(testLibinputPointerEvent Qt::Test Qt::DBus Qt::Widgets KF6::ConfigCore LibInputTestObjects)
|
||||
add_test(NAME kwin-testLibinputPointerEvent COMMAND testLibinputPointerEvent)
|
||||
ecm_mark_as_test(testLibinputPointerEvent)
|
||||
|
||||
########################################################
|
||||
# Test Touch Event
|
||||
########################################################
|
||||
add_executable(testLibinputTouchEvent touch_event_test.cpp)
|
||||
target_link_libraries(testLibinputTouchEvent Qt::Test Qt::DBus Qt::Widgets KF6::ConfigCore LibInputTestObjects)
|
||||
add_test(NAME kwin-testLibinputTouchEvent COMMAND testLibinputTouchEvent)
|
||||
ecm_mark_as_test(testLibinputTouchEvent)
|
||||
|
||||
########################################################
|
||||
# Test Gesture Event
|
||||
########################################################
|
||||
add_executable(testLibinputGestureEvent gesture_event_test.cpp)
|
||||
target_link_libraries(testLibinputGestureEvent Qt::Test Qt::DBus Qt::Widgets KF6::ConfigCore LibInputTestObjects)
|
||||
add_test(NAME kwin-testLibinputGestureEvent COMMAND testLibinputGestureEvent)
|
||||
ecm_mark_as_test(testLibinputGestureEvent)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "mock_libinput.h"
|
||||
|
||||
#include "backends/libinput/device.h"
|
||||
#include "backends/libinput/events.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
Q_DECLARE_METATYPE(libinput_event_type)
|
||||
|
||||
using namespace KWin::LibInput;
|
||||
using namespace std::literals;
|
||||
|
||||
class TestLibinputGestureEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testType_data();
|
||||
void testType();
|
||||
|
||||
void testStart_data();
|
||||
void testStart();
|
||||
|
||||
void testSwipeUpdate();
|
||||
void testPinchUpdate();
|
||||
|
||||
void testEnd_data();
|
||||
void testEnd();
|
||||
|
||||
private:
|
||||
libinput_device *m_nativeDevice = nullptr;
|
||||
Device *m_device = nullptr;
|
||||
};
|
||||
|
||||
void TestLibinputGestureEvent::init()
|
||||
{
|
||||
m_nativeDevice = new libinput_device;
|
||||
m_nativeDevice->pointer = true;
|
||||
m_nativeDevice->gestureSupported = true;
|
||||
m_nativeDevice->deviceSize = QSizeF(12.5, 13.8);
|
||||
m_device = new Device(m_nativeDevice);
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::cleanup()
|
||||
{
|
||||
delete m_device;
|
||||
m_device = nullptr;
|
||||
|
||||
delete m_nativeDevice;
|
||||
m_nativeDevice = nullptr;
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testType_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
|
||||
QTest::newRow("pinch-start") << LIBINPUT_EVENT_GESTURE_PINCH_BEGIN;
|
||||
QTest::newRow("pinch-update") << LIBINPUT_EVENT_GESTURE_PINCH_UPDATE;
|
||||
QTest::newRow("pinch-end") << LIBINPUT_EVENT_GESTURE_PINCH_END;
|
||||
QTest::newRow("swipe-start") << LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN;
|
||||
QTest::newRow("swipe-update") << LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE;
|
||||
QTest::newRow("swipe-end") << LIBINPUT_EVENT_GESTURE_SWIPE_END;
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testType()
|
||||
{
|
||||
// this test verifies the initialization of a PointerEvent and the parent Event class
|
||||
libinput_event_gesture *gestureEvent = new libinput_event_gesture;
|
||||
QFETCH(libinput_event_type, type);
|
||||
gestureEvent->type = type;
|
||||
gestureEvent->device = m_nativeDevice;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(gestureEvent));
|
||||
// API of event
|
||||
QCOMPARE(event->type(), type);
|
||||
QCOMPARE(event->device(), m_device);
|
||||
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
||||
QCOMPARE((libinput_event *)(*event.get()), gestureEvent);
|
||||
// verify it's a pointer event
|
||||
QVERIFY(dynamic_cast<GestureEvent *>(event.get()));
|
||||
QCOMPARE((libinput_event_gesture *)(*dynamic_cast<GestureEvent *>(event.get())), gestureEvent);
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testStart_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
|
||||
QTest::newRow("pinch") << LIBINPUT_EVENT_GESTURE_PINCH_BEGIN;
|
||||
QTest::newRow("swipe") << LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN;
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testStart()
|
||||
{
|
||||
libinput_event_gesture *gestureEvent = new libinput_event_gesture;
|
||||
gestureEvent->device = m_nativeDevice;
|
||||
QFETCH(libinput_event_type, type);
|
||||
gestureEvent->type = type;
|
||||
gestureEvent->fingerCount = 3;
|
||||
gestureEvent->time = 100ms;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(gestureEvent));
|
||||
auto ge = dynamic_cast<GestureEvent *>(event.get());
|
||||
QVERIFY(ge);
|
||||
QCOMPARE(ge->fingerCount(), gestureEvent->fingerCount);
|
||||
QVERIFY(!ge->isCancelled());
|
||||
QCOMPARE(ge->time(), gestureEvent->time);
|
||||
QCOMPARE(ge->delta(), QPointF(0, 0));
|
||||
if (ge->type() == LIBINPUT_EVENT_GESTURE_PINCH_BEGIN) {
|
||||
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
|
||||
QCOMPARE(pe->scale(), 1.0);
|
||||
QCOMPARE(pe->angleDelta(), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testSwipeUpdate()
|
||||
{
|
||||
libinput_event_gesture *gestureEvent = new libinput_event_gesture;
|
||||
gestureEvent->device = m_nativeDevice;
|
||||
gestureEvent->type = LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE;
|
||||
gestureEvent->fingerCount = 2;
|
||||
gestureEvent->time = 200ms;
|
||||
gestureEvent->delta = QPointF(2, 3);
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(gestureEvent));
|
||||
auto se = dynamic_cast<SwipeGestureEvent *>(event.get());
|
||||
QVERIFY(se);
|
||||
QCOMPARE(se->fingerCount(), gestureEvent->fingerCount);
|
||||
QVERIFY(!se->isCancelled());
|
||||
QCOMPARE(se->time(), gestureEvent->time);
|
||||
QCOMPARE(se->delta(), QPointF(2, 3));
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testPinchUpdate()
|
||||
{
|
||||
libinput_event_gesture *gestureEvent = new libinput_event_gesture;
|
||||
gestureEvent->device = m_nativeDevice;
|
||||
gestureEvent->type = LIBINPUT_EVENT_GESTURE_PINCH_UPDATE;
|
||||
gestureEvent->fingerCount = 4;
|
||||
gestureEvent->time = 600ms;
|
||||
gestureEvent->delta = QPointF(5, 4);
|
||||
gestureEvent->scale = 2;
|
||||
gestureEvent->angleDelta = -30;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(gestureEvent));
|
||||
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
|
||||
QVERIFY(pe);
|
||||
QCOMPARE(pe->fingerCount(), gestureEvent->fingerCount);
|
||||
QVERIFY(!pe->isCancelled());
|
||||
QCOMPARE(pe->time(), gestureEvent->time);
|
||||
QCOMPARE(pe->delta(), QPointF(5, 4));
|
||||
QCOMPARE(pe->scale(), gestureEvent->scale);
|
||||
QCOMPARE(pe->angleDelta(), gestureEvent->angleDelta);
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testEnd_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
QTest::addColumn<bool>("cancelled");
|
||||
|
||||
QTest::newRow("pinch/not cancelled") << LIBINPUT_EVENT_GESTURE_PINCH_END << false;
|
||||
QTest::newRow("pinch/cancelled") << LIBINPUT_EVENT_GESTURE_PINCH_END << true;
|
||||
QTest::newRow("swipe/not cancelled") << LIBINPUT_EVENT_GESTURE_SWIPE_END << false;
|
||||
QTest::newRow("swipe/cancelled") << LIBINPUT_EVENT_GESTURE_SWIPE_END << true;
|
||||
}
|
||||
|
||||
void TestLibinputGestureEvent::testEnd()
|
||||
{
|
||||
libinput_event_gesture *gestureEvent = new libinput_event_gesture;
|
||||
gestureEvent->device = m_nativeDevice;
|
||||
QFETCH(libinput_event_type, type);
|
||||
gestureEvent->type = type;
|
||||
gestureEvent->fingerCount = 4;
|
||||
QFETCH(bool, cancelled);
|
||||
gestureEvent->cancelled = cancelled;
|
||||
gestureEvent->time = 300ms;
|
||||
gestureEvent->scale = 3;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(gestureEvent));
|
||||
auto ge = dynamic_cast<GestureEvent *>(event.get());
|
||||
QVERIFY(ge);
|
||||
QCOMPARE(ge->fingerCount(), gestureEvent->fingerCount);
|
||||
QCOMPARE(ge->isCancelled(), cancelled);
|
||||
QCOMPARE(ge->time(), gestureEvent->time);
|
||||
QCOMPARE(ge->delta(), QPointF(0, 0));
|
||||
if (ge->type() == LIBINPUT_EVENT_GESTURE_PINCH_END) {
|
||||
auto pe = dynamic_cast<PinchGestureEvent *>(event.get());
|
||||
QCOMPARE(pe->scale(), gestureEvent->scale);
|
||||
QCOMPARE(pe->angleDelta(), 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputGestureEvent)
|
||||
#include "gesture_event_test.moc"
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "mock_libinput.h"
|
||||
|
||||
#include "backends/libinput/device.h"
|
||||
#include "backends/libinput/events.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
Q_DECLARE_METATYPE(libinput_key_state)
|
||||
|
||||
using namespace KWin::LibInput;
|
||||
|
||||
class TestLibinputKeyEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testCreate();
|
||||
void testEvent_data();
|
||||
void testEvent();
|
||||
|
||||
private:
|
||||
libinput_device *m_nativeDevice = nullptr;
|
||||
Device *m_device = nullptr;
|
||||
};
|
||||
|
||||
void TestLibinputKeyEvent::init()
|
||||
{
|
||||
m_nativeDevice = new libinput_device;
|
||||
m_nativeDevice->keyboard = true;
|
||||
m_device = new Device(m_nativeDevice);
|
||||
}
|
||||
|
||||
void TestLibinputKeyEvent::cleanup()
|
||||
{
|
||||
delete m_device;
|
||||
m_device = nullptr;
|
||||
|
||||
delete m_nativeDevice;
|
||||
m_nativeDevice = nullptr;
|
||||
}
|
||||
|
||||
void TestLibinputKeyEvent::testCreate()
|
||||
{
|
||||
// this test verifies the initialisation of a KeyEvent and the parent Event class
|
||||
libinput_event_keyboard *keyEvent = new libinput_event_keyboard;
|
||||
keyEvent->device = m_nativeDevice;
|
||||
|
||||
std::unique_ptr<Event> event{Event::create(keyEvent)};
|
||||
// API of event
|
||||
QCOMPARE(event->type(), LIBINPUT_EVENT_KEYBOARD_KEY);
|
||||
QCOMPARE(event->device(), m_device);
|
||||
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
||||
QCOMPARE((libinput_event *)(*event.get()), keyEvent);
|
||||
// verify it's a key event
|
||||
QVERIFY(dynamic_cast<KeyEvent *>(event.get()));
|
||||
QCOMPARE((libinput_event_keyboard *)(*dynamic_cast<KeyEvent *>(event.get())), keyEvent);
|
||||
|
||||
// verify that a nullptr passed to Event::create returns a nullptr
|
||||
QVERIFY(!Event::create(nullptr));
|
||||
}
|
||||
|
||||
void TestLibinputKeyEvent::testEvent_data()
|
||||
{
|
||||
QTest::addColumn<libinput_key_state>("keyState");
|
||||
QTest::addColumn<KWin::KeyboardKeyState>("expectedKeyState");
|
||||
QTest::addColumn<quint32>("key");
|
||||
QTest::addColumn<quint32>("time");
|
||||
|
||||
QTest::newRow("pressed") << LIBINPUT_KEY_STATE_PRESSED << KWin::KeyboardKeyState::Pressed << quint32(KEY_A) << 100u;
|
||||
QTest::newRow("released") << LIBINPUT_KEY_STATE_RELEASED << KWin::KeyboardKeyState::Released << quint32(KEY_B) << 200u;
|
||||
}
|
||||
|
||||
void TestLibinputKeyEvent::testEvent()
|
||||
{
|
||||
// this test verifies the key press/release
|
||||
libinput_event_keyboard *keyEvent = new libinput_event_keyboard;
|
||||
keyEvent->device = m_nativeDevice;
|
||||
QFETCH(libinput_key_state, keyState);
|
||||
keyEvent->state = keyState;
|
||||
QFETCH(quint32, key);
|
||||
keyEvent->key = key;
|
||||
QFETCH(quint32, time);
|
||||
keyEvent->time = std::chrono::milliseconds(time);
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(keyEvent));
|
||||
auto ke = dynamic_cast<KeyEvent *>(event.get());
|
||||
QVERIFY(ke);
|
||||
QTEST(ke->state(), "expectedKeyState");
|
||||
QCOMPARE(ke->key(), key);
|
||||
QCOMPARE(ke->time(), keyEvent->time);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputKeyEvent)
|
||||
#include "key_event_test.moc"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#ifndef MOCK_LIBINPUT_H
|
||||
#define MOCK_LIBINPUT_H
|
||||
#include <libinput.h>
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QPointF>
|
||||
#include <QSizeF>
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
|
||||
struct libinput_device
|
||||
{
|
||||
void *userData = nullptr;
|
||||
bool keyboard = false;
|
||||
bool pointer = false;
|
||||
bool touch = false;
|
||||
bool tabletTool = false;
|
||||
bool gestureSupported = false;
|
||||
bool switchDevice = false;
|
||||
QByteArray name;
|
||||
QByteArray sysName = QByteArrayLiteral("event0");
|
||||
QByteArray outputName;
|
||||
quint32 product = 0;
|
||||
quint32 vendor = 0;
|
||||
int tapFingerCount = 0;
|
||||
QSizeF deviceSize;
|
||||
int deviceSizeReturnValue = 0;
|
||||
bool tapEnabledByDefault = false;
|
||||
bool tapToClick = false;
|
||||
bool tapAndDragEnabledByDefault = false;
|
||||
bool tapAndDrag = false;
|
||||
bool tapDragLockEnabledByDefault = false;
|
||||
bool tapDragLock = false;
|
||||
bool supportsDisableWhileTyping = false;
|
||||
bool supportsPointerAcceleration = false;
|
||||
bool supportsLeftHanded = false;
|
||||
bool supportsCalibrationMatrix = false;
|
||||
bool supportsDisableEvents = false;
|
||||
bool supportsDisableEventsOnExternalMouse = false;
|
||||
bool supportsMiddleEmulation = false;
|
||||
bool supportsNaturalScroll = false;
|
||||
quint32 supportedScrollMethods = 0;
|
||||
bool middleEmulationEnabledByDefault = false;
|
||||
bool middleEmulation = false;
|
||||
enum libinput_config_tap_button_map defaultTapButtonMap = LIBINPUT_CONFIG_TAP_MAP_LRM;
|
||||
enum libinput_config_tap_button_map tapButtonMap = LIBINPUT_CONFIG_TAP_MAP_LRM;
|
||||
int setTapButtonMapReturnValue = 0;
|
||||
enum libinput_config_dwt_state disableWhileTypingEnabledByDefault = LIBINPUT_CONFIG_DWT_DISABLED;
|
||||
enum libinput_config_dwt_state disableWhileTyping = LIBINPUT_CONFIG_DWT_DISABLED;
|
||||
int setDisableWhileTypingReturnValue = 0;
|
||||
qreal defaultPointerAcceleration = 0.0;
|
||||
qreal pointerAcceleration = 0.0;
|
||||
int setPointerAccelerationReturnValue = 0;
|
||||
bool leftHandedEnabledByDefault = false;
|
||||
bool leftHanded = false;
|
||||
int setLeftHandedReturnValue = 0;
|
||||
bool naturalScrollEnabledByDefault = false;
|
||||
bool naturalScroll = false;
|
||||
int setNaturalScrollReturnValue = 0;
|
||||
enum libinput_config_scroll_method defaultScrollMethod = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
||||
enum libinput_config_scroll_method scrollMethod = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
|
||||
int setScrollMethodReturnValue = 0;
|
||||
quint32 defaultScrollButton = 0;
|
||||
quint32 scrollButton = 0;
|
||||
int setScrollButtonReturnValue = 0;
|
||||
Qt::MouseButtons supportedButtons;
|
||||
QList<quint32> keys;
|
||||
bool enabled = true;
|
||||
bool disableEventsOnExternalMouse = false;
|
||||
int setEnableModeReturnValue = 0;
|
||||
int setTapToClickReturnValue = 0;
|
||||
int setTapAndDragReturnValue = 0;
|
||||
int setTapDragLockReturnValue = 0;
|
||||
int setMiddleEmulationReturnValue = 0;
|
||||
quint32 supportedPointerAccelerationProfiles = 0;
|
||||
enum libinput_config_accel_profile defaultPointerAccelerationProfile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
||||
enum libinput_config_accel_profile pointerAccelerationProfile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
|
||||
bool setPointerAccelerationProfileReturnValue = 0;
|
||||
std::array<float, 6> defaultCalibrationMatrix{{1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f}};
|
||||
std::array<float, 6> calibrationMatrix{{1.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f}};
|
||||
bool defaultCalibrationMatrixIsIdentity = true;
|
||||
bool calibrationMatrixIsIdentity = true;
|
||||
|
||||
bool lidSwitch = false;
|
||||
bool tabletModeSwitch = false;
|
||||
quint32 supportedClickMethods = 0;
|
||||
enum libinput_config_click_method defaultClickMethod = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
|
||||
enum libinput_config_click_method clickMethod = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
|
||||
bool setClickMethodReturnValue = 0;
|
||||
uint32_t buttonCount = 0;
|
||||
uint32_t stripCount = 0;
|
||||
uint32_t ringCount = 0;
|
||||
};
|
||||
|
||||
struct libinput_event
|
||||
{
|
||||
virtual ~libinput_event()
|
||||
{
|
||||
}
|
||||
libinput_device *device = nullptr;
|
||||
libinput_event_type type = LIBINPUT_EVENT_NONE;
|
||||
std::chrono::microseconds time = std::chrono::microseconds::zero();
|
||||
};
|
||||
|
||||
struct libinput_event_keyboard : libinput_event
|
||||
{
|
||||
libinput_event_keyboard()
|
||||
{
|
||||
type = LIBINPUT_EVENT_KEYBOARD_KEY;
|
||||
}
|
||||
libinput_key_state state = LIBINPUT_KEY_STATE_RELEASED;
|
||||
quint32 key = 0;
|
||||
};
|
||||
|
||||
struct libinput_event_pointer : libinput_event
|
||||
{
|
||||
libinput_button_state buttonState = LIBINPUT_BUTTON_STATE_RELEASED;
|
||||
quint32 button = 0;
|
||||
bool verticalAxis = false;
|
||||
bool horizontalAxis = false;
|
||||
qreal horizontalScrollValue = 0.0;
|
||||
qreal verticalScrollValue = 0.0;
|
||||
qreal horizontalScrollValueV120 = 0.0;
|
||||
qreal verticalScrollValueV120 = 0.0;
|
||||
QPointF delta;
|
||||
QPointF absolutePos;
|
||||
};
|
||||
|
||||
struct libinput_event_touch : libinput_event
|
||||
{
|
||||
qint32 slot = -1;
|
||||
QPointF absolutePos;
|
||||
};
|
||||
|
||||
struct libinput_event_gesture : libinput_event
|
||||
{
|
||||
int fingerCount = 0;
|
||||
bool cancelled = false;
|
||||
QPointF delta = QPointF(0, 0);
|
||||
qreal scale = 0.0;
|
||||
qreal angleDelta = 0.0;
|
||||
};
|
||||
|
||||
struct libinput_event_switch : libinput_event
|
||||
{
|
||||
enum class State {
|
||||
Off,
|
||||
On
|
||||
};
|
||||
State state = State::Off;
|
||||
};
|
||||
|
||||
struct libinput
|
||||
{
|
||||
int refCount = 1;
|
||||
QByteArray seat;
|
||||
int assignSeatRetVal = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,292 @@
|
||||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "mock_libinput.h"
|
||||
|
||||
#include "backends/libinput/device.h"
|
||||
#include "backends/libinput/events.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
Q_DECLARE_METATYPE(libinput_event_type)
|
||||
Q_DECLARE_METATYPE(libinput_button_state)
|
||||
|
||||
using namespace KWin::LibInput;
|
||||
using namespace std::literals;
|
||||
|
||||
class TestLibinputPointerEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testType_data();
|
||||
void testType();
|
||||
void testButton_data();
|
||||
void testButton();
|
||||
void testScrollWheel_data();
|
||||
void testScrollWheel();
|
||||
void testScrollFinger_data();
|
||||
void testScrollFinger();
|
||||
void testScrollContinuous_data();
|
||||
void testScrollContinuous();
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
||||
// API of event
|
||||
QCOMPARE(event->type(), type);
|
||||
QCOMPARE(event->device(), m_device);
|
||||
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
||||
QCOMPARE((libinput_event *)(*event.get()), pointerEvent);
|
||||
// verify it's a pointer event
|
||||
QVERIFY(dynamic_cast<PointerEvent *>(event.get()));
|
||||
QCOMPARE((libinput_event_pointer *)(*dynamic_cast<PointerEvent *>(event.get())), pointerEvent);
|
||||
}
|
||||
|
||||
void TestLibinputPointerEvent::testButton_data()
|
||||
{
|
||||
QTest::addColumn<libinput_button_state>("buttonState");
|
||||
QTest::addColumn<KWin::PointerButtonState>("expectedButtonState");
|
||||
QTest::addColumn<quint32>("button");
|
||||
QTest::addColumn<quint32>("time");
|
||||
|
||||
QTest::newRow("pressed") << LIBINPUT_BUTTON_STATE_RELEASED << KWin::PointerButtonState::Released << quint32(BTN_RIGHT) << 100u;
|
||||
QTest::newRow("released") << LIBINPUT_BUTTON_STATE_PRESSED << KWin::PointerButtonState::Pressed << 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 = std::chrono::milliseconds(time);
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
||||
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
||||
QVERIFY(pe);
|
||||
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_BUTTON);
|
||||
QTEST(pe->buttonState(), "expectedButtonState");
|
||||
QCOMPARE(pe->button(), button);
|
||||
QCOMPARE(pe->time(), pointerEvent->time);
|
||||
}
|
||||
|
||||
void TestLibinputPointerEvent::testScrollWheel_data()
|
||||
{
|
||||
QTest::addColumn<bool>("horizontal");
|
||||
QTest::addColumn<bool>("vertical");
|
||||
QTest::addColumn<QPointF>("value");
|
||||
QTest::addColumn<QPoint>("valueV120");
|
||||
QTest::addColumn<quint32>("time");
|
||||
|
||||
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 = std::chrono::milliseconds(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::PointerAxis::Horizontal), horizontal);
|
||||
QCOMPARE(pe->axis().contains(KWin::PointerAxis::Vertical), vertical);
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Horizontal), value.x());
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Vertical), value.y());
|
||||
QCOMPARE(pe->scrollValueV120(KWin::PointerAxis::Horizontal), valueV120.x());
|
||||
QCOMPARE(pe->scrollValueV120(KWin::PointerAxis::Vertical), valueV120.y());
|
||||
QCOMPARE(pe->time(), pointerEvent->time);
|
||||
}
|
||||
|
||||
void TestLibinputPointerEvent::testScrollFinger_data()
|
||||
{
|
||||
QTest::addColumn<bool>("horizontal");
|
||||
QTest::addColumn<bool>("vertical");
|
||||
QTest::addColumn<QPointF>("value");
|
||||
QTest::addColumn<quint32>("time");
|
||||
|
||||
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 = std::chrono::milliseconds(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::PointerAxis::Horizontal), horizontal);
|
||||
QCOMPARE(pe->axis().contains(KWin::PointerAxis::Vertical), vertical);
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Horizontal), value.x());
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Vertical), value.y());
|
||||
QCOMPARE(pe->time(), pointerEvent->time);
|
||||
}
|
||||
|
||||
void TestLibinputPointerEvent::testScrollContinuous_data()
|
||||
{
|
||||
QTest::addColumn<bool>("horizontal");
|
||||
QTest::addColumn<bool>("vertical");
|
||||
QTest::addColumn<QPointF>("value");
|
||||
QTest::addColumn<quint32>("time");
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void TestLibinputPointerEvent::testScrollContinuous()
|
||||
{
|
||||
// this test verifies pointer axis functionality
|
||||
libinput_event_pointer *pointerEvent = new libinput_event_pointer;
|
||||
pointerEvent->device = m_nativeDevice;
|
||||
pointerEvent->type = LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS;
|
||||
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 = std::chrono::milliseconds(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_CONTINUOUS);
|
||||
QCOMPARE(pe->axis().contains(KWin::PointerAxis::Horizontal), horizontal);
|
||||
QCOMPARE(pe->axis().contains(KWin::PointerAxis::Vertical), vertical);
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Horizontal), value.x());
|
||||
QCOMPARE(pe->scrollValue(KWin::PointerAxis::Vertical), value.y());
|
||||
QCOMPARE(pe->time(), pointerEvent->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;
|
||||
pointerEvent->delta = QPointF(2.1, 4.5);
|
||||
pointerEvent->time = 500ms;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
||||
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
||||
QVERIFY(pe);
|
||||
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION);
|
||||
QCOMPARE(pe->time(), pointerEvent->time);
|
||||
QCOMPARE(pe->delta(), QPointF(2.1, 4.5));
|
||||
}
|
||||
|
||||
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 = 500ms;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(pointerEvent));
|
||||
auto pe = dynamic_cast<PointerEvent *>(event.get());
|
||||
QVERIFY(pe);
|
||||
QCOMPARE(pe->type(), LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
|
||||
QCOMPARE(pe->time(), pointerEvent->time);
|
||||
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"
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
||||
|
||||
SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
#include "mock_libinput.h"
|
||||
|
||||
#include "backends/libinput/device.h"
|
||||
#include "backends/libinput/events.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
#include <linux/input.h>
|
||||
|
||||
Q_DECLARE_METATYPE(libinput_event_type)
|
||||
|
||||
using namespace KWin::LibInput;
|
||||
using namespace std::literals;
|
||||
|
||||
class TestLibinputTouchEvent : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
void init();
|
||||
void cleanup();
|
||||
|
||||
void testType_data();
|
||||
void testType();
|
||||
void testAbsoluteMotion_data();
|
||||
void testAbsoluteMotion();
|
||||
|
||||
private:
|
||||
libinput_device *m_nativeDevice = nullptr;
|
||||
Device *m_device = nullptr;
|
||||
};
|
||||
|
||||
void TestLibinputTouchEvent::init()
|
||||
{
|
||||
m_nativeDevice = new libinput_device;
|
||||
m_nativeDevice->touch = true;
|
||||
m_nativeDevice->deviceSize = QSizeF(12.5, 13.8);
|
||||
m_device = new Device(m_nativeDevice);
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::cleanup()
|
||||
{
|
||||
delete m_device;
|
||||
m_device = nullptr;
|
||||
|
||||
delete m_nativeDevice;
|
||||
m_nativeDevice = nullptr;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testType_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
QTest::addColumn<bool>("hasId");
|
||||
|
||||
QTest::newRow("down") << LIBINPUT_EVENT_TOUCH_DOWN << true;
|
||||
QTest::newRow("up") << LIBINPUT_EVENT_TOUCH_UP << true;
|
||||
QTest::newRow("motion") << LIBINPUT_EVENT_TOUCH_MOTION << true;
|
||||
QTest::newRow("cancel") << LIBINPUT_EVENT_TOUCH_CANCEL << false;
|
||||
QTest::newRow("frame") << LIBINPUT_EVENT_TOUCH_FRAME << false;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testType()
|
||||
{
|
||||
// this test verifies the initialization of a PointerEvent and the parent Event class
|
||||
libinput_event_touch *touchEvent = new libinput_event_touch;
|
||||
QFETCH(libinput_event_type, type);
|
||||
touchEvent->type = type;
|
||||
touchEvent->device = m_nativeDevice;
|
||||
touchEvent->slot = 0;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(touchEvent));
|
||||
// API of event
|
||||
QCOMPARE(event->type(), type);
|
||||
QCOMPARE(event->device(), m_device);
|
||||
QCOMPARE(event->nativeDevice(), m_nativeDevice);
|
||||
QCOMPARE((libinput_event *)(*event.get()), touchEvent);
|
||||
// verify it's a pointer event
|
||||
QVERIFY(dynamic_cast<TouchEvent *>(event.get()));
|
||||
QCOMPARE((libinput_event_touch *)(*dynamic_cast<TouchEvent *>(event.get())), touchEvent);
|
||||
QFETCH(bool, hasId);
|
||||
if (hasId) {
|
||||
QCOMPARE(dynamic_cast<TouchEvent *>(event.get())->id(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testAbsoluteMotion_data()
|
||||
{
|
||||
QTest::addColumn<libinput_event_type>("type");
|
||||
QTest::newRow("down") << LIBINPUT_EVENT_TOUCH_DOWN;
|
||||
QTest::newRow("motion") << LIBINPUT_EVENT_TOUCH_MOTION;
|
||||
}
|
||||
|
||||
void TestLibinputTouchEvent::testAbsoluteMotion()
|
||||
{
|
||||
// this test verifies absolute touch points (either down or motion)
|
||||
libinput_event_touch *touchEvent = new libinput_event_touch;
|
||||
touchEvent->device = m_nativeDevice;
|
||||
QFETCH(libinput_event_type, type);
|
||||
touchEvent->type = type;
|
||||
touchEvent->absolutePos = QPointF(6.25, 6.9);
|
||||
touchEvent->time = 500ms;
|
||||
touchEvent->slot = 1;
|
||||
|
||||
std::unique_ptr<Event> event(Event::create(touchEvent));
|
||||
auto te = dynamic_cast<TouchEvent *>(event.get());
|
||||
QVERIFY(te);
|
||||
QCOMPARE(te->type(), type);
|
||||
QCOMPARE(te->time(), touchEvent->time);
|
||||
QCOMPARE(te->absolutePos(), QPointF(6.25, 6.9));
|
||||
QCOMPARE(te->absolutePos(QSize(1280, 1024)), QPointF(640, 512));
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestLibinputTouchEvent)
|
||||
#include "touch_event_test.moc"
|
||||
Reference in New Issue
Block a user