Changeset View
Changeset View
Standalone View
Standalone View
libinput/device.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 63 | { | |||
---|---|---|---|---|---|
69 | if (it != s_devices.constEnd()) { | 69 | if (it != s_devices.constEnd()) { | ||
70 | return *it; | 70 | return *it; | ||
71 | } | 71 | } | ||
72 | return nullptr; | 72 | return nullptr; | ||
73 | } | 73 | } | ||
74 | 74 | | |||
75 | enum class ConfigKey { | 75 | enum class ConfigKey { | ||
76 | Enabled, | 76 | Enabled, | ||
77 | LeftHanded, | ||||
77 | TapToClick, | 78 | TapToClick, | ||
78 | TapAndDrag, | 79 | TapAndDrag, | ||
79 | TapDragLock, | 80 | TapDragLock, | ||
80 | MiddleButtonEmulation, | 81 | MiddleButtonEmulation, | ||
81 | NaturalScroll, | 82 | NaturalScroll, | ||
82 | ScrollTwoFinger, | 83 | ScrollTwoFinger, | ||
83 | ScrollEdge, | 84 | ScrollEdge, | ||
84 | ScrollOnButton, | 85 | ScrollOnButton, | ||
Show All 9 Lines | 89 | struct ConfigData { | |||
94 | struct UintSetter { | 95 | struct UintSetter { | ||
95 | std::function<void (Device*, quint32)> setter; | 96 | std::function<void (Device*, quint32)> setter; | ||
96 | std::function<quint32 (Device*)> defaultValue; | 97 | std::function<quint32 (Device*)> defaultValue; | ||
97 | } quint32Setter; | 98 | } quint32Setter; | ||
98 | }; | 99 | }; | ||
99 | 100 | | |||
100 | static const QMap<ConfigKey, ConfigData> s_configData { | 101 | static const QMap<ConfigKey, ConfigData> s_configData { | ||
101 | {ConfigKey::Enabled, {QByteArrayLiteral("Enabled"), {&Device::setEnabled, std::function<bool (Device*)>()}, {}}}, | 102 | {ConfigKey::Enabled, {QByteArrayLiteral("Enabled"), {&Device::setEnabled, std::function<bool (Device*)>()}, {}}}, | ||
103 | {ConfigKey::LeftHanded, {QByteArrayLiteral("LeftHanded"), {&Device::setLeftHanded, &Device::leftHandedEnabledByDefault}, {}}}, | ||||
102 | {ConfigKey::TapToClick, {QByteArrayLiteral("TapToClick"), {&Device::setTapToClick, &Device::tapToClickEnabledByDefault}, {}}}, | 104 | {ConfigKey::TapToClick, {QByteArrayLiteral("TapToClick"), {&Device::setTapToClick, &Device::tapToClickEnabledByDefault}, {}}}, | ||
103 | {ConfigKey::TapAndDrag, {QByteArrayLiteral("TapAndDrag"), {&Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault}, {}}}, | 105 | {ConfigKey::TapAndDrag, {QByteArrayLiteral("TapAndDrag"), {&Device::setTapAndDrag, &Device::tapAndDragEnabledByDefault}, {}}}, | ||
104 | {ConfigKey::TapDragLock, {QByteArrayLiteral("TapDragLock"), {&Device::setTapDragLock, &Device::tapDragLockEnabledByDefault}, {}}}, | 106 | {ConfigKey::TapDragLock, {QByteArrayLiteral("TapDragLock"), {&Device::setTapDragLock, &Device::tapDragLockEnabledByDefault}, {}}}, | ||
105 | {ConfigKey::MiddleButtonEmulation, {QByteArrayLiteral("MiddleButtonEmulation"), {&Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault}, {}}}, | 107 | {ConfigKey::MiddleButtonEmulation, {QByteArrayLiteral("MiddleButtonEmulation"), {&Device::setMiddleEmulation, &Device::middleEmulationEnabledByDefault}, {}}}, | ||
106 | {ConfigKey::NaturalScroll, {QByteArrayLiteral("NaturalScroll"), {&Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault}, {}}}, | 108 | {ConfigKey::NaturalScroll, {QByteArrayLiteral("NaturalScroll"), {&Device::setNaturalScroll, &Device::naturalScrollEnabledByDefault}, {}}}, | ||
107 | {ConfigKey::ScrollTwoFinger, {QByteArrayLiteral("ScrollTwoFinger"), {&Device::setScrollTwoFinger, &Device::scrollTwoFingerEnabledByDefault}, {}}}, | 109 | {ConfigKey::ScrollTwoFinger, {QByteArrayLiteral("ScrollTwoFinger"), {&Device::setScrollTwoFinger, &Device::scrollTwoFingerEnabledByDefault}, {}}}, | ||
108 | {ConfigKey::ScrollEdge, {QByteArrayLiteral("ScrollEdge"), {&Device::setScrollEdge, &Device::scrollEdgeEnabledByDefault}, {}}}, | 110 | {ConfigKey::ScrollEdge, {QByteArrayLiteral("ScrollEdge"), {&Device::setScrollEdge, &Device::scrollEdgeEnabledByDefault}, {}}}, | ||
109 | {ConfigKey::ScrollOnButton, {QByteArrayLiteral("ScrollOnButton"), {&Device::setScrollOnButtonDown, &Device::scrollOnButtonDownEnabledByDefault}, {}}}, | 111 | {ConfigKey::ScrollOnButton, {QByteArrayLiteral("ScrollOnButton"), {&Device::setScrollOnButtonDown, &Device::scrollOnButtonDownEnabledByDefault}, {}}}, | ||
Show All 31 Lines | 127 | #endif | |||
141 | , m_supportsLeftHanded(libinput_device_config_left_handed_is_available(m_device)) | 143 | , m_supportsLeftHanded(libinput_device_config_left_handed_is_available(m_device)) | ||
142 | , m_supportsCalibrationMatrix(libinput_device_config_calibration_has_matrix(m_device)) | 144 | , m_supportsCalibrationMatrix(libinput_device_config_calibration_has_matrix(m_device)) | ||
143 | , m_supportsDisableEvents(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) | 145 | , m_supportsDisableEvents(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) | ||
144 | , m_supportsDisableEventsOnExternalMouse(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) | 146 | , m_supportsDisableEventsOnExternalMouse(libinput_device_config_send_events_get_modes(m_device) & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) | ||
145 | , m_supportsMiddleEmulation(libinput_device_config_middle_emulation_is_available(m_device)) | 147 | , m_supportsMiddleEmulation(libinput_device_config_middle_emulation_is_available(m_device)) | ||
146 | , m_supportsNaturalScroll(libinput_device_config_scroll_has_natural_scroll(m_device)) | 148 | , m_supportsNaturalScroll(libinput_device_config_scroll_has_natural_scroll(m_device)) | ||
147 | , m_supportedScrollMethods(libinput_device_config_scroll_get_methods(m_device)) | 149 | , m_supportedScrollMethods(libinput_device_config_scroll_get_methods(m_device)) | ||
148 | , m_middleEmulationEnabledByDefault(libinput_device_config_middle_emulation_get_default_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | 150 | , m_middleEmulationEnabledByDefault(libinput_device_config_middle_emulation_get_default_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | ||
151 | , m_leftHandedEnabledByDefault(libinput_device_config_left_handed_get_default(m_device)) | ||||
149 | , m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device)) | 152 | , m_naturalScrollEnabledByDefault(libinput_device_config_scroll_get_default_natural_scroll_enabled(m_device)) | ||
150 | , m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device)) | 153 | , m_defaultScrollMethod(libinput_device_config_scroll_get_default_method(m_device)) | ||
151 | , m_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device)) | 154 | , m_defaultScrollButton(libinput_device_config_scroll_get_default_button(m_device)) | ||
152 | , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | 155 | , m_middleEmulation(libinput_device_config_middle_emulation_get_enabled(m_device) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED) | ||
153 | , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) | 156 | , m_leftHanded(m_supportsLeftHanded ? libinput_device_config_left_handed_get(m_device) : false) | ||
154 | , m_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(m_device) : false) | 157 | , m_naturalScroll(m_supportsNaturalScroll ? libinput_device_config_scroll_get_natural_scroll_enabled(m_device) : false) | ||
155 | , m_scrollMethod(libinput_device_config_scroll_get_method(m_device)) | 158 | , m_scrollMethod(libinput_device_config_scroll_get_method(m_device)) | ||
156 | , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) | 159 | , m_scrollButton(libinput_device_config_scroll_get_button(m_device)) | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 246 | for (auto it = s_configData.begin(), end = s_configData.end(); it != end; ++it) { | |||
247 | } | 250 | } | ||
248 | readEntry(key, it.value().booleanSetter, true); | 251 | readEntry(key, it.value().booleanSetter, true); | ||
249 | readEntry(key, it.value().quint32Setter, 0); | 252 | readEntry(key, it.value().quint32Setter, 0); | ||
250 | }; | 253 | }; | ||
251 | 254 | | |||
252 | m_loading = false; | 255 | m_loading = false; | ||
253 | } | 256 | } | ||
254 | 257 | | |||
255 | void Device::setLeftHanded(bool set) | | |||
256 | { | | |||
257 | if (!m_supportsLeftHanded) { | | |||
258 | return; | | |||
259 | } | | |||
260 | if (libinput_device_config_left_handed_set(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | | |||
261 | if (m_leftHanded != set) { | | |||
262 | m_leftHanded = set; | | |||
263 | emit leftHandedChanged(); | | |||
264 | } | | |||
265 | } | | |||
266 | } | | |||
267 | | ||||
268 | void Device::setPointerAcceleration(qreal acceleration) | 258 | void Device::setPointerAcceleration(qreal acceleration) | ||
269 | { | 259 | { | ||
270 | if (!m_supportsPointerAcceleration) { | 260 | if (!m_supportsPointerAcceleration) { | ||
271 | return; | 261 | return; | ||
272 | } | 262 | } | ||
273 | acceleration = qBound(-1.0, acceleration, 1.0); | 263 | acceleration = qBound(-1.0, acceleration, 1.0); | ||
274 | if (libinput_device_config_accel_set_speed(m_device, acceleration) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | 264 | if (libinput_device_config_accel_set_speed(m_device, acceleration) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||
275 | if (m_pointerAcceleration != acceleration) { | 265 | if (m_pointerAcceleration != acceleration) { | ||
276 | m_pointerAcceleration = acceleration; | 266 | m_pointerAcceleration = acceleration; | ||
277 | emit pointerAccelerationChanged(); | 267 | emit pointerAccelerationChanged(); | ||
278 | } | 268 | } | ||
279 | } | 269 | } | ||
280 | } | 270 | } | ||
281 | 271 | | |||
282 | void Device::setNaturalScroll(bool set) | | |||
283 | { | | |||
284 | if (!m_supportsNaturalScroll) { | | |||
285 | return; | | |||
286 | } | | |||
287 | if (libinput_device_config_scroll_set_natural_scroll_enabled(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | | |||
288 | if (m_naturalScroll != set) { | | |||
289 | m_naturalScroll = set; | | |||
290 | writeEntry(ConfigKey::NaturalScroll, m_naturalScroll); | | |||
291 | emit naturalScrollChanged(); | | |||
292 | } | | |||
293 | } | | |||
294 | } | | |||
295 | | ||||
296 | bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) | 272 | bool Device::setScrollMethod(bool set, enum libinput_config_scroll_method method) | ||
297 | { | 273 | { | ||
298 | if (!(m_supportedScrollMethods & method)) { | 274 | if (!(m_supportedScrollMethods & method)) { | ||
299 | return false; | 275 | return false; | ||
300 | } | 276 | } | ||
301 | if (set) { | 277 | if (set) { | ||
302 | if (m_scrollMethod == method) { | 278 | if (m_scrollMethod == method) { | ||
303 | return false; | 279 | return false; | ||
Show All 11 Lines | 288 | if (libinput_device_config_scroll_set_method(m_device, method) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | |||
315 | return true; | 291 | return true; | ||
316 | } | 292 | } | ||
317 | return false; | 293 | return false; | ||
318 | } | 294 | } | ||
319 | 295 | | |||
320 | void Device::setScrollTwoFinger(bool set) { | 296 | void Device::setScrollTwoFinger(bool set) { | ||
321 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG)) { | 297 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_2FG)) { | ||
322 | writeEntry(ConfigKey::ScrollTwoFinger, set); | 298 | writeEntry(ConfigKey::ScrollTwoFinger, set); | ||
299 | writeEntry(ConfigKey::ScrollEdge, !set); | ||||
300 | writeEntry(ConfigKey::ScrollOnButton, !set); | ||||
323 | } | 301 | } | ||
324 | } | 302 | } | ||
325 | 303 | | |||
326 | void Device::setScrollEdge(bool set) { | 304 | void Device::setScrollEdge(bool set) { | ||
327 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE)) { | 305 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_EDGE)) { | ||
328 | writeEntry(ConfigKey::ScrollEdge, set); | 306 | writeEntry(ConfigKey::ScrollEdge, set); | ||
307 | writeEntry(ConfigKey::ScrollTwoFinger, !set); | ||||
308 | writeEntry(ConfigKey::ScrollOnButton, !set); | ||||
329 | } | 309 | } | ||
330 | } | 310 | } | ||
331 | 311 | | |||
332 | void Device::setScrollOnButtonDown(bool set) { | 312 | void Device::setScrollOnButtonDown(bool set) { | ||
333 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | 313 | if (setScrollMethod(set, LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | ||
334 | writeEntry(ConfigKey::ScrollOnButton, set); | 314 | writeEntry(ConfigKey::ScrollOnButton, set); | ||
315 | writeEntry(ConfigKey::ScrollTwoFinger, !set); | ||||
316 | writeEntry(ConfigKey::ScrollEdge, !set); | ||||
335 | } | 317 | } | ||
336 | } | 318 | } | ||
337 | 319 | | |||
338 | void Device::setScrollButton(quint32 button) | 320 | void Device::setScrollButton(quint32 button) | ||
339 | { | 321 | { | ||
340 | if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | 322 | if (!(m_supportedScrollMethods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)) { | ||
341 | return; | 323 | return; | ||
342 | } | 324 | } | ||
343 | if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | 325 | if (libinput_device_config_scroll_set_button(m_device, button) == LIBINPUT_CONFIG_STATUS_SUCCESS) { | ||
344 | if (m_scrollButton != button) { | 326 | if (m_scrollButton != button) { | ||
345 | m_scrollButton = button; | 327 | m_scrollButton = button; | ||
346 | writeEntry(ConfigKey::ScrollButton, m_scrollButton); | 328 | writeEntry(ConfigKey::ScrollButton, m_scrollButton); | ||
347 | emit scrollButtonChanged(); | 329 | emit scrollButtonChanged(); | ||
348 | } | 330 | } | ||
349 | } | 331 | } | ||
350 | } | 332 | } | ||
351 | 333 | | |||
334 | #define CONFIG(method, condition, function, variable, key) \ | ||||
335 | void Device::method(bool set) \ | ||||
336 | { \ | ||||
337 | if (condition) { \ | ||||
338 | return; \ | ||||
339 | } \ | ||||
340 | if (libinput_device_config_##function(m_device, set) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \ | ||||
341 | if (m_##variable != set) { \ | ||||
342 | m_##variable = set; \ | ||||
343 | writeEntry(ConfigKey::key, m_##variable); \ | ||||
344 | emit variable##Changed(); \ | ||||
345 | }\ | ||||
346 | } \ | ||||
347 | } | ||||
348 | | ||||
349 | CONFIG(setLeftHanded, !m_supportsLeftHanded, left_handed_set, leftHanded, LeftHanded) | ||||
350 | CONFIG(setNaturalScroll, !m_supportsNaturalScroll, scroll_set_natural_scroll_enabled, naturalScroll, NaturalScroll) | ||||
351 | | ||||
352 | #undef CONFIG | ||||
353 | | ||||
352 | #define CONFIG(method, condition, function, enum, variable, key) \ | 354 | #define CONFIG(method, condition, function, enum, variable, key) \ | ||
353 | void Device::method(bool set) \ | 355 | void Device::method(bool set) \ | ||
354 | { \ | 356 | { \ | ||
355 | if (condition) { \ | 357 | if (condition) { \ | ||
356 | return; \ | 358 | return; \ | ||
357 | } \ | 359 | } \ | ||
358 | if (libinput_device_config_##function(m_device, set ? LIBINPUT_CONFIG_##enum##_ENABLED : LIBINPUT_CONFIG_##enum##_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \ | 360 | if (libinput_device_config_##function(m_device, set ? LIBINPUT_CONFIG_##enum##_ENABLED : LIBINPUT_CONFIG_##enum##_DISABLED) == LIBINPUT_CONFIG_STATUS_SUCCESS) { \ | ||
359 | if (m_##variable != set) { \ | 361 | if (m_##variable != set) { \ | ||
Show All 17 Lines |