Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/backends/x11/evdev_settings.cpp
- This file was moved from kcms/input/mousesettings.cpp.
1 | /* | 1 | /* | ||
---|---|---|---|---|---|
2 | * Copyright 2017 Xuetian Weng <wengxt@gmail.com> | 2 | * Copyright 2017 Xuetian Weng <wengxt@gmail.com> | ||
3 | * Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | * | 4 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
8 | * | 9 | * | ||
9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | 13 | * GNU General Public License for more details. | ||
13 | * | 14 | * | ||
14 | * You should have received a copy of the GNU General Public License | 15 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | 16 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 18 | */ | ||
18 | 19 | #include "evdev_settings.h" | |||
19 | #include "mousesettings.h" | 20 | #include "x11_backend.h" | ||
20 | | ||||
21 | #include "mousebackend.h" | | |||
22 | #include <QDBusMessage> | 21 | #include <QDBusMessage> | ||
23 | #include <QDBusConnection> | 22 | #include <QDBusConnection> | ||
24 | #include <KSharedConfig> | 23 | #include <KSharedConfig> | ||
25 | #include <KConfigGroup> | 24 | #include <KConfigGroup> | ||
26 | 25 | | |||
27 | #include "../migrationlib/kdelibs4config.h" | 26 | #include "../migrationlib/kdelibs4config.h" | ||
28 | 27 | | |||
29 | void MouseSettings::apply(MouseBackend* backend, bool force) | 28 | void EvdevSettings::apply(X11Backend *backend, bool force) | ||
30 | { | 29 | { | ||
31 | if (!backend) { | 30 | if (!backend) { | ||
32 | return; | 31 | return; | ||
33 | } | 32 | } | ||
34 | 33 | | |||
35 | backend->apply(*this, force); | 34 | backend->apply(force); | ||
36 | handedNeedsApply = false; | 35 | handedNeedsApply = false; | ||
37 | } | 36 | } | ||
38 | 37 | | |||
39 | void MouseSettings::load(KConfig *config, MouseBackend *backend) | 38 | void EvdevSettings::load(X11Backend *backend) | ||
40 | { | 39 | { | ||
40 | KConfig config("kcminputrc"); | ||||
41 | | ||||
41 | // TODO: what's a good threshold default value | 42 | // TODO: what's a good threshold default value | ||
42 | int threshold = 0; | 43 | int threshold = 0; | ||
43 | handed = MouseHanded::Right; | 44 | handed = Handed::Right; | ||
44 | double accel = 1.0; | 45 | double accel = 1.0; | ||
45 | QString profile; | 46 | QString profile; | ||
46 | if (backend) { | 47 | if (backend) { | ||
47 | backend->load(); | | |||
48 | auto handedOnServer = backend->handed(); | 48 | auto handedOnServer = backend->handed(); | ||
49 | handedEnabled = handedOnServer != MouseHanded::NotSupported; | 49 | handedEnabled = handedOnServer != Handed::NotSupported; | ||
50 | if (handedEnabled) { | 50 | if (handedEnabled) { | ||
51 | handed = handedOnServer; | 51 | handed = handedOnServer; | ||
52 | } | 52 | } | ||
53 | accel = backend->accelRate(); | 53 | accel = backend->accelRate(); | ||
54 | threshold = backend->threshold(); | 54 | threshold = backend->threshold(); | ||
55 | profile = backend->accelerationProfile(); | 55 | profile = backend->accelerationProfile(); | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | KConfigGroup group = config->group("Mouse"); | 58 | KConfigGroup group = config.group("Mouse"); | ||
59 | double a = group.readEntry("Acceleration", -1.0); | 59 | double a = group.readEntry("Acceleration", -1.0); | ||
60 | if (a == -1) | 60 | if (a == -1) | ||
61 | accelRate = accel; | 61 | accelRate = accel; | ||
62 | else | 62 | else | ||
63 | accelRate = a; | 63 | accelRate = a; | ||
64 | 64 | | |||
65 | int t = group.readEntry("Threshold", -1); | 65 | int t = group.readEntry("Threshold", -1); | ||
66 | if (t == -1) | 66 | if (t == -1) | ||
67 | thresholdMove = threshold; | 67 | thresholdMove = threshold; | ||
68 | else | 68 | else | ||
69 | thresholdMove = t; | 69 | thresholdMove = t; | ||
70 | 70 | | |||
71 | QString key = group.readEntry("MouseButtonMapping"); | 71 | QString key = group.readEntry("MouseButtonMapping"); | ||
72 | if (key == "RightHanded") | 72 | if (key == "RightHanded") | ||
73 | handed = MouseHanded::Right; | 73 | handed = Handed::Right; | ||
74 | else if (key == "LeftHanded") | 74 | else if (key == "LeftHanded") | ||
75 | handed = MouseHanded::Left; | 75 | handed = Handed::Left; | ||
76 | reverseScrollPolarity = group.readEntry("ReverseScrollPolarity", false); | 76 | reverseScrollPolarity = group.readEntry("ReverseScrollPolarity", false); | ||
77 | currentAccelProfile = group.readEntry("AccelerationProfile"); | 77 | currentAccelProfile = group.readEntry("AccelerationProfile"); | ||
78 | if (currentAccelProfile.isEmpty()) { | 78 | if (currentAccelProfile.isEmpty()) { | ||
79 | currentAccelProfile = profile; | 79 | currentAccelProfile = profile; | ||
80 | } | 80 | } | ||
81 | handedNeedsApply = false; | 81 | handedNeedsApply = false; | ||
82 | 82 | | |||
83 | // SC/DC/AutoSelect/ChangeCursor | 83 | // SC/DC/AutoSelect/ChangeCursor | ||
84 | group = config->group("KDE"); | 84 | group = config.group("KDE"); | ||
85 | doubleClickInterval = group.readEntry("DoubleClickInterval", 400); | 85 | doubleClickInterval = group.readEntry("DoubleClickInterval", 400); | ||
86 | dragStartTime = group.readEntry("StartDragTime", 500); | 86 | dragStartTime = group.readEntry("StartDragTime", 500); | ||
87 | dragStartDist = group.readEntry("StartDragDist", 4); | 87 | dragStartDist = group.readEntry("StartDragDist", 4); | ||
88 | wheelScrollLines = group.readEntry("WheelScrollLines", 3); | 88 | wheelScrollLines = group.readEntry("WheelScrollLines", 3); | ||
89 | 89 | | |||
90 | singleClick = group.readEntry("SingleClick", true); | 90 | singleClick = group.readEntry("SingleClick", true); | ||
91 | } | 91 | } | ||
92 | 92 | | |||
Show All 14 Lines | 105 | { | |||
107 | QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange"); | 107 | QDBusMessage message = QDBusMessage::createSignal("/KGlobalSettings", "org.kde.KGlobalSettings", "notifyChange"); | ||
108 | QList<QVariant> args; | 108 | QList<QVariant> args; | ||
109 | args.append(static_cast<int>(changeType)); | 109 | args.append(static_cast<int>(changeType)); | ||
110 | args.append(arg); | 110 | args.append(arg); | ||
111 | message.setArguments(args); | 111 | message.setArguments(args); | ||
112 | QDBusConnection::sessionBus().send(message); | 112 | QDBusConnection::sessionBus().send(message); | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | void MouseSettings::save(KConfig *config) | 115 | void EvdevSettings::save() | ||
116 | { | 116 | { | ||
117 | KSharedConfig::Ptr kcminputProfile = KSharedConfig::openConfig("kcminputrc"); | 117 | KSharedConfig::Ptr kcminputProfile = KSharedConfig::openConfig("kcminputrc"); | ||
118 | KConfigGroup kcminputGroup(kcminputProfile, "Mouse"); | 118 | KConfigGroup kcminputGroup(kcminputProfile, "Mouse"); | ||
119 | kcminputGroup.writeEntry("Acceleration",accelRate); | 119 | kcminputGroup.writeEntry("Acceleration",accelRate); | ||
120 | kcminputGroup.writeEntry("Threshold",thresholdMove); | 120 | kcminputGroup.writeEntry("Threshold",thresholdMove); | ||
121 | if (handed == MouseHanded::Right) { | 121 | if (handed == Handed::Right) { | ||
122 | kcminputGroup.writeEntry("MouseButtonMapping",QString("RightHanded")); | 122 | kcminputGroup.writeEntry("MouseButtonMapping",QString("RightHanded")); | ||
123 | } else { | 123 | } else { | ||
124 | kcminputGroup.writeEntry("MouseButtonMapping",QString("LeftHanded")); | 124 | kcminputGroup.writeEntry("MouseButtonMapping",QString("LeftHanded")); | ||
125 | } | 125 | } | ||
126 | kcminputGroup.writeEntry("ReverseScrollPolarity", reverseScrollPolarity); | 126 | kcminputGroup.writeEntry("ReverseScrollPolarity", reverseScrollPolarity); | ||
127 | kcminputGroup.writeEntry("AccelerationProfile", currentAccelProfile); | 127 | kcminputGroup.writeEntry("AccelerationProfile", currentAccelProfile); | ||
128 | kcminputGroup.sync(); | 128 | kcminputGroup.sync(); | ||
129 | 129 | | |||
130 | KSharedConfig::Ptr profile = KSharedConfig::openConfig("kdeglobals"); | 130 | KSharedConfig::Ptr profile = KSharedConfig::openConfig("kdeglobals"); | ||
131 | KConfigGroup group(profile, "KDE"); | 131 | KConfigGroup group(profile, "KDE"); | ||
132 | group.writeEntry("DoubleClickInterval", doubleClickInterval, KConfig::Persistent); | 132 | group.writeEntry("DoubleClickInterval", doubleClickInterval, KConfig::Persistent); | ||
133 | group.writeEntry("StartDragTime", dragStartTime, KConfig::Persistent); | 133 | group.writeEntry("StartDragTime", dragStartTime, KConfig::Persistent); | ||
134 | group.writeEntry("StartDragDist", dragStartDist, KConfig::Persistent); | 134 | group.writeEntry("StartDragDist", dragStartDist, KConfig::Persistent); | ||
135 | group.writeEntry("WheelScrollLines", wheelScrollLines, KConfig::Persistent); | 135 | group.writeEntry("WheelScrollLines", wheelScrollLines, KConfig::Persistent); | ||
136 | group.writeEntry("SingleClick", singleClick, KConfig::Persistent); | 136 | group.writeEntry("SingleClick", singleClick, KConfig::Persistent); | ||
137 | 137 | | |||
138 | group.sync(); | 138 | group.sync(); | ||
139 | config->sync(); | 139 | kcminputProfile->sync(); | ||
140 | 140 | | |||
141 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("Mouse"), "kcminputrc"); | 141 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("Mouse"), "kcminputrc"); | ||
142 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("KDE"), "kdeglobals"); | 142 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("KDE"), "kdeglobals"); | ||
143 | 143 | | |||
144 | emitChange(SettingsChanged, SETTINGS_MOUSE); | 144 | emitChange(SettingsChanged, SETTINGS_MOUSE); | ||
145 | } | 145 | } |