diff --git a/autotests/libinput/mock_libinput.cpp b/autotests/libinput/mock_libinput.cpp index 86d3fc153d..4f298ff521 100644 --- a/autotests/libinput/mock_libinput.cpp +++ b/autotests/libinput/mock_libinput.cpp @@ -587,3 +587,38 @@ int libinput_resume(struct libinput *libinput) Q_UNUSED(libinput) return 0; } + +int libinput_device_config_middle_emulation_is_available(struct libinput_device *device) +{ + return device->supportsMiddleEmulation; +} + +enum libinput_config_status libinput_device_config_middle_emulation_set_enabled(struct libinput_device *device, enum libinput_config_middle_emulation_state enable) +{ + if (device->setMiddleEmulationReturnValue == 0) { + if (!device->supportsMiddleEmulation) { + return LIBINPUT_CONFIG_STATUS_INVALID; + } + device->middleEmulation = (enable == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED); + return LIBINPUT_CONFIG_STATUS_SUCCESS; + } + return LIBINPUT_CONFIG_STATUS_INVALID; +} + +enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_enabled(struct libinput_device *device) +{ + if (device->middleEmulation) { + return LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; + } else { + return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; + } +} + +enum libinput_config_middle_emulation_state libinput_device_config_middle_emulation_get_default_enabled(struct libinput_device *device) +{ + if (device->middleEmulationEnabledByDefault) { + return LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED; + } else { + return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED; + } +} diff --git a/autotests/libinput/mock_libinput.h b/autotests/libinput/mock_libinput.h index ee855c9e6f..99864a31f4 100644 --- a/autotests/libinput/mock_libinput.h +++ b/autotests/libinput/mock_libinput.h @@ -52,6 +52,9 @@ struct libinput_device { bool supportsCalibrationMatrix = false; bool supportsDisableEvents = false; bool supportsDisableEventsOnExternalMouse = false; + bool supportsMiddleEmulation = false; + bool middleEmulationEnabledByDefault = false; + bool middleEmulation = false; qreal pointerAcceleration = 0.0; int setPointerAccelerationReturnValue = 0; bool leftHanded = false; @@ -63,6 +66,7 @@ struct libinput_device { int setTapToClickReturnValue = 0; int setTapAndDragReturnValue = 0; int setTapDragLockReturnValue = 0; + int setMiddleEmulationReturnValue = 0; }; struct libinput_event { diff --git a/libinput/device.cpp b/libinput/device.cpp index 74a654db08..ff199fc0c9 100644 --- a/libinput/device.cpp +++ b/libinput/device.cpp @@ -103,6 +103,9 @@ Device::Device(libinput_device *device, QObject *parent) , m_supportsCalibrationMatrix(libinput_device_config_calibration_has_matrix(m_device)) , m_supportsDisableEvents(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) , m_supportsDisableEventsOnExternalMouse(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) + , m_supportsMiddleEmulation(libinput_device_config_middle_emulation_is_available(m_device)) + , m_middleEmulationEnabledByDefault(libinput_device_config_middle_emulation_get_default_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) + , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) , m_pointerAcceleration(libinput_device_config_accel_get_speed(m_device)) , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) @@ -204,6 +207,7 @@ CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick) CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag) CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock) +CONFIG(setMiddleEmulation, m_supportsMiddleEmulation == false, middle_emulation_set_enabled, MIDDLE_EMULATION, middleEmulation) #undef CONFIG diff --git a/libinput/device.h b/libinput/device.h index a24b77afa8..5c37031ff4 100644 --- a/libinput/device.h +++ b/libinput/device.h @@ -57,6 +57,9 @@ class Device : public QObject Q_PROPERTY(bool supportsCalibrationMatrix READ supportsCalibrationMatrix CONSTANT) Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT) + Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) + Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) + Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged) @@ -156,6 +159,16 @@ public: bool supportsDisableEventsOnExternalMouse() const { return m_supportsDisableEventsOnExternalMouse; } + bool supportsMiddleEmulation() const { + return m_supportsMiddleEmulation; + } + bool middleEmulationEnabledByDefault() const { + return m_middleEmulationEnabledByDefault; + } + bool isMiddleEmulation() const { + return m_middleEmulation; + } + void setMiddleEmulation(bool set); bool isLeftHanded() const { return m_leftHanded; @@ -201,6 +214,7 @@ Q_SIGNALS: void tapToClickChanged(); void tapAndDragChanged(); void tapDragLockChanged(); + void middleEmulationChanged(); private: libinput_device *m_device; @@ -231,6 +245,9 @@ private: bool m_supportsCalibrationMatrix; bool m_supportsDisableEvents; bool m_supportsDisableEventsOnExternalMouse; + bool m_supportsMiddleEmulation; + bool m_middleEmulationEnabledByDefault; + bool m_middleEmulation; bool m_leftHanded; qreal m_pointerAcceleration; bool m_enabled;