Changeset View
Changeset View
Standalone View
Standalone View
kcms/input/kcm/xlib/xlib_config.cpp
Show All 20 Lines | |||||
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. | ||
22 | * | 22 | * | ||
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | 24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 25 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
26 | */ | 26 | */ | ||
27 | #include "xlib_config.h" | 27 | #include "xlib_config.h" | ||
28 | 28 | | |||
29 | #include "backends/x11/x11_backend.h" | 29 | #include "backends/x11/x11_evdev_backend.h" | ||
30 | #include "../configcontainer.h" | 30 | #include "../configcontainer.h" | ||
31 | 31 | | |||
32 | #include "../../../migrationlib/kdelibs4config.h" | 32 | #include "../../../migrationlib/kdelibs4config.h" | ||
33 | 33 | | |||
34 | #include <kglobalsettings.h> | 34 | #include <kglobalsettings.h> | ||
35 | #include <config-workspace.h> | 35 | #include <config-workspace.h> | ||
36 | 36 | | |||
37 | #include <ktoolinvocation.h> | 37 | #include <ktoolinvocation.h> | ||
38 | #include <klocalizedstring.h> | 38 | #include <klocalizedstring.h> | ||
39 | //#include <kconfig.h> | 39 | //#include <kconfig.h> | ||
40 | #include <kstandarddirs.h> | 40 | #include <kstandarddirs.h> | ||
41 | #include <kaboutdata.h> | 41 | #include <kaboutdata.h> | ||
42 | #include <KPluginFactory> | 42 | #include <KPluginFactory> | ||
43 | #include <KPluginLoader> | 43 | #include <KPluginLoader> | ||
44 | 44 | | |||
45 | #include <QCheckBox> | 45 | #include <QCheckBox> | ||
46 | #include <QDoubleSpinBox> | 46 | #include <QDoubleSpinBox> | ||
47 | #include <QFormLayout> | 47 | #include <QFormLayout> | ||
48 | #include <QSpinBox> | 48 | #include <QSpinBox> | ||
49 | #include <QWhatsThis> | 49 | #include <QWhatsThis> | ||
50 | #include <QTabWidget> | 50 | #include <QTabWidget> | ||
51 | 51 | | |||
52 | #include <klauncher_iface.h> | | |||
53 | | ||||
54 | #include <KConfig> | 52 | #include <KConfig> | ||
55 | #include <KConfigGroup> | 53 | #include <KConfigGroup> | ||
56 | 54 | | |||
57 | void XlibConfig::kcmInit() | | |||
58 | { | | |||
59 | X11Backend *backend = dynamic_cast<X11Backend*>(InputBackend::implementation()); | | |||
60 | if (!backend) { | | |||
61 | return; | | |||
62 | } | | |||
63 | | ||||
64 | backend->settings()->load(backend); | | |||
65 | backend->settings()->apply(backend, true); // force | | |||
66 | | ||||
67 | KConfigGroup group = KConfig("kcminputrc", KConfig::NoGlobals).group("Mouse"); | | |||
68 | QString theme = group.readEntry("cursorTheme", QString()); | | |||
69 | QString size = group.readEntry("cursorSize", QString()); | | |||
70 | if (backend) { | | |||
71 | int intSize = -1; | | |||
72 | if (size.isEmpty()) { | | |||
73 | bool ok; | | |||
74 | uint value = size.toUInt(&ok); | | |||
75 | if (ok) { | | |||
76 | intSize = value; | | |||
77 | } | | |||
78 | } | | |||
79 | // Note: If you update this code, update kapplymousetheme as well. | | |||
80 | | ||||
81 | // use a default value for theme only if it's not configured at all, not even in X resources | | |||
82 | if (theme.isEmpty() && backend->currentCursorTheme().isEmpty()) { | | |||
83 | theme = "breeze_cursors"; | | |||
84 | } | | |||
85 | backend->applyCursorTheme(theme, intSize); | | |||
86 | } | | |||
87 | | ||||
88 | // Tell klauncher to set the XCURSOR_THEME and XCURSOR_SIZE environment | | |||
89 | // variables when launching applications. | | |||
90 | OrgKdeKLauncherInterface klauncher(QStringLiteral("org.kde.klauncher5"), | | |||
91 | QStringLiteral("/KLauncher"), | | |||
92 | QDBusConnection::sessionBus()); | | |||
93 | if (!theme.isEmpty()) { | | |||
94 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_THEME"), theme); | | |||
95 | } | | |||
96 | if (!size.isEmpty()) { | | |||
97 | klauncher.setLaunchEnv(QStringLiteral("XCURSOR_SIZE"), size); | | |||
98 | } | | |||
99 | } | | |||
100 | | ||||
101 | XlibConfig::XlibConfig(ConfigContainer *parent, InputBackend *backend) | 55 | XlibConfig::XlibConfig(ConfigContainer *parent, InputBackend *backend) | ||
102 | : ConfigPlugin(parent), | 56 | : ConfigPlugin(parent), | ||
103 | m_backend(dynamic_cast<X11Backend*>(backend)) | 57 | m_backend(dynamic_cast<X11EvdevBackend*>(backend)) | ||
104 | { | 58 | { | ||
105 | setupUi(this); | 59 | setupUi(this); | ||
106 | 60 | | |||
107 | handedGroup->setId(rightHanded, static_cast<int>(Handed::Right)); | 61 | handedGroup->setId(rightHanded, static_cast<int>(Handed::Right)); | ||
108 | handedGroup->setId(leftHanded, static_cast<int>(Handed::Left)); | 62 | handedGroup->setId(leftHanded, static_cast<int>(Handed::Left)); | ||
109 | 63 | | |||
110 | connect(handedGroup, SIGNAL(buttonClicked(int)), m_parent, SLOT(changed())); | 64 | connect(handedGroup, SIGNAL(buttonClicked(int)), m_parent, SLOT(changed())); | ||
111 | connect(handedGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotHandedChanged(int))); | 65 | connect(handedGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotHandedChanged(int))); | ||
112 | connect(doubleClick, SIGNAL(clicked()), m_parent, SLOT(changed())); | 66 | connect(doubleClick, SIGNAL(clicked()), m_parent, SLOT(changed())); | ||
113 | 67 | | |||
114 | connect(singleClick, SIGNAL(clicked()), m_parent, SLOT(changed())); | 68 | connect(singleClick, SIGNAL(clicked()), m_parent, SLOT(changed())); | ||
115 | connect(cbScrollPolarity, SIGNAL(clicked()), m_parent, SLOT(changed())); | 69 | connect(cbScrollPolarity, SIGNAL(clicked()), m_parent, SLOT(changed())); | ||
116 | connect(cbScrollPolarity, SIGNAL(clicked()), this, SLOT(slotScrollPolarityChanged())); | 70 | connect(cbScrollPolarity, SIGNAL(clicked()), this, SLOT(slotScrollPolarityChanged())); | ||
117 | 71 | | |||
118 | connect(accel, SIGNAL(valueChanged(double)), m_parent, SLOT(changed())); | 72 | connect(accel, SIGNAL(valueChanged(double)), m_parent, SLOT(changed())); | ||
119 | connect(thresh, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | 73 | connect(thresh, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | ||
120 | connect(thresh, SIGNAL(valueChanged(int)), this, SLOT(slotThreshChanged(int))); | 74 | connect(thresh, SIGNAL(valueChanged(int)), this, SLOT(slotThreshChanged(int))); | ||
121 | connect(accelProfileComboBox, SIGNAL(currentIndexChanged(int)), m_parent, SLOT(changed())); | | |||
122 | slotThreshChanged(thresh->value()); | 75 | slotThreshChanged(thresh->value()); | ||
123 | 76 | | |||
124 | // It would be nice if the user had a test field. | 77 | // It would be nice if the user had a test field. | ||
125 | // Selecting such values in milliseconds is not intuitive | 78 | // Selecting such values in milliseconds is not intuitive | ||
126 | connect(doubleClickInterval, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | 79 | connect(doubleClickInterval, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | ||
127 | 80 | | |||
128 | connect(dragStartTime, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | 81 | connect(dragStartTime, SIGNAL(valueChanged(int)), m_parent, SLOT(changed())); | ||
129 | 82 | | |||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 153 | { | |||
206 | } | 159 | } | ||
207 | else { | 160 | else { | ||
208 | leftHanded->setChecked(true); | 161 | leftHanded->setChecked(true); | ||
209 | mousePix->setPixmap(KStandardDirs::locate("data", "kcminput/pics/mouse_lh.png")); | 162 | mousePix->setPixmap(KStandardDirs::locate("data", "kcminput/pics/mouse_lh.png")); | ||
210 | } | 163 | } | ||
211 | m_backend->settings()->handedNeedsApply = true; | 164 | m_backend->settings()->handedNeedsApply = true; | ||
212 | } | 165 | } | ||
213 | 166 | | |||
214 | | ||||
215 | | ||||
216 | | ||||
217 | void XlibConfig::load() | 167 | void XlibConfig::load() | ||
218 | { | 168 | { | ||
219 | EvdevSettings *settings = m_backend->settings(); | 169 | EvdevSettings *settings = m_backend->settings(); | ||
220 | 170 | | |||
221 | m_parent->kcmLoad(); | 171 | m_parent->kcmLoad(); | ||
222 | m_backend->load(); | 172 | m_backend->load(); | ||
223 | 173 | | |||
224 | // Only allow setting reversing scroll polarity if we have scroll buttons | 174 | // Only allow setting reversing scroll polarity if we have scroll buttons | ||
225 | if (m_backend) { | 175 | if (m_backend) { | ||
226 | if (m_backend->supportScrollPolarity()) | 176 | if (m_backend->supportScrollPolarity()) | ||
227 | { | 177 | { | ||
228 | cbScrollPolarity->setEnabled(true); | 178 | cbScrollPolarity->setEnabled(true); | ||
229 | cbScrollPolarity->show(); | 179 | cbScrollPolarity->show(); | ||
230 | } | 180 | } | ||
231 | else | 181 | else | ||
232 | { | 182 | { | ||
233 | cbScrollPolarity->setEnabled(false); | 183 | cbScrollPolarity->setEnabled(false); | ||
234 | cbScrollPolarity->hide(); | 184 | cbScrollPolarity->hide(); | ||
235 | } | 185 | } | ||
236 | } | 186 | } | ||
237 | 187 | | |||
238 | auto accelerationProfiles = m_backend->supportedAccelerationProfiles(); | | |||
239 | accelProfileComboBox->setEnabled(!accelerationProfiles.isEmpty()); | | |||
240 | accelProfileComboBox->setVisible(!accelerationProfiles.isEmpty()); | | |||
241 | accelerationProfileLabel->setEnabled(!accelerationProfiles.isEmpty()); | | |||
242 | accelerationProfileLabel->setVisible(!accelerationProfiles.isEmpty()); | | |||
243 | accelProfileComboBox->clear(); | | |||
244 | int idx = 0; | | |||
245 | for (const auto &profile : accelerationProfiles) { | | |||
246 | accelProfileComboBox->addItem(i18n(profile.toUtf8().constData()), profile); | | |||
247 | if (profile == settings->currentAccelProfile) { | | |||
248 | accelProfileComboBox->setCurrentIndex(idx); | | |||
249 | } | | |||
250 | idx++; | | |||
251 | } | | |||
252 | | ||||
253 | rightHanded->setEnabled(settings->handedEnabled); | 188 | rightHanded->setEnabled(settings->handedEnabled); | ||
254 | leftHanded->setEnabled(settings->handedEnabled); | 189 | leftHanded->setEnabled(settings->handedEnabled); | ||
255 | if (cbScrollPolarity->isEnabled()) | 190 | if (cbScrollPolarity->isEnabled()) | ||
256 | cbScrollPolarity->setEnabled(settings->handedEnabled); | 191 | cbScrollPolarity->setEnabled(settings->handedEnabled); | ||
257 | cbScrollPolarity->setChecked(settings->reverseScrollPolarity); | 192 | cbScrollPolarity->setChecked(settings->reverseScrollPolarity); | ||
258 | 193 | | |||
259 | setAccel(settings->accelRate); | 194 | setAccel(settings->accelRate); | ||
260 | setThreshold(settings->thresholdMove); | 195 | setThreshold(settings->thresholdMove); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 237 | { | |||
307 | settings->handed = getHandedness(); | 242 | settings->handed = getHandedness(); | ||
308 | 243 | | |||
309 | settings->doubleClickInterval = doubleClickInterval->value(); | 244 | settings->doubleClickInterval = doubleClickInterval->value(); | ||
310 | settings->dragStartTime = dragStartTime->value(); | 245 | settings->dragStartTime = dragStartTime->value(); | ||
311 | settings->dragStartDist = dragStartDist->value(); | 246 | settings->dragStartDist = dragStartDist->value(); | ||
312 | settings->wheelScrollLines = wheelScrollLines->value(); | 247 | settings->wheelScrollLines = wheelScrollLines->value(); | ||
313 | settings->singleClick = !doubleClick->isChecked(); | 248 | settings->singleClick = !doubleClick->isChecked(); | ||
314 | settings->reverseScrollPolarity = cbScrollPolarity->isChecked(); | 249 | settings->reverseScrollPolarity = cbScrollPolarity->isChecked(); | ||
315 | settings->currentAccelProfile = accelProfileComboBox->itemData(accelProfileComboBox->currentIndex()).toString(); | | |||
316 | 250 | | |||
317 | m_backend->apply(); | 251 | m_backend->apply(); | ||
318 | settings->save(); | 252 | settings->save(); | ||
319 | 253 | | |||
320 | KConfig ac("kaccessrc"); | 254 | KConfig ac("kaccessrc"); | ||
321 | 255 | | |||
322 | KConfigGroup group = ac.group("Mouse"); | 256 | KConfigGroup group = ac.group("Mouse"); | ||
323 | 257 | | |||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |