Commit b1934177 authored by David Strobach's avatar David Strobach

[libinput] Add natural scrolling support

Wraps libinput
libinput_device_config_has_natural_scroll
libinput_device_config_set_natural_scroll_enabled
libinput_device_config_get_natural_scroll_enabled
libinput_device_config_scroll_get_default_natural_scroll_enabled

Differential Revision: https://phabricator.kde.org/D3193
BUG: 371791
FIXED-IN: 5.8.4
parent e00649d0
......@@ -622,3 +622,30 @@ enum libinput_config_middle_emulation_state libinput_device_config_middle_emulat
return LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
}
}
int libinput_device_config_scroll_has_natural_scroll(struct libinput_device *device)
{
return device->supportsNaturalScroll;
}
enum libinput_config_status libinput_device_config_scroll_set_natural_scroll_enabled(struct libinput_device *device, int enable)
{
if (device->setNaturalScrollReturnValue == 0) {
if (!device->supportsNaturalScroll) {
return LIBINPUT_CONFIG_STATUS_INVALID;
}
device->naturalScroll = enable;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
return LIBINPUT_CONFIG_STATUS_INVALID;
}
int libinput_device_config_scroll_get_natural_scroll_enabled(struct libinput_device *device)
{
return device->naturalScroll;
}
int libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput_device *device)
{
return device->naturalScrollEnabledByDefault;
}
......@@ -53,12 +53,16 @@ struct libinput_device {
bool supportsDisableEvents = false;
bool supportsDisableEventsOnExternalMouse = false;
bool supportsMiddleEmulation = false;
bool supportsNaturalScroll = false;
bool middleEmulationEnabledByDefault = false;
bool middleEmulation = false;
qreal pointerAcceleration = 0.0;
int setPointerAccelerationReturnValue = 0;
bool leftHanded = false;
int setLeftHandedReturnValue = 0;
bool naturalScrollEnabledByDefault = false;
bool naturalScroll = false;
int setNaturalScrollReturnValue = 0;
Qt::MouseButtons supportedButtons;
QVector<quint32> keys;
bool enabled = true;
......
......@@ -104,9 +104,12 @@ Device::Device(libinput_device *device, QObject *parent)
, 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_supportsNaturalScroll(libinput_device_config_scroll_has_natural_scroll(m_device))
, m_middleEmulationEnabledByDefault(libinput_device_config_middle_emulation_get_default_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED)
, m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device))
, 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_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(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)
{
......@@ -189,6 +192,19 @@ void Device::setPointerAcceleration(qreal acceleration)
}
}
void Device::setNaturalScroll(bool set)
{
if (!m_supportsNaturalScroll) {
return;
}
if (libinput_device_config_scroll_set_natural_scroll_enabled(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_naturalScroll != set) {
m_naturalScroll = set;
emit naturalScrollChanged();
}
}
}
#define CONFIG(method, condition, function, enum, variable) \
void Device::method(bool set) \
{ \
......
......@@ -58,9 +58,12 @@ class Device : public QObject
Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT)
Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT)
Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT)
Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT)
Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT)
Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT)
Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged)
Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged)
Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged)
Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged)
Q_PROPERTY(bool tapAndDragEnabledByDefault READ tapAndDragEnabledByDefault CONSTANT)
......@@ -162,13 +165,23 @@ public:
bool supportsMiddleEmulation() const {
return m_supportsMiddleEmulation;
}
bool supportsNaturalScroll() const {
return m_supportsNaturalScroll;
}
bool middleEmulationEnabledByDefault() const {
return m_middleEmulationEnabledByDefault;
}
bool naturalScrollEnabledByDefault() const {
return m_naturalScrollEnabledByDefault;
}
bool isMiddleEmulation() const {
return m_middleEmulation;
}
void setMiddleEmulation(bool set);
bool isNaturalScroll() const {
return m_naturalScroll;
}
void setNaturalScroll(bool set);
bool isLeftHanded() const {
return m_leftHanded;
......@@ -215,6 +228,7 @@ Q_SIGNALS:
void tapAndDragChanged();
void tapDragLockChanged();
void middleEmulationChanged();
void naturalScrollChanged();
private:
libinput_device *m_device;
......@@ -246,9 +260,12 @@ private:
bool m_supportsDisableEvents;
bool m_supportsDisableEventsOnExternalMouse;
bool m_supportsMiddleEmulation;
bool m_supportsNaturalScroll;
bool m_middleEmulationEnabledByDefault;
bool m_naturalScrollEnabledByDefault;
bool m_middleEmulation;
bool m_leftHanded;
bool m_naturalScroll;
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