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