Input system redesign
Currently, there is a cyclic dependency between the libinput backend and the wl_seat integration. Another issue is that the input system is not unified for real input devices and fake input devices. It will be great if the input system is designed in such a way that it doesn't rely on kwaylandserver and it allows adding support for other kinds of input devices, e.g. fake eis input devices, etc.
The new input device abstractions can look something like this (note that this is a sketch, not complete api)
namespace KWin
{
class PointerDevice;
class TouchDevice;
class KeyboardDevice;
class TabletToolDevice;
class TabletPadDevice;
/**
* The InputDevice class is the base class for all input devices.
*/
class InputDevice : public QObject
{
Q_OBJECT
public:
/**
* This enum type is used to specify the type of the input device.
*/
enum Type {
Pointer,
Touch,
Keyboard,
TabletTool,
TabletPad,
};
/**
* Returns the type of the input device.
*/
Type type() const;
protected:
explicit InputDevice(Type type, QObject *parent = nullptr);
private:
Type m_type;
};
enum class PointerButtonState {
Pressed,
Released,
};
struct PointerButtonEvent
{
PointerDevice *device;
quint32 button;
quint32 time;
PointerButtonState state;
};
struct PointerMotionEvent
{
PointerDevice *device;
quint32 time;
QPointF delta;
QPointF unacceleratedDelta;
};
struct PointerMotionAbsoluteEvent
{
PointerDevice *device;
quint32 time;
QPointF position;
};
enum class PointerAxisSource {
Wheel,
Finger,
Continuous,
WheelTilt,
};
enum class PointerAxisOrientation {
Vertical,
Horizontal,
};
struct PointerAxisEvent
{
PointerDevice *device;
quint32 time;
PointerAxisSource source;
PointerAxisOrientation orientation;
qreal delta;
qint32 discreteDelta;
};
struct PointerFrameEvent
{
PointerDevice *device;
};
struct PointerSwipeBeginEvent
{
PointerDevice *device;
quint32 fingerCount;
quint32 time;
};
struct PointerSwipeUpdateEvent
{
PointerDevice *device;
quint32 fingerCount;
quint32 time;
QPointF delta;
};
struct PointerSwipeEndEvent
{
PointerDevice *device;
quint32 time;
bool canceled;
};
struct PointerPinchBeginEvent
{
PointerDevice *device;
quint32 fingerCount;
quint32 time;
};
struct PointerPinchUpdateEvent
{
PointerDevice *device;
quint32 fingerCount;
quint32 time;
QPointF delta;
qreal scale;
qreal angleDelta;
};
struct PointerPinchEndEvent
{
PointerDevice *device;
quint32 time;
bool canceled;
};
/**
* The PointerDevice class represents input devices such as mice, touchpads, etc.
*/
class PointerDevice : public InputDevice
{
Q_OBJECT
public:
explicit PointerDevice(QObject *parent = nullptr);
Q_SIGNALS:
void button(const PointerButtonEvent &event);
void motion(const PointerMotionEvent &event);
void motionAbsolute(const PointerMotionAbsoluteEvent &event);
void axis(const PointerAxisEvent &event);
void frame(const PointerFrameEvent &event);
void swipeBegin(const PointerSwipeBeginEvent &event);
void swipeUpdate(const PointerSwipeUpdateEvent &event);
void swipeEnd(const PointerSwipeEndEvent &event);
void pinchBegin(const PointerPinchBeginEvent &event);
void pinchUpdate(const PointerPinchUpdateEvent &event);
void pinchEnd(const PointerPinchEndEvent &event);
};
struct TouchDownEvent
{
TouchDevice *device;
qint32 touchId;
quint32 time;
};
struct TouchUpEvent
{
TouchDevice *device;
qint32 touchId;
quint32 time;
};
struct TouchMotionEvent
{
TouchDevice *device;
qint32 touchId;
quint32 time;
QPointF delta;
};
struct TouchFrameEvent
{
TouchDevice *device;
}
struct TouchCancelEvent
{
TouchDevice *device;
qint32 touchId;
quint32 time;
};
/**
* The TouchDevice class represents input devices such as touch screens.
*/
class TouchDevice : public InputDevice
{
Q_OBJECT
public:
explicit TouchDevice(QObject *parent = nullptr);
Q_SIGNALS:
void down(const TouchDownEvent &event);
void up(const TouchUpEvent &event);
void motion(const TouchMotionEvent &event);
void frame(const TouchFrameEvent &event);
void cancel(const TouchCancelEvent &event);
};
struct KeyboardKeyEvent
{
KeyboardDevice *device;
quint32 time;
};
struct KeyboardModifiersEvent
{
KeyboardDevice *device;
quint32 time;
};
/**
* The KeyboardDevice class represents keyboard input devices.
*/
class KeyboardDevice : public InputDevice
{
Q_OBJECT
public:
explicit KeyboardDevice(QObject *parent = nullptr);
Q_SIGNALS:
void key(const KeyboardKeyEvent &event);
void modifiers(const KeyboardModifiersEvent &event);
};
enum class TabletPadButtonState {
Pressed,
Released,
};
struct TabletPadButtonEvent
{
TabletPadDevice *device;
quint32 time;
quint32 button;
TabletPadButtonState state;
};
enum class TabletPadRingSource {
Unknown,
Finger,
};
struct TabletPadRingEvent
{
TabletPadDevice *device;
quint32 time;
quint32 ring;
qreal position;
TabletPadRingSource source;
};
enum class TabletPadStripSource {
Unknown,
Finger,
};
struct TabletPadStripEvent
{
TabletPadDevice *device;
quint32 time;
quint32 strip;
qreal position;
TabletPadStripSource source;
};
/**
* The TabletPadDevice class represents a tablet pad input device.
*/
class TabletPadDevice : public InputDevice
{
Q_OBJECT
public:
explicit TabletPadDevice(QObject *parent = nullptr);
Q_SIGNALS:
void button(const TabletPadButtonEvent &event);
void ring(const TabletPadRingEvent &event);
void strip(const TabletPadStripEvent &event);
};
struct TabletToolAxisEvent
{
TabletToolDevice *device;
quint32 time;
QPointF position;
QPointF delta;
qreal pressure;
qreal distance;
qreal xTilt;
qreal yTilt;
qreal rotation;
qreal slider;
qreal wheelDelta;
};
enum class TabletToolProximityState {
In,
Out,
};
struct TabletToolProximityEvent
{
TabletToolDevice *device;
quint32 time;
QPointF position;
TabletToolProximityState state;
};
enum class TabletToolTipState {
Up,
Down,
};
struct TabletToolTipEvent
{
TabletToolDevice *device;
quint32 time;
QPointF position;
TabletToolTipState state;
};
enum class TabletToolButtonState {
Pressed,
Released,
};
struct TabletToolButtonEvent
{
TabletToolDevice *device;
quint32 time;
quint32 button;
TabletToolButtonState state;
};
/**
* The TabletToolDevice class represents a tablet tool input device.
*/
class TabletToolDevice : public InputDevice
{
Q_OBJECT
public:
explicit TabletToolDevice(QObject *parent = nullptr);
enum Type {
Pen,
Eraser,
Brush,
Pencil,
Airbrush,
Finger,
Mouse,
Lens,
Totem,
};
enum Capability {
Tilt = 0x1,
Pressure = 0x2,
Distance = 0x4,
Rotation = 0x8,
Slider = 0x10,
Wheel = 0x20,
};
Q_DECLARE_FLAGS(Capabilities, Capability)
quint32 serial() const;
quint32 toolId() const;
Capabilities capabilities() const;
Type type() const;
Q_SIGNALS:
void axis(const TabletToolAxisEvent &event);
void proximity(const TabletToolProximityEvent &event);
void tip(const TabletToolTipEvent &event);
void button(const TabletToolButtonEvent &event);
};
} // namespace KWin