File indexing completed on 2024-06-23 05:29:34

0001 /*
0002     SPDX-FileCopyrightText: 2018 Roman Gilg <subdiff@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 #include <QString>
0011 
0012 class QDBusInterface;
0013 
0014 class KWinWaylandDevice : public QObject
0015 {
0016     Q_OBJECT
0017 
0018     //
0019     // general
0020     Q_PROPERTY(QString name READ name CONSTANT)
0021     Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT)
0022     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0023 
0024     //
0025     // advanced
0026     Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT)
0027 
0028     Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT)
0029     Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT)
0030     Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged)
0031 
0032     Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT)
0033     Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT)
0034     Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged)
0035 
0036     //
0037     // acceleration speed and profile
0038     Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT)
0039     Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged)
0040 
0041     Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT)
0042     Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT)
0043     Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY
0044                    pointerAccelerationProfileChanged)
0045 
0046     Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT)
0047     Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT)
0048     Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY
0049                    pointerAccelerationProfileChanged)
0050 
0051     //
0052     // scrolling
0053     Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT)
0054     Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT)
0055     Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged)
0056     Q_PROPERTY(qreal scrollFactor READ scrollFactor WRITE setScrollFactor NOTIFY scrollFactorChanged)
0057 
0058 public:
0059     KWinWaylandDevice(const QString &dbusName);
0060     ~KWinWaylandDevice() override;
0061 
0062     bool init();
0063 
0064     bool getDefaultConfig();
0065     bool applyConfig();
0066     bool isChangedConfig() const;
0067 
0068     //
0069     // general
0070     QString name() const
0071     {
0072         return m_name.val;
0073     }
0074     QString sysName() const
0075     {
0076         return m_sysName.val;
0077     }
0078     bool supportsDisableEvents() const
0079     {
0080         return m_supportsDisableEvents.val;
0081     }
0082     void setEnabled(bool enabled)
0083     {
0084         m_enabled.set(enabled);
0085     }
0086     bool isEnabled() const
0087     {
0088         return m_enabled.val;
0089     }
0090     Qt::MouseButtons supportedButtons() const
0091     {
0092         return m_supportedButtons.val;
0093     }
0094 
0095     //
0096     // advanced
0097     bool supportsLeftHanded() const
0098     {
0099         return m_supportsLeftHanded.val;
0100     }
0101     bool leftHandedEnabledByDefault() const
0102     {
0103         return m_leftHandedEnabledByDefault.val;
0104     }
0105     bool isLeftHanded() const
0106     {
0107         return m_leftHanded.val;
0108     }
0109     void setLeftHanded(bool set)
0110     {
0111         m_leftHanded.set(set);
0112     }
0113 
0114     bool supportsMiddleEmulation() const
0115     {
0116         return m_supportsMiddleEmulation.val;
0117     }
0118     bool middleEmulationEnabledByDefault() const
0119     {
0120         return m_middleEmulationEnabledByDefault.val;
0121     }
0122     bool isMiddleEmulation() const
0123     {
0124         return m_middleEmulation.val;
0125     }
0126     void setMiddleEmulation(bool set)
0127     {
0128         m_middleEmulation.set(set);
0129     }
0130 
0131     //
0132     // acceleration speed and profile
0133     bool supportsPointerAcceleration() const
0134     {
0135         return m_supportsPointerAcceleration.val;
0136     }
0137     qreal pointerAcceleration() const
0138     {
0139         return m_pointerAcceleration.val;
0140     }
0141     void setPointerAcceleration(qreal acceleration)
0142     {
0143         m_pointerAcceleration.set(acceleration);
0144     }
0145 
0146     bool supportsPointerAccelerationProfileFlat() const
0147     {
0148         return m_supportsPointerAccelerationProfileFlat.val;
0149     }
0150     bool defaultPointerAccelerationProfileFlat() const
0151     {
0152         return m_defaultPointerAccelerationProfileFlat.val;
0153     }
0154     bool pointerAccelerationProfileFlat() const
0155     {
0156         return m_pointerAccelerationProfileFlat.val;
0157     }
0158     void setPointerAccelerationProfileFlat(bool set)
0159     {
0160         m_pointerAccelerationProfileFlat.set(set);
0161     }
0162 
0163     bool supportsPointerAccelerationProfileAdaptive() const
0164     {
0165         return m_supportsPointerAccelerationProfileAdaptive.val;
0166     }
0167     bool defaultPointerAccelerationProfileAdaptive() const
0168     {
0169         return m_defaultPointerAccelerationProfileAdaptive.val;
0170     }
0171     bool pointerAccelerationProfileAdaptive() const
0172     {
0173         return m_pointerAccelerationProfileAdaptive.val;
0174     }
0175     void setPointerAccelerationProfileAdaptive(bool set)
0176     {
0177         m_pointerAccelerationProfileAdaptive.set(set);
0178     }
0179 
0180     //
0181     // scrolling
0182     bool supportsNaturalScroll() const
0183     {
0184         return m_supportsNaturalScroll.val;
0185     }
0186     bool naturalScrollEnabledByDefault() const
0187     {
0188         return m_naturalScrollEnabledByDefault.val;
0189     }
0190     bool isNaturalScroll() const
0191     {
0192         return m_naturalScroll.val;
0193     }
0194     void setNaturalScroll(bool set)
0195     {
0196         m_naturalScroll.set(set);
0197     }
0198 
0199     qreal scrollFactor() const
0200     {
0201         return m_scrollFactor.val;
0202     }
0203     void setScrollFactor(qreal set)
0204     {
0205         m_scrollFactor.set(set);
0206     }
0207 
0208 Q_SIGNALS:
0209     void leftHandedChanged();
0210     void pointerAccelerationChanged();
0211     void pointerAccelerationProfileChanged();
0212     void enabledChanged();
0213     void middleEmulationChanged();
0214     void naturalScrollChanged();
0215     void scrollFactorChanged();
0216 
0217 private:
0218     template<typename T>
0219     struct Prop {
0220         using value_type = T;
0221         explicit Prop(const char *dbusName)
0222             : dbus(dbusName)
0223         {
0224         }
0225 
0226         void set(T newVal)
0227         {
0228             if (avail && val != newVal) {
0229                 val = newVal;
0230             }
0231         }
0232         void set(const Prop<T> &p)
0233         {
0234             if (avail && val != p.val) {
0235                 val = p.val;
0236             }
0237         }
0238         bool changed() const
0239         {
0240             return avail && (old != val);
0241         }
0242 
0243         QLatin1String dbus;
0244         bool avail;
0245         T old;
0246         T val;
0247     };
0248 
0249     template<typename T>
0250     bool valueLoader(Prop<T> &prop);
0251 
0252     template<typename T>
0253     QString valueWriter(const Prop<T> &prop);
0254 
0255     //
0256     // general
0257     Prop<QString> m_name = Prop<QString>("name");
0258     Prop<QString> m_sysName = Prop<QString>("sysName");
0259     Prop<bool> m_supportsDisableEvents = Prop<bool>("supportsDisableEvents");
0260     Prop<bool> m_enabled = Prop<bool>("enabled");
0261 
0262     //
0263     // advanced
0264     Prop<Qt::MouseButtons> m_supportedButtons = Prop<Qt::MouseButtons>("supportedButtons");
0265 
0266     Prop<bool> m_supportsLeftHanded = Prop<bool>("supportsLeftHanded");
0267     Prop<bool> m_leftHandedEnabledByDefault = Prop<bool>("leftHandedEnabledByDefault");
0268     Prop<bool> m_leftHanded = Prop<bool>("leftHanded");
0269 
0270     Prop<bool> m_supportsMiddleEmulation = Prop<bool>("supportsMiddleEmulation");
0271     Prop<bool> m_middleEmulationEnabledByDefault = Prop<bool>("middleEmulationEnabledByDefault");
0272     Prop<bool> m_middleEmulation = Prop<bool>("middleEmulation");
0273 
0274     //
0275     // acceleration speed and profile
0276     Prop<bool> m_supportsPointerAcceleration = Prop<bool>("supportsPointerAcceleration");
0277     Prop<qreal> m_defaultPointerAcceleration = Prop<qreal>("defaultPointerAcceleration");
0278     Prop<qreal> m_pointerAcceleration = Prop<qreal>("pointerAcceleration");
0279 
0280     Prop<bool> m_supportsPointerAccelerationProfileFlat = Prop<bool>("supportsPointerAccelerationProfileFlat");
0281     Prop<bool> m_defaultPointerAccelerationProfileFlat = Prop<bool>("defaultPointerAccelerationProfileFlat");
0282     Prop<bool> m_pointerAccelerationProfileFlat = Prop<bool>("pointerAccelerationProfileFlat");
0283 
0284     Prop<bool> m_supportsPointerAccelerationProfileAdaptive = Prop<bool>("supportsPointerAccelerationProfileAdaptive");
0285     Prop<bool> m_defaultPointerAccelerationProfileAdaptive = Prop<bool>("defaultPointerAccelerationProfileAdaptive");
0286     Prop<bool> m_pointerAccelerationProfileAdaptive = Prop<bool>("pointerAccelerationProfileAdaptive");
0287 
0288     //
0289     // scrolling
0290     Prop<bool> m_supportsNaturalScroll = Prop<bool>("supportsNaturalScroll");
0291     Prop<bool> m_naturalScrollEnabledByDefault = Prop<bool>("naturalScrollEnabledByDefault");
0292     Prop<bool> m_naturalScroll = Prop<bool>("naturalScroll");
0293     Prop<qreal> m_scrollFactor = Prop<qreal>("scrollFactor");
0294 
0295     QString m_dbusName;
0296 };