File indexing completed on 2025-01-26 05:06:35
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 #include <QtGui/private/qtx11extras_p.h> 0012 0013 #include <X11/Xdefs.h> 0014 0015 struct LibinputSettings; 0016 0017 class X11LibinputDummyDevice : public QObject 0018 { 0019 Q_OBJECT 0020 0021 // 0022 // general 0023 Q_PROPERTY(QString name READ name CONSTANT) 0024 Q_PROPERTY(bool supportsDisableEvents READ supportsDisableEvents CONSTANT) 0025 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) 0026 0027 // 0028 // advanced 0029 Q_PROPERTY(Qt::MouseButtons supportedButtons READ supportedButtons CONSTANT) 0030 0031 Q_PROPERTY(bool supportsLeftHanded READ supportsLeftHanded CONSTANT) 0032 Q_PROPERTY(bool leftHandedEnabledByDefault READ leftHandedEnabledByDefault CONSTANT) 0033 Q_PROPERTY(bool leftHanded READ isLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) 0034 0035 Q_PROPERTY(bool supportsMiddleEmulation READ supportsMiddleEmulation CONSTANT) 0036 Q_PROPERTY(bool middleEmulationEnabledByDefault READ middleEmulationEnabledByDefault CONSTANT) 0037 Q_PROPERTY(bool middleEmulation READ isMiddleEmulation WRITE setMiddleEmulation NOTIFY middleEmulationChanged) 0038 0039 // 0040 // acceleration speed and profile 0041 Q_PROPERTY(bool supportsPointerAcceleration READ supportsPointerAcceleration CONSTANT) 0042 Q_PROPERTY(qreal pointerAcceleration READ pointerAcceleration WRITE setPointerAcceleration NOTIFY pointerAccelerationChanged) 0043 0044 Q_PROPERTY(bool supportsPointerAccelerationProfileFlat READ supportsPointerAccelerationProfileFlat CONSTANT) 0045 Q_PROPERTY(bool defaultPointerAccelerationProfileFlat READ defaultPointerAccelerationProfileFlat CONSTANT) 0046 Q_PROPERTY(bool pointerAccelerationProfileFlat READ pointerAccelerationProfileFlat WRITE setPointerAccelerationProfileFlat NOTIFY 0047 pointerAccelerationProfileChanged) 0048 0049 Q_PROPERTY(bool supportsPointerAccelerationProfileAdaptive READ supportsPointerAccelerationProfileAdaptive CONSTANT) 0050 Q_PROPERTY(bool defaultPointerAccelerationProfileAdaptive READ defaultPointerAccelerationProfileAdaptive CONSTANT) 0051 Q_PROPERTY(bool pointerAccelerationProfileAdaptive READ pointerAccelerationProfileAdaptive WRITE setPointerAccelerationProfileAdaptive NOTIFY 0052 pointerAccelerationProfileChanged) 0053 0054 // 0055 // scrolling 0056 Q_PROPERTY(bool supportsNaturalScroll READ supportsNaturalScroll CONSTANT) 0057 Q_PROPERTY(bool naturalScrollEnabledByDefault READ naturalScrollEnabledByDefault CONSTANT) 0058 Q_PROPERTY(bool naturalScroll READ isNaturalScroll WRITE setNaturalScroll NOTIFY naturalScrollChanged) 0059 0060 public: 0061 X11LibinputDummyDevice(QObject *parent, Display *dpy); 0062 ~X11LibinputDummyDevice() override; 0063 0064 bool getConfig(); 0065 bool getDefaultConfig(); 0066 bool applyConfig(); 0067 bool isChangedConfig() const; 0068 0069 void getDefaultConfigFromX(); 0070 0071 // 0072 // general 0073 QString name() const 0074 { 0075 return m_name.val; 0076 } 0077 QString sysName() const 0078 { 0079 return m_sysName.val; 0080 } 0081 bool supportsDisableEvents() const 0082 { 0083 return m_supportsDisableEvents.val; 0084 } 0085 void setEnabled(bool enabled) 0086 { 0087 m_enabled.set(enabled); 0088 } 0089 bool isEnabled() const 0090 { 0091 return m_enabled.val; 0092 } 0093 Qt::MouseButtons supportedButtons() const 0094 { 0095 return m_supportedButtons.val; 0096 } 0097 0098 // 0099 // advanced 0100 bool supportsLeftHanded() const 0101 { 0102 return m_supportsLeftHanded.val; 0103 } 0104 bool leftHandedEnabledByDefault() const 0105 { 0106 return m_leftHandedEnabledByDefault.val; 0107 } 0108 bool isLeftHanded() const 0109 { 0110 return m_leftHanded.val; 0111 } 0112 void setLeftHanded(bool set) 0113 { 0114 m_leftHanded.set(set); 0115 } 0116 0117 bool supportsMiddleEmulation() const 0118 { 0119 return m_supportsMiddleEmulation.val; 0120 } 0121 bool middleEmulationEnabledByDefault() const 0122 { 0123 return m_middleEmulationEnabledByDefault.val; 0124 } 0125 bool isMiddleEmulation() const 0126 { 0127 return m_middleEmulation.val; 0128 } 0129 void setMiddleEmulation(bool set) 0130 { 0131 m_middleEmulation.set(set); 0132 } 0133 0134 // 0135 // acceleration speed and profile 0136 bool supportsPointerAcceleration() const 0137 { 0138 return m_supportsPointerAcceleration.val; 0139 } 0140 qreal pointerAcceleration() const 0141 { 0142 return m_pointerAcceleration.val; 0143 } 0144 void setPointerAcceleration(qreal acceleration) 0145 { 0146 m_pointerAcceleration.set(acceleration); 0147 } 0148 0149 bool supportsPointerAccelerationProfileFlat() const 0150 { 0151 return m_supportsPointerAccelerationProfileFlat.val; 0152 } 0153 bool defaultPointerAccelerationProfileFlat() const 0154 { 0155 return m_defaultPointerAccelerationProfileFlat.val; 0156 } 0157 bool pointerAccelerationProfileFlat() const 0158 { 0159 return m_pointerAccelerationProfileFlat.val; 0160 } 0161 void setPointerAccelerationProfileFlat(bool set) 0162 { 0163 m_pointerAccelerationProfileFlat.set(set); 0164 } 0165 0166 bool supportsPointerAccelerationProfileAdaptive() const 0167 { 0168 return m_supportsPointerAccelerationProfileAdaptive.val; 0169 } 0170 bool defaultPointerAccelerationProfileAdaptive() const 0171 { 0172 return m_defaultPointerAccelerationProfileAdaptive.val; 0173 } 0174 bool pointerAccelerationProfileAdaptive() const 0175 { 0176 return m_pointerAccelerationProfileAdaptive.val; 0177 } 0178 void setPointerAccelerationProfileAdaptive(bool set) 0179 { 0180 m_pointerAccelerationProfileAdaptive.set(set); 0181 } 0182 0183 // 0184 // scrolling 0185 bool supportsNaturalScroll() const 0186 { 0187 return m_supportsNaturalScroll.val; 0188 } 0189 bool naturalScrollEnabledByDefault() const 0190 { 0191 return m_naturalScrollEnabledByDefault.val; 0192 } 0193 bool isNaturalScroll() const 0194 { 0195 return m_naturalScroll.val; 0196 } 0197 void setNaturalScroll(bool set) 0198 { 0199 m_naturalScroll.set(set); 0200 } 0201 0202 Q_SIGNALS: 0203 void leftHandedChanged(); 0204 void pointerAccelerationChanged(); 0205 void pointerAccelerationProfileChanged(); 0206 void enabledChanged(); 0207 void middleEmulationChanged(); 0208 void naturalScrollChanged(); 0209 0210 private: 0211 template<typename T> 0212 struct Prop { 0213 explicit Prop(const QString &_name, const QString &_cfgName = "") 0214 : name(_name) 0215 , cfgName(_cfgName) 0216 { 0217 } 0218 0219 void set(T newVal) 0220 { 0221 if (avail && val != newVal) { 0222 val = newVal; 0223 } 0224 } 0225 void set(const Prop<T> &p) 0226 { 0227 if (avail && val != p.val) { 0228 val = p.val; 0229 } 0230 } 0231 bool changed() const 0232 { 0233 return avail && (old != val); 0234 } 0235 0236 void reset(T newVal) 0237 { 0238 val = newVal; 0239 old = newVal; 0240 } 0241 0242 QString name; 0243 QString cfgName; 0244 0245 bool avail = true; 0246 T old; 0247 T val; 0248 0249 Atom atom; 0250 }; 0251 0252 template<typename T> 0253 bool valueWriter(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", "XLbInptLeftHanded"); 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", "XLbInptMiddleEmulation"); 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", "XLbInptPointerAcceleration"); 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", "XLbInptAccelProfileFlat"); 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", "XLbInptNaturalScroll"); 0293 0294 LibinputSettings *m_settings; 0295 Display *m_dpy = nullptr; 0296 };