Changeset View
Changeset View
Standalone View
Standalone View
libinput/device.cpp
Context not available. | |||||
73 | enum class ConfigKey { | 73 | enum class ConfigKey { | ||
---|---|---|---|---|---|
74 | Enabled, | 74 | Enabled, | ||
75 | LeftHanded, | 75 | LeftHanded, | ||
76 | DisableWhileTyping, | ||||
77 | PointerAcceleration, | ||||
78 | PointerAccelerationProfile, | ||||
76 | TapToClick, | 79 | TapToClick, | ||
80 | LmrTapButtonMap, | ||||
77 | TapAndDrag, | 81 | TapAndDrag, | ||
78 | TapDragLock, | 82 | TapDragLock, | ||
79 | MiddleButtonEmulation, | 83 | MiddleButtonEmulation, | ||
Context not available. | |||||
91 | : key(_key) | 95 | : key(_key) | ||
92 | { quint32Setter.setter = _setter; quint32Setter.defaultValue = _defaultValue; } | 96 | { quint32Setter.setter = _setter; quint32Setter.defaultValue = _defaultValue; } | ||
93 | 97 | | |||
98 | explicit ConfigData(QByteArray _key, void (Device::*_setter)(QString), QString (Device::*_defaultValue)() const = nullptr) | ||||
99 | : key(_key) | ||||
100 | { stringSetter.setter = _setter; stringSetter.defaultValue = _defaultValue; } | ||||
101 | | ||||
94 | QByteArray key; | 102 | QByteArray key; | ||
95 | 103 | | |||
96 | struct { | 104 | struct { | ||
Context not available. | |||||
102 | void (Device::*setter)(quint32) = nullptr; | 110 | void (Device::*setter)(quint32) = nullptr; | ||
103 | quint32 (Device::*defaultValue)() const; | 111 | quint32 (Device::*defaultValue)() const; | ||
104 | } quint32Setter; | 112 | } quint32Setter; | ||
113 | struct { | ||||
114 | void (Device::*setter)(QString) = nullptr; | ||||
115 | QString (Device::*defaultValue)() const; | ||||
116 | } stringSetter; | ||||
105 | }; | 117 | }; | ||
106 | 118 | | |||
107 | static const QMap<ConfigKey, ConfigData> s_configData { | 119 | static const QMap<ConfigKey, ConfigData> s_configData { | ||
108 | {ConfigKey::Enabled, ConfigData(QByteArrayLiteral("Enabled"), &Device::setEnabled)}, | 120 | {ConfigKey::Enabled, ConfigData(QByteArrayLiteral("Enabled"), &Device::setEnabled)}, | ||
109 | {ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)}, | 121 | {ConfigKey::LeftHanded, ConfigData(QByteArrayLiteral("LeftHanded"), &Device::setLeftHanded, &Device::leftHandedEnabledByDefault)}, | ||
122 | {ConfigKey::DisableWhileTyping, ConfigData(QByteArrayLiteral("DisableWhileTyping"), &Device::setDisableWhileTyping, &Device::disableWhileTypingEnabledByDefault)}, | ||||
123 | {ConfigKey::PointerAcceleration, ConfigData(QByteArrayLiteral("PointerAcceleration"), &Device::setPointerAccelerationFromString, &Device::defaultPointerAccelerationToString)}, | ||||
124 | {ConfigKey::PointerAccelerationProfile, ConfigData(QByteArrayLiteral("PointerAccelerationProfile"), &Device::activatePointerAccelerationProfileFromInt, &Device::defaultPointerAccelerationProfileToInt)}, | ||||
110 | {ConfigKey::TapToClick, ConfigData(QByteArrayLiteral("TapToClick"), &Device::setTapToClick, &Device::tapToClickEnabledByDefault)}, | 125 | {ConfigKey::TapToClick, ConfigData(QByteArrayLiteral("TapToClick"), &Device::setTapToClick, &Device::tapToClickEnabledByDefault)}, | ||
111 | {ConfigKey::TapAndDrag, ConfigData(QByteArrayLiteral("TapAndDrag"), &Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault)}, | 126 | {ConfigKey::TapAndDrag, ConfigData(QByteArrayLiteral("TapAndDrag"), &Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault)}, | ||
112 | {ConfigKey::TapDragLock, ConfigData(QByteArrayLiteral("TapDragLock"), &Device::setTapDragLock, &Device::tapDragLockEnabledByDefault)}, | 127 | {ConfigKey::TapDragLock, ConfigData(QByteArrayLiteral("TapDragLock"), &Device::setTapDragLock, &Device::tapDragLockEnabledByDefault)}, | ||
113 | {ConfigKey::MiddleButtonEmulation, ConfigData(QByteArrayLiteral("MiddleButtonEmulation"), &Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault)}, | 128 | {ConfigKey::MiddleButtonEmulation, ConfigData(QByteArrayLiteral("MiddleButtonEmulation"), &Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault)}, | ||
129 | {ConfigKey::LmrTapButtonMap, ConfigData(QByteArrayLiteral("LmrTapButtonMap"), &Device::setLmrTapButtonMap, &Device::lmrTapButtonMapEnabledByDefault)}, | ||||
114 | {ConfigKey::NaturalScroll, ConfigData(QByteArrayLiteral("NaturalScroll"), &Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault)}, | 130 | {ConfigKey::NaturalScroll, ConfigData(QByteArrayLiteral("NaturalScroll"), &Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault)}, | ||
115 | {ConfigKey::ScrollMethod, ConfigData(QByteArrayLiteral("ScrollMethod"), &Device::activateScrollMethodFromInt, &Device::defaultScrollMethodToInt)}, | 131 | {ConfigKey::ScrollMethod, ConfigData(QByteArrayLiteral("ScrollMethod"), &Device::activateScrollMethodFromInt, &Device::defaultScrollMethodToInt)}, | ||
116 | {ConfigKey::ScrollButton, ConfigData(QByteArrayLiteral("ScrollButton"), &Device::setScrollButton, &Device::defaultScrollButton)} | 132 | {ConfigKey::ScrollButton, ConfigData(QByteArrayLiteral("ScrollButton"), &Device::setScrollButton, &Device::defaultScrollButton)} | ||
Context not available. | |||||
138 | , m_tapFingerCount(libinput_device_config_tap_get_finger_count(m_device)) | 154 | , m_tapFingerCount(libinput_device_config_tap_get_finger_count(m_device)) | ||
139 | , m_tapToClickEnabledByDefault(libinput_device_config_tap_get_default_enabled(m_device) == LIBINPUT_CONFIG_TAP_ENABLED) | 155 | , m_tapToClickEnabledByDefault(libinput_device_config_tap_get_default_enabled(m_device) == LIBINPUT_CONFIG_TAP_ENABLED) | ||
140 | , m_tapToClick(libinput_device_config_tap_get_enabled(m_device)) | 156 | , m_tapToClick(libinput_device_config_tap_get_enabled(m_device)) | ||
157 | , m_defaultTapButtonMap(libinput_device_config_tap_get_default_button_map(m_device)) | ||||
158 | , m_tapButtonMap(libinput_device_config_tap_get_button_map(m_device)) | ||||
141 | , m_tapAndDragEnabledByDefault(libinput_device_config_tap_get_default_drag_enabled(m_device)) | 159 | , m_tapAndDragEnabledByDefault(libinput_device_config_tap_get_default_drag_enabled(m_device)) | ||
142 | , m_tapAndDrag(libinput_device_config_tap_get_drag_enabled(m_device)) | 160 | , m_tapAndDrag(libinput_device_config_tap_get_drag_enabled(m_device)) | ||
143 | , m_tapDragLockEnabledByDefault(libinput_device_config_tap_get_default_drag_lock_enabled(m_device)) | 161 | , m_tapDragLockEnabledByDefault(libinput_device_config_tap_get_default_drag_lock_enabled(m_device)) | ||
Context not available. | |||||
156 | , m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device)) | 174 | , m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device)) | ||
157 | , m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device)) | 175 | , m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device)) | ||
158 | , m_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device)) | 176 | , m_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device)) | ||
177 | , m_disableWhileTypingEnabledByDefault(libinput_device_config_dwt_get_default_enabled(m_device)) | ||||
178 | , m_disableWhileTyping(m_supportsDisableWhileTyping ? libinput_device_config_dwt_get_enabled(m_device) : false) | ||||
159 | , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | 179 | , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | ||
160 | , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) | 180 | , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) | ||
161 | , m_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(m_device) : false) | 181 | , m_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(m_device) : false) | ||
162 | , m_scrollMethod(libinput_device_config_scroll_get_method(m_device)) | 182 | , m_scrollMethod(libinput_device_config_scroll_get_method(m_device)) | ||
163 | , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) | 183 | , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) | ||
184 | , m_defaultPointerAcceleration(libinput_device_config_accel_get_default_speed(m_device)) | ||||
164 | , m_pointerAcceleration(libinput_device_config_accel_get_speed(m_device)) | 185 | , m_pointerAcceleration(libinput_device_config_accel_get_speed(m_device)) | ||
186 | , m_supportedPointerAccelerationProfiles(libinput_device_config_accel_get_profiles(m_device)) | ||||
187 | , m_defaultPointerAccelerationProfile(libinput_device_config_accel_get_default_profile(m_device)) | ||||
188 | , m_pointerAccelerationProfile(libinput_device_config_accel_get_profile(m_device)) | ||||
165 | , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) | 189 | , m_enabled(m_supportsDisableEvents ? libinput_device_config_send_events_get_mode(m_device) == LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : true) | ||
166 | , m_config() | 190 | , m_config() | ||
167 | { | 191 | { | ||
Context not available. | |||||
255 | } | 279 | } | ||
256 | readEntry(key, it.value().booleanSetter, true); | 280 | readEntry(key, it.value().booleanSetter, true); | ||
257 | readEntry(key, it.value().quint32Setter, 0); | 281 | readEntry(key, it.value().quint32Setter, 0); | ||
282 | readEntry(key, it.value().stringSetter, ""); | ||||
258 | }; | 283 | }; | ||
259 | 284 | | |||
260 | m_loading = false; | 285 | m_loading = false; | ||
Context not available. | |||||
270 | if (m_pointerAcceleration != acceleration) { | 295 | if (m_pointerAcceleration != acceleration) { | ||
271 | m_pointerAcceleration = acceleration; | 296 | m_pointerAcceleration = acceleration; | ||
272 | emit pointerAccelerationChanged(); | 297 | emit pointerAccelerationChanged(); | ||
298 | writeEntry(ConfigKey::PointerAcceleration, QString::number(acceleration, 'f', 3)); | ||||
299 | } | ||||
300 | } | ||||
301 | } | ||||
302 | | ||||
303 | void Device::setScrollButton(quint32 button) | ||||
304 | { | ||||
305 | if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | ||||
306 | return; | ||||
307 | } | ||||
308 | if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||||
309 | if (m_scrollButton != button) { | ||||
310 | m_scrollButton = button; | ||||
311 | writeEntry(ConfigKey::ScrollButton, m_scrollButton); | ||||
312 | emit scrollButtonChanged(); | ||||
313 | } | ||||
314 | } | ||||
315 | } | ||||
316 | | ||||
317 | void Device::setPointerAccelerationProfile(bool set, enum libinput_config_accel_profile profile) { | ||||
318 | | ||||
319 | if (!(m_supportedPointerAccelerationProfiles & profile)) { | ||||
320 | return; | ||||
321 | } | ||||
322 | | ||||
323 | if (!set) { | ||||
324 | profile = LIBINPUT_CONFIG_ACCEL_PROFILE_NONE; | ||||
325 | } | ||||
326 | | ||||
327 | if (libinput_device_config_accel_set_profile(m_device, profile) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||||
328 | if (m_pointerAccelerationProfile != profile) { | ||||
329 | m_pointerAccelerationProfile = profile; | ||||
330 | emit pointerAccelerationProfileChanged(); | ||||
331 | writeEntry(ConfigKey::PointerAccelerationProfile, (quint32) profile); | ||||
273 | } | 332 | } | ||
274 | } | 333 | } | ||
275 | } | 334 | } | ||
276 | 335 | | |||
277 | void Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) | 336 | void Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) | ||
278 | { | 337 | { | ||
279 | bool stays_the_same = (m_scrollMethod == method) == set; | 338 | if (!(m_supportedScrollMethods & method)) { | ||
280 | if (!(m_supportedScrollMethods & method) || stays_the_same) { | | |||
281 | return; | 339 | return; | ||
282 | } | 340 | } | ||
283 | 341 | | |||
Context not available. | |||||
286 | } | 344 | } | ||
287 | 345 | | |||
288 | if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | 346 | if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||
289 | m_scrollMethod = method; | 347 | if (m_scrollMethod != method) { | ||
290 | emit scrollMethodChanged(); | 348 | m_scrollMethod = method; | ||
291 | writeEntry(ConfigKey::ScrollMethod, (quint32) method); | 349 | emit scrollMethodChanged(); | ||
350 | writeEntry(ConfigKey::ScrollMethod, (quint32) method); | ||||
351 | } | ||||
292 | } | 352 | } | ||
293 | } | 353 | } | ||
294 | 354 | | |||
295 | void Device::setScrollButton(quint32 button) | 355 | void Device::setLmrTapButtonMap(bool set) { | ||
296 | { | 356 | enum libinput_config_tap_button_map map = set ? LIBINPUT_CONFIG_TAP_MAP_LMR : LIBINPUT_CONFIG_TAP_MAP_LRM; | ||
297 | if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | 357 | | ||
358 | if (m_tapFingerCount < 2) { | ||||
298 | return; | 359 | return; | ||
299 | } | 360 | } | ||
300 | if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | 361 | if (!set) { | ||
301 | if (m_scrollButton != button) { | 362 | map = LIBINPUT_CONFIG_TAP_MAP_LRM; | ||
302 | m_scrollButton = button; | 363 | } | ||
303 | writeEntry(ConfigKey::ScrollButton, m_scrollButton); | 364 | | ||
304 | emit scrollButtonChanged(); | 365 | if (libinput_device_config_tap_set_button_map(m_device, map) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||
366 | if (m_tapButtonMap != map) { | ||||
367 | m_tapButtonMap = map; | ||||
368 | writeEntry(ConfigKey::LmrTapButtonMap, set); | ||||
369 | emit tapButtonMapChanged(); | ||||
305 | } | 370 | } | ||
306 | } | 371 | } | ||
307 | } | 372 | } | ||
Context not available. | |||||
342 | } | 407 | } | ||
343 | 408 | | |||
344 | CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, enabled, Enabled) | 409 | CONFIG(setEnabled, !m_supportsDisableEvents, send_events_set_mode, SEND_EVENTS, enabled, Enabled) | ||
410 | CONFIG(setDisableWhileTyping, !m_supportsDisableWhileTyping, dwt_set_enabled, DWT, disableWhileTyping, DisableWhileTyping) | ||||
345 | CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick, TapToClick) | 411 | CONFIG(setTapToClick, m_tapFingerCount == 0, tap_set_enabled, TAP, tapToClick, TapToClick) | ||
346 | CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag, TapAndDrag) | 412 | CONFIG(setTapAndDrag, false, tap_set_drag_enabled, DRAG, tapAndDrag, TapAndDrag) | ||
347 | CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock, TapDragLock) | 413 | CONFIG(setTapDragLock, false, tap_set_drag_lock_enabled, DRAG_LOCK, tapDragLock, TapDragLock) | ||
Context not available. |