Changeset View
Changeset View
Standalone View
Standalone View
libinput/device.cpp
Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 73 | enum class ConfigKey { | |||
---|---|---|---|---|---|
79 | TapToClick, | 79 | TapToClick, | ||
80 | LmrTapButtonMap, | 80 | LmrTapButtonMap, | ||
81 | TapAndDrag, | 81 | TapAndDrag, | ||
82 | TapDragLock, | 82 | TapDragLock, | ||
83 | MiddleButtonEmulation, | 83 | MiddleButtonEmulation, | ||
84 | NaturalScroll, | 84 | NaturalScroll, | ||
85 | ScrollMethod, | 85 | ScrollMethod, | ||
86 | ScrollButton, | 86 | ScrollButton, | ||
87 | ClickMethod | 87 | ClickMethod, | ||
88 | ScrollFactor | ||||
88 | }; | 89 | }; | ||
89 | 90 | | |||
90 | struct ConfigData { | 91 | struct ConfigData { | ||
91 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(bool), bool (Device::*_defaultValue)() const = nullptr) | 92 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(bool), bool (Device::*_defaultValue)() const = nullptr) | ||
92 | : key(_key) | 93 | : key(_key) | ||
93 | { booleanSetter.setter = _setter; booleanSetter.defaultValue = _defaultValue; } | 94 | { booleanSetter.setter = _setter; booleanSetter.defaultValue = _defaultValue; } | ||
94 | 95 | | |||
95 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(quint32), quint32 (Device::*_defaultValue)() const = nullptr) | 96 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(quint32), quint32 (Device::*_defaultValue)() const = nullptr) | ||
96 | : key(_key) | 97 | : key(_key) | ||
97 | { quint32Setter.setter = _setter; quint32Setter.defaultValue = _defaultValue; } | 98 | { quint32Setter.setter = _setter; quint32Setter.defaultValue = _defaultValue; } | ||
98 | 99 | | |||
99 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(QString), QString (Device::*_defaultValue)() const = nullptr) | 100 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(QString), QString (Device::*_defaultValue)() const = nullptr) | ||
100 | : key(_key) | 101 | : key(_key) | ||
101 | { stringSetter.setter = _setter; stringSetter.defaultValue = _defaultValue; } | 102 | { stringSetter.setter = _setter; stringSetter.defaultValue = _defaultValue; } | ||
102 | 103 | | |||
104 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(qreal), qreal (Device::*_defaultValue)() const = nullptr) | ||||
105 | : key(_key) | ||||
106 | { qrealSetter.setter = _setter; qrealSetter.defaultValue = _defaultValue; } | ||||
107 | | ||||
103 | QByteArray key; | 108 | QByteArray key; | ||
104 | 109 | | |||
105 | struct { | 110 | struct { | ||
106 | void (Device::*setter)(bool) = nullptr; | 111 | void (Device::*setter)(bool) = nullptr; | ||
107 | bool (Device::*defaultValue)() const; | 112 | bool (Device::*defaultValue)() const; | ||
108 | } booleanSetter; | 113 | } booleanSetter; | ||
109 | 114 | | |||
110 | struct { | 115 | struct { | ||
111 | void (Device::*setter)(quint32) = nullptr; | 116 | void (Device::*setter)(quint32) = nullptr; | ||
112 | quint32 (Device::*defaultValue)() const; | 117 | quint32 (Device::*defaultValue)() const; | ||
113 | } quint32Setter; | 118 | } quint32Setter; | ||
114 | struct { | 119 | struct { | ||
115 | void (Device::*setter)(QString) = nullptr; | 120 | void (Device::*setter)(QString) = nullptr; | ||
116 | QString (Device::*defaultValue)() const; | 121 | QString (Device::*defaultValue)() const; | ||
117 | } stringSetter; | 122 | } stringSetter; | ||
123 | struct { | ||||
124 | void (Device::*setter)(qreal) = nullptr; | ||||
125 | qreal (Device::*defaultValue)() const; | ||||
126 | } qrealSetter; | ||||
118 | }; | 127 | }; | ||
119 | 128 | | |||
120 | static const QMap<ConfigKey, ConfigData> s_configData { | 129 | static const QMap<ConfigKey, ConfigData> s_configData { | ||
121 | {ConfigKey::Enabled, ConfigData(QByteArrayLiteral("Enabled"), &Device::setEnabled)}, | 130 | {ConfigKey::Enabled, ConfigData(QByteArrayLiteral("Enabled"), &Device::setEnabled)}, | ||
122 | {ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)}, | 131 | {ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)}, | ||
123 | {ConfigKey::DisableWhileTyping, ConfigData(QByteArrayLiteral("DisableWhileTyping"), &Device::setDisableWhileTyping, &Device::disableWhileTypingEnabledByDefault)}, | 132 | {ConfigKey::DisableWhileTyping, ConfigData(QByteArrayLiteral("DisableWhileTyping"), &Device::setDisableWhileTyping, &Device::disableWhileTypingEnabledByDefault)}, | ||
124 | {ConfigKey::PointerAcceleration, ConfigData(QByteArrayLiteral("PointerAcceleration"), &Device::setPointerAccelerationFromString, &Device::defaultPointerAccelerationToString)}, | 133 | {ConfigKey::PointerAcceleration, ConfigData(QByteArrayLiteral("PointerAcceleration"), &Device::setPointerAccelerationFromString, &Device::defaultPointerAccelerationToString)}, | ||
125 | {ConfigKey::PointerAccelerationProfile, ConfigData(QByteArrayLiteral("PointerAccelerationProfile"), &Device::setPointerAccelerationProfileFromInt, &Device::defaultPointerAccelerationProfileToInt)}, | 134 | {ConfigKey::PointerAccelerationProfile, ConfigData(QByteArrayLiteral("PointerAccelerationProfile"), &Device::setPointerAccelerationProfileFromInt, &Device::defaultPointerAccelerationProfileToInt)}, | ||
126 | {ConfigKey::TapToClick, ConfigData(QByteArrayLiteral("TapToClick"), &Device::setTapToClick, &Device::tapToClickEnabledByDefault)}, | 135 | {ConfigKey::TapToClick, ConfigData(QByteArrayLiteral("TapToClick"), &Device::setTapToClick, &Device::tapToClickEnabledByDefault)}, | ||
127 | {ConfigKey::TapAndDrag, ConfigData(QByteArrayLiteral("TapAndDrag"), &Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault)}, | 136 | {ConfigKey::TapAndDrag, ConfigData(QByteArrayLiteral("TapAndDrag"), &Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault)}, | ||
128 | {ConfigKey::TapDragLock, ConfigData(QByteArrayLiteral("TapDragLock"), &Device::setTapDragLock, &Device::tapDragLockEnabledByDefault)}, | 137 | {ConfigKey::TapDragLock, ConfigData(QByteArrayLiteral("TapDragLock"), &Device::setTapDragLock, &Device::tapDragLockEnabledByDefault)}, | ||
129 | {ConfigKey::MiddleButtonEmulation, ConfigData(QByteArrayLiteral("MiddleButtonEmulation"), &Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault)}, | 138 | {ConfigKey::MiddleButtonEmulation, ConfigData(QByteArrayLiteral("MiddleButtonEmulation"), &Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault)}, | ||
130 | {ConfigKey::LmrTapButtonMap, ConfigData(QByteArrayLiteral("LmrTapButtonMap"), &Device::setLmrTapButtonMap, &Device::lmrTapButtonMapEnabledByDefault)}, | 139 | {ConfigKey::LmrTapButtonMap, ConfigData(QByteArrayLiteral("LmrTapButtonMap"), &Device::setLmrTapButtonMap, &Device::lmrTapButtonMapEnabledByDefault)}, | ||
131 | {ConfigKey::NaturalScroll, ConfigData(QByteArrayLiteral("NaturalScroll"), &Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault)}, | 140 | {ConfigKey::NaturalScroll, ConfigData(QByteArrayLiteral("NaturalScroll"), &Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault)}, | ||
132 | {ConfigKey::ScrollMethod, ConfigData(QByteArrayLiteral("ScrollMethod"), &Device::activateScrollMethodFromInt, &Device::defaultScrollMethodToInt)}, | 141 | {ConfigKey::ScrollMethod, ConfigData(QByteArrayLiteral("ScrollMethod"), &Device::activateScrollMethodFromInt, &Device::defaultScrollMethodToInt)}, | ||
133 | {ConfigKey::ScrollButton, ConfigData(QByteArrayLiteral("ScrollButton"), &Device::setScrollButton, &Device::defaultScrollButton)}, | 142 | {ConfigKey::ScrollButton, ConfigData(QByteArrayLiteral("ScrollButton"), &Device::setScrollButton, &Device::defaultScrollButton)}, | ||
134 | {ConfigKey::ClickMethod, ConfigData(QByteArrayLiteral("ClickMethod"), &Device::setClickMethodFromInt, &Device::defaultClickMethodToInt)} | 143 | {ConfigKey::ClickMethod, ConfigData(QByteArrayLiteral("ClickMethod"), &Device::setClickMethodFromInt, &Device::defaultClickMethodToInt)}, | ||
144 | {ConfigKey::ScrollFactor, ConfigData(QByteArrayLiteral("ScrollFactor"), &Device::setScrollFactor, &Device::ScrollFactorDefault)} | ||||
135 | }; | 145 | }; | ||
136 | 146 | | |||
137 | namespace { | 147 | namespace { | ||
138 | QMatrix4x4 defaultCalibrationMatrix(libinput_device *device) | 148 | QMatrix4x4 defaultCalibrationMatrix(libinput_device *device) | ||
139 | { | 149 | { | ||
140 | float matrix[6]; | 150 | float matrix[6]; | ||
141 | const int ret = libinput_device_config_calibration_get_default_matrix(device, matrix); | 151 | const int ret = libinput_device_config_calibration_get_default_matrix(device, matrix); | ||
142 | if (ret == 0) { | 152 | if (ret == 0) { | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 164 | Device::Device(libinput_device *device, QObject *parent) | |||
204 | , m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device)) | 214 | , m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device)) | ||
205 | , m_pointerAccelerationProfile(libinput_device_config_accel_get_profile(m_device)) | 215 | , m_pointerAccelerationProfile(libinput_device_config_accel_get_profile(m_device)) | ||
206 | , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) | 216 | , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) | ||
207 | , m_config() | 217 | , m_config() | ||
208 | , m_defaultCalibrationMatrix(m_supportsCalibrationMatrix ? defaultCalibrationMatrix(m_device) : QMatrix4x4{}) | 218 | , m_defaultCalibrationMatrix(m_supportsCalibrationMatrix ? defaultCalibrationMatrix(m_device) : QMatrix4x4{}) | ||
209 | , m_supportedClickMethods(libinput_device_config_click_get_methods(m_device)) | 219 | , m_supportedClickMethods(libinput_device_config_click_get_methods(m_device)) | ||
210 | , m_defaultClickMethod(libinput_device_config_click_get_default_method(m_device)) | 220 | , m_defaultClickMethod(libinput_device_config_click_get_default_method(m_device)) | ||
211 | , m_clickMethod(libinput_device_config_click_get_method(m_device)) | 221 | , m_clickMethod(libinput_device_config_click_get_method(m_device)) | ||
222 | , m_scrollFactor(ScrollFactorDefault()) | ||||
212 | { | 223 | { | ||
213 | libinput_device_ref(m_device); | 224 | libinput_device_ref(m_device); | ||
214 | 225 | | |||
215 | qreal width = 0; | 226 | qreal width = 0; | ||
216 | qreal height = 0; | 227 | qreal height = 0; | ||
217 | if (libinput_device_get_size(m_device, &width, &height) == 0) { | 228 | if (libinput_device_get_size(m_device, &width, &height) == 0) { | ||
218 | m_size = QSizeF(width, height); | 229 | m_size = QSizeF(width, height); | ||
219 | } | 230 | } | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 302 | { | |||
296 | for (auto it = s_configData.begin(), end = s_configData.end(); it != end; ++it) { | 307 | for (auto it = s_configData.begin(), end = s_configData.end(); it != end; ++it) { | ||
297 | const auto key = it.value().key; | 308 | const auto key = it.value().key; | ||
298 | if (!m_config.hasKey(key.constData())) { | 309 | if (!m_config.hasKey(key.constData())) { | ||
299 | continue; | 310 | continue; | ||
300 | } | 311 | } | ||
301 | readEntry(key, it.value().booleanSetter, true); | 312 | readEntry(key, it.value().booleanSetter, true); | ||
302 | readEntry(key, it.value().quint32Setter, 0); | 313 | readEntry(key, it.value().quint32Setter, 0); | ||
303 | readEntry(key, it.value().stringSetter, ""); | 314 | readEntry(key, it.value().stringSetter, ""); | ||
315 | readEntry(key, it.value().qrealSetter, 1); | ||||
ervin: There is type erasure and implicit conversion involved so I guess it ends up working properly… | |||||
304 | }; | 316 | }; | ||
305 | 317 | | |||
306 | m_loading = false; | 318 | m_loading = false; | ||
307 | } | 319 | } | ||
308 | 320 | | |||
309 | void Device::setPointerAcceleration(qreal acceleration) | 321 | void Device::setPointerAcceleration(qreal acceleration) | ||
310 | { | 322 | { | ||
311 | if (!m_supportsPointerAcceleration) { | 323 | if (!m_supportsPointerAcceleration) { | ||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | |||||
471 | CONFIG(setDisableWhileTyping, !m_supportsDisableWhileTyping, dwt_set_enabled, DWT, disableWhileTyping, DisableWhileTyping) | 483 | CONFIG(setDisableWhileTyping, !m_supportsDisableWhileTyping, dwt_set_enabled, DWT, disableWhileTyping, DisableWhileTyping) | ||
472 | CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick, TapToClick) | 484 | CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick, TapToClick) | ||
473 | CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag, TapAndDrag) | 485 | CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag, TapAndDrag) | ||
474 | CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock, TapDragLock) | 486 | CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock, TapDragLock) | ||
475 | CONFIG(setMiddleEmulation, m_supportsMiddleEmulation == false, middle_emulation_set_enabled, MIDDLE_EMULATION, middleEmulation, MiddleButtonEmulation) | 487 | CONFIG(setMiddleEmulation, m_supportsMiddleEmulation == false, middle_emulation_set_enabled, MIDDLE_EMULATION, middleEmulation, MiddleButtonEmulation) | ||
476 | 488 | | |||
477 | #undef CONFIG | 489 | #undef CONFIG | ||
478 | 490 | | |||
491 | void Device::setScrollFactor(qreal factor) | ||||
492 | { | ||||
493 | if (m_scrollFactor != factor) { | ||||
494 | m_scrollFactor = factor; | ||||
495 | writeEntry(ConfigKey::ScrollFactor, m_scrollFactor); | ||||
496 | emit scrollFactorChanged(); | ||||
497 | } | ||||
498 | } | ||||
499 | | ||||
479 | void Device::setOrientation(Qt::ScreenOrientation orientation) | 500 | void Device::setOrientation(Qt::ScreenOrientation orientation) | ||
480 | { | 501 | { | ||
481 | if (!m_supportsCalibrationMatrix) { | 502 | if (!m_supportsCalibrationMatrix) { | ||
482 | return; | 503 | return; | ||
483 | } | 504 | } | ||
484 | // 90 deg cw: | 505 | // 90 deg cw: | ||
485 | static const QMatrix4x4 portraitMatrix{ | 506 | static const QMatrix4x4 portraitMatrix{ | ||
486 | 0.0f, -1.0f, 1.0f, 0.0f, | 507 | 0.0f, -1.0f, 1.0f, 0.0f, | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
There is type erasure and implicit conversion involved so I guess it ends up working properly in practice, still I'd advise using "1.0" here which would be of the right type. Just a question of making intent obvious.