Changeset View
Changeset View
Standalone View
Standalone View
kcms/touchpad/src/backends/x11/libinputtouchpad.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU General Public License | 14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "libinputtouchpad.h" | 19 | #include "libinputtouchpad.h" | ||
20 | #include "logging.h" | 20 | #include "logging.h" | ||
21 | 21 | | |||
22 | #include <QSet> | ||||
23 | | ||||
22 | #include <stddef.h> | 24 | #include <stddef.h> | ||
23 | #include <limits.h> | 25 | #include <limits.h> | ||
24 | 26 | | |||
25 | #include <libinput-properties.h> | 27 | #include <libinput-properties.h> | ||
26 | #include <xserver-properties.h> | 28 | #include <xserver-properties.h> | ||
27 | 29 | | |||
28 | #include <X11/extensions/XInput2.h> | 30 | #include <X11/extensions/XInput2.h> | ||
29 | 31 | | |||
32 | static const QSet<QString> configProps = { | ||||
fvogt: `static`? | |||||
33 | QStringLiteral("enabled"), | ||||
34 | QStringLiteral("disableWhileTyping"), | ||||
35 | QStringLiteral("disableEventsOnExternalMouse"), | ||||
36 | QStringLiteral("leftHanded"), | ||||
37 | QStringLiteral("middleEmulation"), | ||||
38 | QStringLiteral("pointerAcceleration"), | ||||
39 | QStringLiteral("pointerAccelerationProfileFlat"), | ||||
40 | QStringLiteral("pointerAccelerationProfileAdaptive"), | ||||
41 | QStringLiteral("tapToClick"), | ||||
42 | QStringLiteral("tapAndDrag"), | ||||
43 | QStringLiteral("tapDragLock"), | ||||
44 | QStringLiteral("lrmTapButtonMap"), | ||||
45 | QStringLiteral("lmrTapButtonMap"), | ||||
46 | QStringLiteral("scrollTwoFinger"), | ||||
47 | QStringLiteral("scrollOnButtonDown"), | ||||
48 | QStringLiteral("scrollButton"), | ||||
49 | QStringLiteral("scrollEdge"), | ||||
50 | QStringLiteral("naturalScroll"), | ||||
51 | QStringLiteral("horizontalScrolling"), | ||||
52 | QStringLiteral("clickMethodAreas"), | ||||
53 | QStringLiteral("clickMethodClickfinger") | ||||
54 | }; | ||||
In best case these should be in some way shared with libinputProperties array to minimize code duplication. But as long as these names are the same as in libinputProperties, we can leave it like that for now. romangg: In best case these should be in some way shared with libinputProperties array to minimize code… | |||||
55 | | ||||
30 | const Parameter libinputProperties[] = { | 56 | const Parameter libinputProperties[] = { | ||
31 | 57 | | |||
32 | /* libinput disable supports property */ | 58 | /* libinput disable supports property */ | ||
33 | {"supportsDisableEvents", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_AVAILABLE, 8, 0}, | 59 | {"supportsDisableEvents", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_AVAILABLE, 8, 0}, | ||
34 | {"enabled", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED, 8, 0}, | 60 | {"enabled", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED, 8, 0}, | ||
35 | {"enabledDefault", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED_DEFAULT, 8, 0}, | 61 | {"enabledDefault", PT_INT, 0, 1, LIBINPUT_PROP_SENDEVENTS_ENABLED_DEFAULT, 8, 0}, | ||
36 | 62 | | |||
37 | /* LeftHandSupport */ | 63 | /* LeftHandSupport */ | ||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Line(s) | 186 | { | |||
180 | } | 206 | } | ||
181 | XIFreeDeviceInfo(deviceInfo); | 207 | XIFreeDeviceInfo(deviceInfo); | ||
182 | 208 | | |||
183 | /* FingerCount cannot be zero */ | 209 | /* FingerCount cannot be zero */ | ||
184 | if (!m_tapFingerCount.val) { | 210 | if (!m_tapFingerCount.val) { | ||
185 | m_tapFingerCount.avail = true; | 211 | m_tapFingerCount.avail = true; | ||
186 | m_tapFingerCount.set(1); | 212 | m_tapFingerCount.set(1); | ||
187 | } | 213 | } | ||
214 | m_config = KSharedConfig::openConfig(QStringLiteral("touchpadxlibinputrc")); | ||||
The name of the config file should be something similar to the other one and only lower case: touchpadxlibinputrc romangg: The name of the config file should be something similar to the other one and only lower case… | |||||
188 | } | 215 | } | ||
This can be left dangling Store the KSharedConfigPtr as the member variable then you'll keep a reference davidedmundson: This can be left dangling
Store the KSharedConfigPtr as the member variable then you'll keep a… | |||||
189 | 216 | | |||
190 | bool LibinputTouchpad::getConfig() | 217 | bool LibinputTouchpad::getConfig() | ||
191 | { | 218 | { | ||
192 | bool success = true; | 219 | bool success = true; | ||
193 | 220 | | |||
194 | success &= valueLoader(m_supportsDisableEvents); | 221 | success &= valueLoader(m_supportsDisableEvents); | ||
195 | success &= valueLoader(m_enabled); | 222 | success &= valueLoader(m_enabled); | ||
196 | success &= valueLoader(m_enabledDefault); | 223 | success &= valueLoader(m_enabledDefault); | ||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Line(s) | 394 | { | |||
373 | 400 | | |||
374 | QVariant reply = getParameter(p); | 401 | QVariant reply = getParameter(p); | ||
375 | if (!reply.isValid()) { | 402 | if (!reply.isValid()) { | ||
376 | prop.avail = false; | 403 | prop.avail = false; | ||
377 | return true; | 404 | return true; | ||
378 | } | 405 | } | ||
379 | prop.avail = true; | 406 | prop.avail = true; | ||
380 | 407 | | |||
381 | T replyValue = valueLoaderPart<T>(reply); | 408 | auto touchpadConfig = m_config->group(m_name); | ||
382 | 409 | | |||
410 | const T replyValue = valueLoaderPart<T>(reply); | ||||
411 | const T loadedValue = touchpadConfig.readEntry(QString(prop.name), replyValue); | ||||
nicolasfella: Coding style: Space around != | |||||
383 | prop.old = replyValue; | 412 | prop.old = replyValue; | ||
384 | prop.val = replyValue; | 413 | prop.val = loadedValue; | ||
414 | | ||||
385 | return true; | 415 | return true; | ||
386 | } | 416 | } | ||
387 | 417 | | |||
romangg: Why this write back? What's configProps. | |||||
Yeah realized later that there is no need to write config here. So no need for configProps. Should I open a new patch for removing it? atulbi: Yeah realized later that there is no need to write config here. So no need for configProps. | |||||
388 | template<typename T> | 418 | template<typename T> | ||
389 | QString LibinputTouchpad::valueWriter(const Prop<T> &prop) | 419 | QString LibinputTouchpad::valueWriter(const Prop<T> &prop) | ||
390 | { | 420 | { | ||
391 | const Parameter *p = findParameter(QString::fromAscii(prop.name)); | 421 | const Parameter *p = findParameter(QString::fromAscii(prop.name)); | ||
392 | 422 | | |||
393 | if (!p || !prop.changed()) { | 423 | if (!p || !prop.changed()) { | ||
394 | return QString(); | 424 | return QString(); | ||
395 | } | 425 | } | ||
396 | 426 | | |||
397 | bool error = !setParameter( p, prop.val); | 427 | bool error = !setParameter( p, prop.val); | ||
398 | if (error) { | 428 | if (error) { | ||
399 | qCCritical(KCM_TOUCHPAD) << "Cannot set property " + QString::fromAscii(prop.name); | 429 | qCCritical(KCM_TOUCHPAD) << "Cannot set property " + QString::fromAscii(prop.name); | ||
400 | return QStringLiteral("Cannot set property ") + QString::fromAscii(prop.name); | 430 | return QStringLiteral("Cannot set property ") + QString::fromAscii(prop.name); | ||
401 | } | 431 | } | ||
432 | auto touchpadConfig = m_config->group(m_name); | ||||
433 | touchpadConfig.writeEntry(QString(prop.name), prop.val); | ||||
434 | touchpadConfig.config()->sync(); | ||||
402 | return QString(); | 435 | return QString(); | ||
403 | } | 436 | } |
static?