Commit e00649d0 authored by David Strobach's avatar David Strobach

[libinput] Add middle mouse button emulation support

Wraps libinput
libinput_device_config_middle_emulation_is_available
libinput_device_config_middle_emulation_set_enabled
libinput_device_config_middle_emulation_get_enabled
libinput_device_config_middle_emulation_get_default_enabled

Differential Revision: https://phabricator.kde.org/D3187
BUG: 371756
FIXED-IN: 5.8.4
parent 679e4178
......@@ -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;
}
}
......@@ -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 {
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment