Commit e4283543 authored by David Strobach's avatar David Strobach

[libinput] Add scroll method configuration support

Wraps libinput
libinput_device_config_scroll_get_methods
libinput_device_config_scroll_get_default_method
libinput_device_config_scroll_set_method
libinput_device_config_scroll_get_method
libinput_device_config_scroll_set_button
libinput_device_config_scroll_get_button
libinput_device_config_scroll_get_default_button

Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D3194
BUG: 371803
FIXED-IN: 5.8.4
parent b1934177
......@@ -649,3 +649,52 @@ int libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libi
{
return device->naturalScrollEnabledByDefault;
}
uint32_t libinput_device_config_scroll_get_methods(struct libinput_device *device)
{
return device->supportedScrollMethods;
}
enum libinput_config_scroll_method libinput_device_config_scroll_get_default_method(struct libinput_device *device)
{
return device->defaultScrollMethod;
}
enum libinput_config_status libinput_device_config_scroll_set_method(struct libinput_device *device, enum libinput_config_scroll_method method)
{
if (device->setScrollMethodReturnValue == 0) {
if (!(device->supportedScrollMethods & method)) {
return LIBINPUT_CONFIG_STATUS_INVALID;
}
device->scrollMethod = method;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
return LIBINPUT_CONFIG_STATUS_INVALID;
}
enum libinput_config_scroll_method libinput_device_config_scroll_get_method(struct libinput_device *device)
{
return device->scrollMethod;
}
enum libinput_config_status libinput_device_config_scroll_set_button(struct libinput_device *device, uint32_t button)
{
if (device->setScrollButtonReturnValue == 0) {
if (!(device->supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) {
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
device->scrollButton = button;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
return LIBINPUT_CONFIG_STATUS_INVALID;
}
uint32_t libinput_device_config_scroll_get_button(struct libinput_device *device)
{
return device->scrollButton;
}
uint32_t libinput_device_config_scroll_get_default_button(struct libinput_device *device)
{
return device->defaultScrollButton;
}
......@@ -54,6 +54,7 @@ struct libinput_device {
bool supportsDisableEventsOnExternalMouse = false;
bool supportsMiddleEmulation = false;
bool supportsNaturalScroll = false;
quint32 supportedScrollMethods = 0;
bool middleEmulationEnabledByDefault = false;
bool middleEmulation = false;
qreal pointerAcceleration = 0.0;
......@@ -63,6 +64,12 @@ struct libinput_device {
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;
QVector<quint32> keys;
bool enabled = true;
......
......@@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "device.h"
#include <libinput.h>
#include <QDBusConnection>
......@@ -105,11 +104,16 @@ Device::Device(libinput_device *device, QObject *parent)
, 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_supportedScrollMethods(libinput_device_config_scroll_get_methods(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_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device))
, m_defaultScrollButton(libinput_device_config_scroll_get_default_button(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_scrollMethod(libinput_device_config_scroll_get_method(m_device))
, m_scrollButton(libinput_device_config_scroll_get_button(m_device))
, 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)
{
......@@ -205,6 +209,53 @@ void Device::setNaturalScroll(bool set)
}
}
void Device::setScrollMethod(bool set, enum libinput_config_scroll_method method)
{
if (!(m_supportedScrollMethods & method)) {
return;
}
if (set) {
if (m_scrollMethod == method) {
return;
}
} else {
if (m_scrollMethod != method) {
return;
}
method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
}
if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
m_scrollMethod = method;
emit scrollMethodChanged();
}
}
void Device::setScrollTwoFinger(bool set) {
setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG);
}
void Device::setScrollEdge(bool set) {
setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE);
}
void Device::setScrollOnButtonDown(bool set) {
setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
}
void Device::setScrollButton(quint32 button)
{
if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) {
return;
}
if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) {
if (m_scrollButton != button) {
m_scrollButton = button;
emit scrollButtonChanged();
}
}
}
#define CONFIG(method, condition, function, enum, variable) \
void Device::method(bool set) \
{ \
......
......@@ -20,6 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_LIBINPUT_DEVICE_H
#define KWIN_LIBINPUT_DEVICE_H
#include <libinput.h>
#include <QObject>
#include <QSizeF>
#include <QVector>
......@@ -59,11 +61,22 @@ class Device : public QObject
Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT)
Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT)
Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT)
Q_PROPERTY(bool supportsScrollTwoFinger READ supportsScrollTwoFinger CONSTANT)
Q_PROPERTY(bool supportsScrollEdge READ supportsScrollEdge CONSTANT)
Q_PROPERTY(bool supportsScrollOnButtonDown READ supportsScrollOnButtonDown CONSTANT)
Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT)
Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT)
Q_PROPERTY(bool scrollTwoFingerEnabledByDefault READ scrollTwoFingerEnabledByDefault CONSTANT)
Q_PROPERTY(bool scrollEdgeEnabledByDefault READ scrollEdgeEnabledByDefault CONSTANT)
Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT)
Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton 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(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged)
Q_PROPERTY(bool scrollEdge READ isScrollEdge WRITE setScrollEdge NOTIFY scrollMethodChanged)
Q_PROPERTY(bool scrollOnButtonDown READ isScrollOnButtonDown WRITE setScrollOnButtonDown NOTIFY scrollMethodChanged)
Q_PROPERTY(quint32 scrollButton READ scrollButton WRITE setScrollButton NOTIFY scrollButtonChanged)
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)
......@@ -168,12 +181,33 @@ public:
bool supportsNaturalScroll() const {
return m_supportsNaturalScroll;
}
bool supportsScrollTwoFinger() const {
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_2FG);
}
bool supportsScrollEdge() const {
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_EDGE);
}
bool supportsScrollOnButtonDown() const {
return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
}
bool middleEmulationEnabledByDefault() const {
return m_middleEmulationEnabledByDefault;
}
bool naturalScrollEnabledByDefault() const {
return m_naturalScrollEnabledByDefault;
}
bool scrollTwoFingerEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_2FG;
}
bool scrollEdgeEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_EDGE;
}
bool scrollOnButtonDownEnabledByDefault() const {
return m_defaultScrollMethod == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
}
quint32 defaultScrollButton() const {
return m_defaultScrollButton;
}
bool isMiddleEmulation() const {
return m_middleEmulation;
}
......@@ -182,6 +216,23 @@ public:
return m_naturalScroll;
}
void setNaturalScroll(bool set);
void setScrollMethod(bool set, enum libinput_config_scroll_method method);
bool isScrollTwoFinger() const {
return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_2FG;
}
void setScrollTwoFinger(bool set);
bool isScrollEdge() const {
return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_EDGE;
}
void setScrollEdge(bool set);
bool isScrollOnButtonDown() const {
return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
}
void setScrollOnButtonDown(bool set);
quint32 scrollButton() const {
return m_scrollButton;
}
void setScrollButton(quint32 button);
bool isLeftHanded() const {
return m_leftHanded;
......@@ -229,6 +280,8 @@ Q_SIGNALS:
void tapDragLockChanged();
void middleEmulationChanged();
void naturalScrollChanged();
void scrollMethodChanged();
void scrollButtonChanged();
private:
libinput_device *m_device;
......@@ -261,11 +314,18 @@ private:
bool m_supportsDisableEventsOnExternalMouse;
bool m_supportsMiddleEmulation;
bool m_supportsNaturalScroll;
quint32 m_supportedScrollMethods;
bool m_supportsScrollEdge;
bool m_supportsScrollOnButtonDown;
bool m_middleEmulationEnabledByDefault;
bool m_naturalScrollEnabledByDefault;
enum libinput_config_scroll_method m_defaultScrollMethod;
quint32 m_defaultScrollButton;
bool m_middleEmulation;
bool m_leftHanded;
bool m_naturalScroll;
enum libinput_config_scroll_method m_scrollMethod;
quint32 m_scrollButton;
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