File indexing completed on 2024-05-19 16:33:52

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include "core/inputdevice.h"
0012 
0013 #include <libinput.h>
0014 
0015 #include <KConfigGroup>
0016 
0017 #include <QMatrix4x4>
0018 #include <QObject>
0019 #include <QPointer>
0020 #include <QSizeF>
0021 #include <QVector>
0022 
0023 struct libinput_device;
0024 
0025 namespace KWin
0026 {
0027 class Output;
0028 
0029 namespace LibInput
0030 {
0031 enum class ConfigKey;
0032 
0033 class KWIN_EXPORT Device : public InputDevice
0034 {
0035     Q_OBJECT
0036     Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.InputDevice")
0037     //
0038     // general
0039     Q_PROPERTY(bool keyboard READ isKeyboard CONSTANT)
0040     Q_PROPERTY(bool alphaNumericKeyboard READ isAlphaNumericKeyboard CONSTANT)
0041     Q_PROPERTY(bool pointer READ isPointer CONSTANT)
0042     Q_PROPERTY(bool touchpad READ isTouchpad CONSTANT)
0043     Q_PROPERTY(bool touch READ isTouch CONSTANT)
0044     Q_PROPERTY(bool tabletTool READ isTabletTool CONSTANT)
0045     Q_PROPERTY(bool tabletPad READ isTabletPad CONSTANT)
0046     Q_PROPERTY(bool gestureSupport READ supportsGesture CONSTANT)
0047     Q_PROPERTY(QString name READ name CONSTANT)
0048     Q_PROPERTY(QString sysName READ sysName CONSTANT)
0049     Q_PROPERTY(QString outputName READ outputName WRITE setOutputName NOTIFY outputNameChanged)
0050     Q_PROPERTY(QSizeF size READ size CONSTANT)
0051     Q_PROPERTY(quint32 product READ product CONSTANT)
0052     Q_PROPERTY(quint32 vendor READ vendor CONSTANT)
0053     Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT)
0054     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0055     Q_PROPERTY(bool enabledByDefault READ isEnabledByDefault CONSTANT)
0056     //
0057     // advanced
0058     Q_PROPERTY(int supportedButtons READ supportedButtons CONSTANT)
0059     Q_PROPERTY(bool supportsCalibrationMatrix READ supportsCalibrationMatrix CONSTANT)
0060     Q_PROPERTY(QMatrix4x4 defaultCalibrationMatrix READ defaultCalibrationMatrix CONSTANT)
0061     Q_PROPERTY(QMatrix4x4 calibrationMatrix READ calibrationMatrix WRITE setCalibrationMatrix NOTIFY calibrationMatrixChanged)
0062     Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
0063     Q_PROPERTY(int orientationDBus READ orientation WRITE setOrientationDBus NOTIFY orientationChanged)
0064 
0065     Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT)
0066     Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT)
0067     Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
0068 
0069     Q_PROPERTY(bool supportsDisableEventsOnExternalMouse READ supportsDisableEventsOnExternalMouse CONSTANT)
0070 
0071     Q_PROPERTY(bool supportsDisableWhileTyping READ supportsDisableWhileTyping CONSTANT)
0072     Q_PROPERTY(bool disableWhileTypingEnabledByDefault READ disableWhileTypingEnabledByDefault CONSTANT)
0073     Q_PROPERTY(bool disableWhileTyping READ isDisableWhileTyping WRITE setDisableWhileTyping NOTIFY disableWhileTypingChanged)
0074     //
0075     // acceleration speed and profile
0076     Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT)
0077     Q_PROPERTY(qreal defaultPointerAcceleration READ defaultPointerAcceleration CONSTANT)
0078     Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged)
0079 
0080     Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT)
0081     Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT)
0082     Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY pointerAccelerationProfileChanged)
0083 
0084     Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT)
0085     Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT)
0086     Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY pointerAccelerationProfileChanged)
0087     //
0088     // tapping
0089     Q_PROPERTY(int tapFingerCount READ tapFingerCount CONSTANT)
0090     Q_PROPERTY(bool tapToClickEnabledByDefault READ tapToClickEnabledByDefault CONSTANT)
0091     Q_PROPERTY(bool tapToClick READ isTapToClick WRITE setTapToClick NOTIFY tapToClickChanged)
0092 
0093     Q_PROPERTY(bool supportsLmrTapButtonMap READ supportsLmrTapButtonMap CONSTANT)
0094     Q_PROPERTY(bool lmrTapButtonMapEnabledByDefault READ lmrTapButtonMapEnabledByDefault CONSTANT)
0095     Q_PROPERTY(bool lmrTapButtonMap READ lmrTapButtonMap WRITE setLmrTapButtonMap NOTIFY tapButtonMapChanged)
0096 
0097     Q_PROPERTY(bool tapAndDragEnabledByDefault READ tapAndDragEnabledByDefault CONSTANT)
0098     Q_PROPERTY(bool tapAndDrag READ isTapAndDrag WRITE setTapAndDrag NOTIFY tapAndDragChanged)
0099     Q_PROPERTY(bool tapDragLockEnabledByDefault READ tapDragLockEnabledByDefault CONSTANT)
0100     Q_PROPERTY(bool tapDragLock READ isTapDragLock WRITE setTapDragLock NOTIFY tapDragLockChanged)
0101 
0102     Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT)
0103     Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT)
0104     Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged)
0105     //
0106     // scrolling
0107     Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT)
0108     Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT)
0109     Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged)
0110 
0111     Q_PROPERTY(bool supportsScrollTwoFinger READ supportsScrollTwoFinger CONSTANT)
0112     Q_PROPERTY(bool scrollTwoFingerEnabledByDefault READ scrollTwoFingerEnabledByDefault CONSTANT)
0113     Q_PROPERTY(bool scrollTwoFinger READ isScrollTwoFinger WRITE setScrollTwoFinger NOTIFY scrollMethodChanged)
0114 
0115     Q_PROPERTY(bool supportsScrollEdge READ supportsScrollEdge CONSTANT)
0116     Q_PROPERTY(bool scrollEdgeEnabledByDefault READ scrollEdgeEnabledByDefault CONSTANT)
0117     Q_PROPERTY(bool scrollEdge READ isScrollEdge WRITE setScrollEdge NOTIFY scrollMethodChanged)
0118 
0119     Q_PROPERTY(bool supportsScrollOnButtonDown READ supportsScrollOnButtonDown CONSTANT)
0120     Q_PROPERTY(bool scrollOnButtonDownEnabledByDefault READ scrollOnButtonDownEnabledByDefault CONSTANT)
0121     Q_PROPERTY(quint32 defaultScrollButton READ defaultScrollButton CONSTANT)
0122     Q_PROPERTY(bool scrollOnButtonDown READ isScrollOnButtonDown WRITE setScrollOnButtonDown NOTIFY scrollMethodChanged)
0123     Q_PROPERTY(quint32 scrollButton READ scrollButton WRITE setScrollButton NOTIFY scrollButtonChanged)
0124 
0125     Q_PROPERTY(qreal scrollFactor READ scrollFactor WRITE setScrollFactor NOTIFY scrollFactorChanged)
0126     //
0127     // switches
0128     Q_PROPERTY(bool switchDevice READ isSwitch CONSTANT)
0129     Q_PROPERTY(bool lidSwitch READ isLidSwitch CONSTANT)
0130     Q_PROPERTY(bool tabletModeSwitch READ isTabletModeSwitch CONSTANT)
0131 
0132     // Click Methods
0133     Q_PROPERTY(bool supportsClickMethodAreas READ supportsClickMethodAreas CONSTANT)
0134     Q_PROPERTY(bool defaultClickMethodAreas READ defaultClickMethodAreas CONSTANT)
0135     Q_PROPERTY(bool clickMethodAreas READ isClickMethodAreas WRITE setClickMethodAreas NOTIFY clickMethodChanged)
0136 
0137     Q_PROPERTY(bool supportsClickMethodClickfinger READ supportsClickMethodClickfinger CONSTANT)
0138     Q_PROPERTY(bool defaultClickMethodClickfinger READ defaultClickMethodClickfinger CONSTANT)
0139     Q_PROPERTY(bool clickMethodClickfinger READ isClickMethodClickfinger WRITE setClickMethodClickfinger NOTIFY clickMethodChanged)
0140 
0141     Q_PROPERTY(bool supportsOutputArea READ supportsOutputArea CONSTANT)
0142     Q_PROPERTY(QRectF defaultOutputArea READ defaultOutputArea CONSTANT)
0143     Q_PROPERTY(QRectF outputArea READ outputArea WRITE setOutputArea NOTIFY outputAreaChanged)
0144 
0145 public:
0146     explicit Device(libinput_device *device, QObject *parent = nullptr);
0147     ~Device() override;
0148 
0149     bool isKeyboard() const override
0150     {
0151         return m_keyboard;
0152     }
0153     bool isAlphaNumericKeyboard() const override
0154     {
0155         return m_alphaNumericKeyboard;
0156     }
0157     bool isPointer() const override
0158     {
0159         return m_pointer;
0160     }
0161     bool isTouchpad() const override
0162     {
0163         return m_pointer &&
0164             // ignore all combined devices. E.g. a touchpad on a keyboard we don't want to toggle
0165             // as that would result in the keyboard going off as well
0166             !(m_keyboard || m_touch || m_tabletPad || m_tabletTool) &&
0167             // is this a touch pad? We don't really know, let's do some assumptions
0168             (m_tapFingerCount > 0 || m_supportsDisableWhileTyping || m_supportsDisableEventsOnExternalMouse);
0169     }
0170     bool isTouch() const override
0171     {
0172         return m_touch;
0173     }
0174     bool isTabletTool() const override
0175     {
0176         return m_tabletTool;
0177     }
0178     bool isTabletPad() const override
0179     {
0180         return m_tabletPad;
0181     }
0182     bool supportsGesture() const
0183     {
0184         return m_supportsGesture;
0185     }
0186     QString name() const override
0187     {
0188         return m_name;
0189     }
0190     QString sysName() const override
0191     {
0192         return m_sysName;
0193     }
0194     QString outputName() const override
0195     {
0196         return m_outputName;
0197     }
0198     QSizeF size() const
0199     {
0200         return m_size;
0201     }
0202     quint32 product() const
0203     {
0204         return m_product;
0205     }
0206     quint32 vendor() const
0207     {
0208         return m_vendor;
0209     }
0210     Qt::MouseButtons supportedButtons() const
0211     {
0212         return m_supportedButtons;
0213     }
0214     int tapFingerCount() const
0215     {
0216         return m_tapFingerCount;
0217     }
0218     bool tapToClickEnabledByDefault() const
0219     {
0220         return defaultValue("TapToClick", m_tapToClickEnabledByDefault);
0221     }
0222     bool isTapToClick() const
0223     {
0224         return m_tapToClick;
0225     }
0226     /**
0227      * Set the Device to tap to click if @p set is @c true.
0228      */
0229     void setTapToClick(bool set);
0230     bool tapAndDragEnabledByDefault() const
0231     {
0232         return defaultValue("TapAndDrag", m_tapAndDragEnabledByDefault);
0233     }
0234     bool isTapAndDrag() const
0235     {
0236         return m_tapAndDrag;
0237     }
0238     void setTapAndDrag(bool set);
0239     bool tapDragLockEnabledByDefault() const
0240     {
0241         return defaultValue("TapDragLock", m_tapDragLockEnabledByDefault);
0242     }
0243     bool isTapDragLock() const
0244     {
0245         return m_tapDragLock;
0246     }
0247     void setTapDragLock(bool set);
0248     bool supportsDisableWhileTyping() const
0249     {
0250         return m_supportsDisableWhileTyping;
0251     }
0252     bool disableWhileTypingEnabledByDefault() const
0253     {
0254         return defaultValue("DisableWhileTyping", m_disableWhileTypingEnabledByDefault);
0255     }
0256     bool supportsPointerAcceleration() const
0257     {
0258         return m_supportsPointerAcceleration;
0259     }
0260     bool supportsLeftHanded() const
0261     {
0262         return m_supportsLeftHanded;
0263     }
0264     bool supportsCalibrationMatrix() const
0265     {
0266         return m_supportsCalibrationMatrix;
0267     }
0268     bool supportsDisableEvents() const
0269     {
0270         return m_supportsDisableEvents;
0271     }
0272     bool supportsDisableEventsOnExternalMouse() const
0273     {
0274         return m_supportsDisableEventsOnExternalMouse;
0275     }
0276     bool supportsMiddleEmulation() const
0277     {
0278         return m_supportsMiddleEmulation;
0279     }
0280     bool supportsNaturalScroll() const
0281     {
0282         return m_supportsNaturalScroll;
0283     }
0284     bool supportsScrollTwoFinger() const
0285     {
0286         return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_2FG);
0287     }
0288     bool supportsScrollEdge() const
0289     {
0290         return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_EDGE);
0291     }
0292     bool supportsScrollOnButtonDown() const
0293     {
0294         return (m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
0295     }
0296     bool leftHandedEnabledByDefault() const
0297     {
0298         return defaultValue("LeftHanded", m_leftHandedEnabledByDefault);
0299     }
0300     bool middleEmulationEnabledByDefault() const
0301     {
0302         return defaultValue("MiddleButtonEmulation", m_middleEmulationEnabledByDefault);
0303     }
0304     bool naturalScrollEnabledByDefault() const
0305     {
0306         return defaultValue("NaturalScroll", m_naturalScrollEnabledByDefault);
0307     }
0308     enum libinput_config_scroll_method defaultScrollMethod() const
0309     {
0310         quint32 defaultScrollMethod = defaultValue("ScrollMethod", static_cast<quint32>(m_defaultScrollMethod));
0311         return static_cast<libinput_config_scroll_method>(defaultScrollMethod);
0312     }
0313     quint32 defaultScrollMethodToInt() const
0314     {
0315         return static_cast<quint32>(defaultScrollMethod());
0316     }
0317     bool scrollTwoFingerEnabledByDefault() const
0318     {
0319         return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_2FG;
0320     }
0321     bool scrollEdgeEnabledByDefault() const
0322     {
0323         return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_EDGE;
0324     }
0325     bool scrollOnButtonDownEnabledByDefault() const
0326     {
0327         return defaultScrollMethod() == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
0328     }
0329     bool supportsLmrTapButtonMap() const
0330     {
0331         return m_tapFingerCount > 1;
0332     }
0333     bool lmrTapButtonMapEnabledByDefault() const
0334     {
0335         quint32 lmrButtonMap = defaultValue("LmrTapButtonMap", static_cast<quint32>(m_defaultTapButtonMap));
0336         return lmrButtonMap == LIBINPUT_CONFIG_TAP_MAP_LMR;
0337     }
0338 
0339     void setLmrTapButtonMap(bool set);
0340     bool lmrTapButtonMap() const
0341     {
0342         return m_tapButtonMap & LIBINPUT_CONFIG_TAP_MAP_LMR;
0343     }
0344 
0345     quint32 defaultScrollButton() const
0346     {
0347         return m_defaultScrollButton;
0348     }
0349     bool isMiddleEmulation() const
0350     {
0351         return m_middleEmulation;
0352     }
0353     void setMiddleEmulation(bool set);
0354     bool isNaturalScroll() const
0355     {
0356         return m_naturalScroll;
0357     }
0358     void setNaturalScroll(bool set);
0359     void setScrollMethod(bool set, enum libinput_config_scroll_method method);
0360     bool isScrollTwoFinger() const
0361     {
0362         return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_2FG;
0363     }
0364     void setScrollTwoFinger(bool set)
0365     {
0366         setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG);
0367     }
0368     bool isScrollEdge() const
0369     {
0370         return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_EDGE;
0371     }
0372     void setScrollEdge(bool set)
0373     {
0374         setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE);
0375     }
0376     bool isScrollOnButtonDown() const
0377     {
0378         return m_scrollMethod & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
0379     }
0380     void setScrollOnButtonDown(bool set)
0381     {
0382         setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
0383     }
0384     void activateScrollMethodFromInt(quint32 method)
0385     {
0386         setScrollMethod(true, (libinput_config_scroll_method)method);
0387     }
0388     quint32 scrollButton() const
0389     {
0390         return m_scrollButton;
0391     }
0392     void setScrollButton(quint32 button);
0393 
0394     qreal scrollFactorDefault() const
0395     {
0396         return defaultValue("ScrollFactor", 1.0);
0397     }
0398     qreal scrollFactor() const
0399     {
0400         return m_scrollFactor;
0401     }
0402     void setScrollFactor(qreal factor);
0403 
0404     void setDisableWhileTyping(bool set);
0405     bool isDisableWhileTyping() const
0406     {
0407         return m_disableWhileTyping;
0408     }
0409     bool isLeftHanded() const
0410     {
0411         return m_leftHanded;
0412     }
0413     /**
0414      * Sets the Device to left handed mode if @p set is @c true.
0415      * If @p set is @c false the device is set to right handed mode
0416      */
0417     void setLeftHanded(bool set);
0418 
0419     QMatrix4x4 defaultCalibrationMatrix() const
0420     {
0421         auto list = defaultValue("CalibrationMatrix", QList<float>{});
0422         if (list.size() == 16) {
0423             return QMatrix4x4{list.toVector().constData()};
0424         }
0425 
0426         return m_defaultCalibrationMatrix;
0427     }
0428     QMatrix4x4 calibrationMatrix() const
0429     {
0430         return m_calibrationMatrix;
0431     }
0432     void setCalibrationMatrix(const QMatrix4x4 &matrix);
0433 
0434     Qt::ScreenOrientation defaultOrientation() const
0435     {
0436         quint32 orientation = defaultValue("Orientation", static_cast<quint32>(Qt::PrimaryOrientation));
0437         return static_cast<Qt::ScreenOrientation>(orientation);
0438     }
0439     Qt::ScreenOrientation orientation() const
0440     {
0441         return m_orientation;
0442     }
0443     void setOrientation(Qt::ScreenOrientation orientation);
0444     void setOrientationDBus(int orientation)
0445     {
0446         setOrientation(Qt::ScreenOrientation(orientation));
0447     }
0448 
0449     qreal defaultPointerAcceleration() const
0450     {
0451         return m_defaultPointerAcceleration;
0452     }
0453     qreal pointerAcceleration() const
0454     {
0455         return m_pointerAcceleration;
0456     }
0457     /**
0458      * @param acceleration mapped to range [-1,1] with -1 being the slowest, 1 being the fastest supported acceleration.
0459      */
0460     void setPointerAcceleration(qreal acceleration);
0461     void setPointerAccelerationFromString(const QString &acceleration)
0462     {
0463         setPointerAcceleration(acceleration.toDouble());
0464     }
0465     QString defaultPointerAccelerationToString() const
0466     {
0467         return QString::number(m_pointerAcceleration, 'f', 3);
0468     }
0469     bool supportsPointerAccelerationProfileFlat() const
0470     {
0471         return (m_supportedPointerAccelerationProfiles & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT);
0472     }
0473     bool supportsPointerAccelerationProfileAdaptive() const
0474     {
0475         return (m_supportedPointerAccelerationProfiles & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
0476     }
0477     bool defaultPointerAccelerationProfileFlat() const
0478     {
0479         return (m_defaultPointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT);
0480     }
0481     bool defaultPointerAccelerationProfileAdaptive() const
0482     {
0483         return (m_defaultPointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
0484     }
0485     bool pointerAccelerationProfileFlat() const
0486     {
0487         return (m_pointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT);
0488     }
0489     bool pointerAccelerationProfileAdaptive() const
0490     {
0491         return (m_pointerAccelerationProfile & LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
0492     }
0493     void setPointerAccelerationProfile(bool set, enum libinput_config_accel_profile profile);
0494     void setPointerAccelerationProfileFlat(bool set)
0495     {
0496         setPointerAccelerationProfile(set, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT);
0497     }
0498     void setPointerAccelerationProfileAdaptive(bool set)
0499     {
0500         setPointerAccelerationProfile(set, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE);
0501     }
0502     void setPointerAccelerationProfileFromInt(quint32 profile)
0503     {
0504         setPointerAccelerationProfile(true, (libinput_config_accel_profile)profile);
0505     }
0506     quint32 defaultPointerAccelerationProfileToInt() const
0507     {
0508         return defaultValue("PointerAccelerationProfile", static_cast<quint32>(m_defaultPointerAccelerationProfile));
0509     }
0510     bool supportsClickMethodAreas() const
0511     {
0512         return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
0513     }
0514     bool defaultClickMethodAreas() const
0515     {
0516         return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
0517     }
0518     bool isClickMethodAreas() const
0519     {
0520         return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
0521     }
0522     bool supportsClickMethodClickfinger() const
0523     {
0524         return (m_supportedClickMethods & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
0525     }
0526     bool defaultClickMethodClickfinger() const
0527     {
0528         return (defaultClickMethod() == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
0529     }
0530     bool isClickMethodClickfinger() const
0531     {
0532         return (m_clickMethod == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
0533     }
0534     void setClickMethod(bool set, enum libinput_config_click_method method);
0535     void setClickMethodAreas(bool set)
0536     {
0537         setClickMethod(set, LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
0538     }
0539     void setClickMethodClickfinger(bool set)
0540     {
0541         setClickMethod(set, LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
0542     }
0543     void setClickMethodFromInt(quint32 method)
0544     {
0545         setClickMethod(true, (libinput_config_click_method)method);
0546     }
0547     libinput_config_click_method defaultClickMethod() const
0548     {
0549         return static_cast<libinput_config_click_method>(defaultClickMethodToInt());
0550     }
0551     quint32 defaultClickMethodToInt() const
0552     {
0553         return defaultValue("ClickMethod", static_cast<quint32>(m_defaultClickMethod));
0554     }
0555 
0556     bool isEnabled() const override
0557     {
0558         return m_enabled;
0559     }
0560     void setEnabled(bool enabled) override;
0561 
0562     bool isEnabledByDefault() const
0563     {
0564         return defaultValue("Enabled", true);
0565     }
0566 
0567     libinput_device *device() const
0568     {
0569         return m_device;
0570     }
0571 
0572     /**
0573      * Sets the @p config to load the Device configuration from and to store each
0574      * successful Device configuration.
0575      */
0576     void setConfig(const KConfigGroup &config)
0577     {
0578         m_config = config;
0579     }
0580 
0581     void setDefaultConfig(const KConfigGroup &config)
0582     {
0583         m_defaultConfig = config;
0584     }
0585 
0586     /**
0587      * Used to deserialize monitor data from KConfig when initializing a device
0588      */
0589     void setOutputName(const QString &uuid) override;
0590     QString defaultOutputName() const
0591     {
0592         return {};
0593     }
0594 
0595     /**
0596      * Loads the configuration and applies it to the Device
0597      */
0598     void loadConfiguration();
0599 
0600     bool isSwitch() const
0601     {
0602         return m_switch;
0603     }
0604 
0605     bool isLidSwitch() const override
0606     {
0607         return m_lidSwitch;
0608     }
0609 
0610     bool isTabletModeSwitch() const override
0611     {
0612         return m_tabletSwitch;
0613     }
0614 
0615     int stripsCount() const;
0616     int ringsCount() const;
0617 
0618     void *groupUserData() const;
0619 
0620     Output *output() const;
0621     void setOutput(Output *output);
0622 
0623     LEDs leds() const override;
0624     void setLeds(LEDs leds) override;
0625 
0626     QRectF defaultOutputArea() const;
0627     bool supportsOutputArea() const;
0628     QRectF outputArea() const;
0629     void setOutputArea(const QRectF &outputArea);
0630 
0631     /**
0632      * Gets the Device for @p native. @c null if there is no Device for @p native.
0633      */
0634     static Device *get(libinput_device *native);
0635 
0636 Q_SIGNALS:
0637     void tapButtonMapChanged();
0638     void calibrationMatrixChanged();
0639     void orientationChanged();
0640     void outputNameChanged();
0641     void leftHandedChanged();
0642     void disableWhileTypingChanged();
0643     void pointerAccelerationChanged();
0644     void pointerAccelerationProfileChanged();
0645     void enabledChanged();
0646     void tapToClickChanged();
0647     void tapAndDragChanged();
0648     void tapDragLockChanged();
0649     void middleEmulationChanged();
0650     void naturalScrollChanged();
0651     void scrollMethodChanged();
0652     void scrollButtonChanged();
0653     void scrollFactorChanged();
0654     void clickMethodChanged();
0655     void outputAreaChanged();
0656 
0657 private:
0658     template<typename T>
0659     void writeEntry(const ConfigKey &key, const T &value);
0660 
0661     template<typename T>
0662     T defaultValue(const char *key, const T &fallback) const
0663     {
0664         if (m_defaultConfig.isValid() && m_defaultConfig.hasKey(key)) {
0665             return m_defaultConfig.readEntry(key, fallback);
0666         }
0667 
0668         return fallback;
0669     }
0670 
0671     libinput_device *m_device;
0672     bool m_keyboard;
0673     bool m_alphaNumericKeyboard = false;
0674     bool m_pointer;
0675     bool m_touch;
0676     bool m_tabletTool;
0677     bool m_tabletPad;
0678     bool m_supportsGesture;
0679     bool m_switch = false;
0680     bool m_lidSwitch = false;
0681     bool m_tabletSwitch = false;
0682     QString m_name;
0683     QString m_sysName;
0684     QString m_outputName;
0685     QSizeF m_size;
0686     quint32 m_product;
0687     quint32 m_vendor;
0688     Qt::MouseButtons m_supportedButtons = Qt::NoButton;
0689     int m_tapFingerCount;
0690     enum libinput_config_tap_button_map m_defaultTapButtonMap;
0691     enum libinput_config_tap_button_map m_tapButtonMap;
0692     bool m_tapToClickEnabledByDefault;
0693     bool m_tapToClick;
0694     bool m_tapAndDragEnabledByDefault;
0695     bool m_tapAndDrag;
0696     bool m_tapDragLockEnabledByDefault;
0697     bool m_tapDragLock;
0698     bool m_supportsDisableWhileTyping;
0699     bool m_supportsPointerAcceleration;
0700     bool m_supportsLeftHanded;
0701     bool m_supportsCalibrationMatrix;
0702     bool m_supportsDisableEvents;
0703     bool m_supportsDisableEventsOnExternalMouse;
0704     bool m_supportsMiddleEmulation;
0705     bool m_supportsNaturalScroll;
0706     quint32 m_supportedScrollMethods;
0707     bool m_supportsScrollEdge;
0708     bool m_supportsScrollOnButtonDown;
0709     bool m_leftHandedEnabledByDefault;
0710     bool m_middleEmulationEnabledByDefault;
0711     bool m_naturalScrollEnabledByDefault;
0712     enum libinput_config_scroll_method m_defaultScrollMethod;
0713     quint32 m_defaultScrollButton;
0714     bool m_disableWhileTypingEnabledByDefault;
0715     bool m_disableWhileTyping;
0716     bool m_middleEmulation;
0717     bool m_leftHanded;
0718     bool m_naturalScroll;
0719     enum libinput_config_scroll_method m_scrollMethod;
0720     quint32 m_scrollButton;
0721     qreal m_defaultPointerAcceleration;
0722     qreal m_pointerAcceleration;
0723     qreal m_scrollFactor;
0724     quint32 m_supportedPointerAccelerationProfiles;
0725     enum libinput_config_accel_profile m_defaultPointerAccelerationProfile;
0726     enum libinput_config_accel_profile m_pointerAccelerationProfile;
0727     bool m_enabled;
0728 
0729     KConfigGroup m_config;
0730     KConfigGroup m_defaultConfig;
0731     bool m_loading = false;
0732 
0733     QPointer<Output> m_output;
0734     Qt::ScreenOrientation m_orientation = Qt::PrimaryOrientation;
0735     QMatrix4x4 m_defaultCalibrationMatrix;
0736     QMatrix4x4 m_calibrationMatrix;
0737     quint32 m_supportedClickMethods;
0738     enum libinput_config_click_method m_defaultClickMethod;
0739     enum libinput_config_click_method m_clickMethod;
0740 
0741     LEDs m_leds;
0742     QRectF m_outputArea = QRectF(0, 0, 1, 1);
0743 };
0744 
0745 }
0746 }
0747 
0748 Q_DECLARE_METATYPE(KWin::LibInput::Device *)