Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwinscreenedges/touch.cpp
1 | /******************************************************************** | 1 | /******************************************************************** | ||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | 2 | KWin - the KDE window manager | ||
3 | This file is part of the KDE project. | 3 | This file is part of the KDE project. | ||
4 | 4 | | |||
5 | Copyright (C) 2008 Martin Gräßlin <mgraesslin@kde.org> | 5 | Copyright (C) 2008 Martin Gräßlin <mgraesslin@kde.org> | ||
6 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | 6 | Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com> | ||
7 | Copyright (C) 2020 Cyril Rossi <cyril.rossi@enioka.com> | ||||
7 | 8 | | |||
8 | This program is free software; you can redistribute it and/or modify | 9 | This program is free software; you can redistribute it and/or modify | ||
9 | it under the terms of the GNU General Public License as published by | 10 | it under the terms of the GNU General Public License as published by | ||
10 | the Free Software Foundation; either version 2 of the License, or | 11 | the Free Software Foundation; either version 2 of the License, or | ||
11 | (at your option) any later version. | 12 | (at your option) any later version. | ||
12 | 13 | | |||
13 | This program is distributed in the hope that it will be useful, | 14 | This program is distributed in the hope that it will be useful, | ||
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
Show All 10 Lines | |||||
25 | 26 | | |||
26 | #include <KAboutData> | 27 | #include <KAboutData> | ||
27 | #include <KConfigGroup> | 28 | #include <KConfigGroup> | ||
28 | #include <KLocalizedString> | 29 | #include <KLocalizedString> | ||
29 | #include <KPluginFactory> | 30 | #include <KPluginFactory> | ||
30 | #include <KPackage/Package> | 31 | #include <KPackage/Package> | ||
31 | #include <KPackage/PackageLoader> | 32 | #include <KPackage/PackageLoader> | ||
32 | #include <QtDBus> | 33 | #include <QtDBus> | ||
34 | #include <QVBoxLayout> | ||||
35 | | ||||
36 | #include "kwintouchscreenedgeconfigform.h" | ||||
37 | #include "kwintouchscreensettings.h" | ||||
38 | #include "kwintouchscreenscriptsettings.h" | ||||
33 | 39 | | |||
34 | K_PLUGIN_FACTORY(KWinScreenEdgesConfigFactory, registerPlugin<KWin::KWinScreenEdgesConfig>();) | 40 | K_PLUGIN_FACTORY(KWinScreenEdgesConfigFactory, registerPlugin<KWin::KWinScreenEdgesConfig>();) | ||
35 | 41 | | |||
36 | namespace KWin | 42 | namespace KWin | ||
37 | { | 43 | { | ||
38 | 44 | | |||
39 | KWinScreenEdgesConfigForm::KWinScreenEdgesConfigForm(QWidget* parent) | | |||
40 | : QWidget(parent) | | |||
41 | { | | |||
42 | setupUi(this); | | |||
43 | } | | |||
44 | | ||||
45 | KWinScreenEdgesConfig::KWinScreenEdgesConfig(QWidget* parent, const QVariantList& args) | 45 | KWinScreenEdgesConfig::KWinScreenEdgesConfig(QWidget *parent, const QVariantList &args) | ||
46 | : KCModule(parent, args) | 46 | : KCModule(parent, args) | ||
47 | , m_form(new KWinTouchScreenEdgeConfigForm(this)) | ||||
47 | , m_config(KSharedConfig::openConfig("kwinrc")) | 48 | , m_config(KSharedConfig::openConfig("kwinrc")) | ||
49 | , m_settings(new KWinTouchScreenSettings(this)) | ||||
48 | { | 50 | { | ||
49 | m_ui = new KWinScreenEdgesConfigForm(this); | | |||
50 | QVBoxLayout* layout = new QVBoxLayout(this); | 51 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
ervin: This would be better in the initialization list. Also this is leaked. | |||||
Agree, much better to put in initialization list. crossi: Agree, much better to put in initialization list.
It's not leaked, I renamed it to m_form since… | |||||
ervin: Ah indeed, stupid me. | |||||
51 | layout->addWidget(m_ui); | 52 | layout->addWidget(m_form); | ||
52 | 53 | | |||
53 | monitorInit(); | 54 | monitorInit(); | ||
54 | 55 | | |||
55 | connect(m_ui->monitor, SIGNAL(changed()), this, SLOT(changed())); | 56 | connect(m_form, &KWinTouchScreenEdgeConfigForm::saveNeededChanged, this, &KWinScreenEdgesConfig::unmanagedWidgetChangeState); | ||
56 | 57 | connect(m_form, &KWinTouchScreenEdgeConfigForm::defaultChanged, this, &KWinScreenEdgesConfig::unmanagedWidgetDefaultState); | |||
57 | load(); | | |||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | KWinScreenEdgesConfig::~KWinScreenEdgesConfig() | 60 | KWinScreenEdgesConfig::~KWinScreenEdgesConfig() | ||
61 | { | 61 | { | ||
62 | } | 62 | } | ||
63 | 63 | | |||
64 | void KWinScreenEdgesConfig::load() | 64 | void KWinScreenEdgesConfig::load() | ||
65 | { | 65 | { | ||
66 | KCModule::load(); | 66 | KCModule::load(); | ||
67 | m_settings->load(); | ||||
68 | for (KWinTouchScreenScriptSettings *setting : qAsConst(m_scriptSettings)) { | ||||
Could you please use an explicit type here? It's not obvious what type setting has. https://community.kde.org/Policies/Library_Code_Policy#auto_Keyword zzag: Could you please use an explicit type here? It's not obvious what type `setting` has.
https… | |||||
If I had my way this policy would get an update. This is "obviously" a setting object so it can be loaded. ;-) More seriously, and more importantly (to me) this lacks a qAsConst for m_scriptSettings ervin: If I had my way this policy would get an update. This is "obviously" a setting object so it can… | |||||
69 | setting->load(); | ||||
70 | } | ||||
67 | 71 | | |||
68 | monitorLoad(); | 72 | monitorLoadSettings(); | ||
69 | 73 | monitorLoadDefaultSettings(); | |||
70 | emit changed(false); | 74 | m_form->reload(); | ||
71 | } | 75 | } | ||
72 | 76 | | |||
73 | void KWinScreenEdgesConfig::save() | 77 | void KWinScreenEdgesConfig::save() | ||
74 | { | 78 | { | ||
75 | KCModule::save(); | 79 | monitorSaveSettings(); | ||
80 | m_settings->save(); | ||||
81 | for (KWinTouchScreenScriptSettings *setting : qAsConst(m_scriptSettings)) { | ||||
82 | setting->save(); | ||||
83 | } | ||||
76 | 84 | | |||
77 | monitorSave(); | 85 | // Reload saved settings to ScreenEdge UI | ||
86 | monitorLoadSettings(); | ||||
87 | m_form->reload(); | ||||
ervin: qAsConst missing | |||||
78 | 88 | | |||
79 | // Reload KWin. | 89 | // Reload KWin. | ||
80 | QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); | 90 | QDBusMessage message = QDBusMessage::createSignal("/KWin", "org.kde.KWin", "reloadConfig"); | ||
81 | QDBusConnection::sessionBus().send(message); | 91 | QDBusConnection::sessionBus().send(message); | ||
82 | // and reconfigure the effects | 92 | // and reconfigure the effects | ||
83 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | 93 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||
84 | QStringLiteral("/Effects"), | 94 | QStringLiteral("/Effects"), | ||
85 | QDBusConnection::sessionBus()); | 95 | QDBusConnection::sessionBus()); | ||
86 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::PresentWindows)); | 96 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::PresentWindows)); | ||
87 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::DesktopGrid)); | 97 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::DesktopGrid)); | ||
88 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::Cube)); | 98 | interface.reconfigureEffect(BuiltInEffects::nameForEffect(BuiltInEffect::Cube)); | ||
89 | 99 | | |||
90 | emit changed(false); | 100 | KCModule::save(); | ||
91 | } | 101 | } | ||
92 | 102 | | |||
93 | void KWinScreenEdgesConfig::defaults() | 103 | void KWinScreenEdgesConfig::defaults() | ||
94 | { | 104 | { | ||
95 | monitorDefaults(); | 105 | m_form->setDefaults(); | ||
96 | 106 | | |||
97 | emit changed(true); | 107 | KCModule::defaults(); | ||
98 | } | 108 | } | ||
ervin: qAsConst missing | |||||
99 | 109 | | |||
100 | void KWinScreenEdgesConfig::showEvent(QShowEvent* e) | 110 | void KWinScreenEdgesConfig::showEvent(QShowEvent* e) | ||
101 | { | 111 | { | ||
102 | KCModule::showEvent(e); | 112 | KCModule::showEvent(e); | ||
103 | 113 | | |||
104 | monitorShowEvent(); | 114 | monitorShowEvent(); | ||
105 | } | 115 | } | ||
106 | 116 | | |||
107 | // Copied from kcmkwin/kwincompositing/main.cpp | 117 | // Copied from kcmkwin/kwincompositing/main.cpp | ||
108 | bool KWinScreenEdgesConfig::effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const | 118 | bool KWinScreenEdgesConfig::effectEnabled(const BuiltInEffect& effect, const KConfigGroup& cfg) const | ||
109 | { | 119 | { | ||
110 | return cfg.readEntry(BuiltInEffects::nameForEffect(effect) + "Enabled", BuiltInEffects::enabledByDefault(effect)); | 120 | return cfg.readEntry(BuiltInEffects::nameForEffect(effect) + "Enabled", BuiltInEffects::enabledByDefault(effect)); | ||
111 | } | 121 | } | ||
112 | 122 | | |||
113 | //----------------------------------------------------------------------------- | 123 | //----------------------------------------------------------------------------- | ||
114 | // Monitor | 124 | // Monitor | ||
115 | 125 | | |||
116 | void KWinScreenEdgesConfig::monitorAddItem(const QString& item) | | |||
117 | { | | |||
118 | for (int i = 0; i < 8; i++) | | |||
119 | m_ui->monitor->addEdgeItem(i, item); | | |||
120 | } | | |||
121 | | ||||
122 | void KWinScreenEdgesConfig::monitorItemSetEnabled(int index, bool enabled) | | |||
123 | { | | |||
124 | for (int i = 0; i < 8; i++) | | |||
125 | m_ui->monitor->setEdgeItemEnabled(i, index, enabled); | | |||
126 | } | | |||
127 | | ||||
128 | void KWinScreenEdgesConfig::monitorInit() | 126 | void KWinScreenEdgesConfig::monitorInit() | ||
129 | { | 127 | { | ||
130 | monitorAddItem(i18n("No Action")); | 128 | m_form->monitorHideEdge(ElectricTopLeft, true); | ||
131 | monitorAddItem(i18n("Show Desktop")); | 129 | m_form->monitorHideEdge(ElectricTopRight, true); | ||
132 | monitorAddItem(i18n("Lock Screen")); | 130 | m_form->monitorHideEdge(ElectricBottomRight, true); | ||
133 | monitorAddItem(i18n("Show KRunner")); | 131 | m_form->monitorHideEdge(ElectricBottomLeft, true); | ||
134 | monitorAddItem(i18n("Activity Manager")); | 132 | | ||
135 | monitorAddItem(i18n("Application Launcher")); | 133 | m_form->monitorAddItem(i18n("No Action")); | ||
134 | m_form->monitorAddItem(i18n("Show Desktop")); | ||||
135 | m_form->monitorAddItem(i18n("Lock Screen")); | ||||
136 | m_form->monitorAddItem(i18n("Show KRunner")); | ||||
137 | m_form->monitorAddItem(i18n("Activity Manager")); | ||||
138 | m_form->monitorAddItem(i18n("Application Launcher")); | ||||
136 | 139 | | |||
137 | // Add the effects | 140 | // Add the effects | ||
138 | const QString presentWindowsName = BuiltInEffects::effectData(BuiltInEffect::PresentWindows).displayName; | 141 | const QString presentWindowsName = BuiltInEffects::effectData(BuiltInEffect::PresentWindows).displayName; | ||
139 | monitorAddItem(i18n("%1 - All Desktops", presentWindowsName)); | 142 | m_form->monitorAddItem(i18n("%1 - All Desktops", presentWindowsName)); | ||
140 | monitorAddItem(i18n("%1 - Current Desktop", presentWindowsName)); | 143 | m_form->monitorAddItem(i18n("%1 - Current Desktop", presentWindowsName)); | ||
141 | monitorAddItem(i18n("%1 - Current Application", presentWindowsName)); | 144 | m_form->monitorAddItem(i18n("%1 - Current Application", presentWindowsName)); | ||
142 | monitorAddItem(BuiltInEffects::effectData(BuiltInEffect::DesktopGrid).displayName); | 145 | m_form->monitorAddItem(BuiltInEffects::effectData(BuiltInEffect::DesktopGrid).displayName); | ||
143 | const QString cubeName = BuiltInEffects::effectData(BuiltInEffect::Cube).displayName; | 146 | const QString cubeName = BuiltInEffects::effectData(BuiltInEffect::Cube).displayName; | ||
144 | monitorAddItem(i18n("%1 - Cube", cubeName)); | 147 | m_form->monitorAddItem(i18n("%1 - Cube", cubeName)); | ||
145 | monitorAddItem(i18n("%1 - Cylinder", cubeName)); | 148 | m_form->monitorAddItem(i18n("%1 - Cylinder", cubeName)); | ||
146 | monitorAddItem(i18n("%1 - Sphere", cubeName)); | 149 | m_form->monitorAddItem(i18n("%1 - Sphere", cubeName)); | ||
147 | 150 | | |||
148 | monitorAddItem(i18n("Toggle window switching")); | 151 | m_form->monitorAddItem(i18n("Toggle window switching")); | ||
149 | monitorAddItem(i18n("Toggle alternative window switching")); | 152 | m_form->monitorAddItem(i18n("Toggle alternative window switching")); | ||
150 | 153 | | |||
151 | const QString scriptFolder = QStringLiteral("kwin/scripts/"); | 154 | const QString scriptFolder = QStringLiteral("kwin/scripts/"); | ||
152 | const auto scripts = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KWin/Script"), scriptFolder); | 155 | const auto scripts = KPackage::PackageLoader::self()->listPackages(QStringLiteral("KWin/Script"), scriptFolder); | ||
153 | 156 | | |||
154 | KConfigGroup config(m_config, "Plugins"); | 157 | KConfigGroup config(m_config, "Plugins"); | ||
155 | for (const KPluginMetaData &script: scripts) { | 158 | for (const KPluginMetaData &script: scripts) { | ||
156 | if (script.value(QStringLiteral("X-KWin-Border-Activate")) != QLatin1String("true")) { | 159 | if (script.value(QStringLiteral("X-KWin-Border-Activate")) != QLatin1String("true")) { | ||
157 | continue; | 160 | continue; | ||
158 | } | 161 | } | ||
159 | 162 | | |||
160 | if (!config.readEntry(script.pluginId() + QStringLiteral("Enabled"), script.isEnabledByDefault())) { | 163 | if (!config.readEntry(script.pluginId() + QStringLiteral("Enabled"), script.isEnabledByDefault())) { | ||
161 | continue; | 164 | continue; | ||
162 | } | 165 | } | ||
163 | m_scripts << script.pluginId(); | 166 | m_scripts << script.pluginId(); | ||
164 | monitorAddItem(script.name()); | 167 | m_form->monitorAddItem(script.name()); | ||
168 | m_scriptSettings[script.pluginId()] = new KWinTouchScreenScriptSettings(script.pluginId(), this); | ||||
165 | } | 169 | } | ||
166 | 170 | | |||
167 | monitorHideEdge(ElectricTopLeft, true); | | |||
168 | monitorHideEdge(ElectricTopRight, true); | | |||
169 | monitorHideEdge(ElectricBottomRight, true); | | |||
170 | monitorHideEdge(ElectricBottomLeft, true); | | |||
171 | | ||||
172 | monitorShowEvent(); | 171 | monitorShowEvent(); | ||
173 | } | 172 | } | ||
174 | 173 | | |||
175 | void KWinScreenEdgesConfig::monitorLoadAction(ElectricBorder edge, const QString& configName) | 174 | void KWinScreenEdgesConfig::monitorLoadSettings() | ||
176 | { | | |||
177 | KConfigGroup config(m_config, "TouchEdges"); | | |||
178 | QString lowerName = config.readEntry(configName, "None").toLower(); | | |||
179 | if (lowerName == "showdesktop") monitorChangeEdge(edge, int(ElectricActionShowDesktop)); | | |||
180 | else if (lowerName == "lockscreen") monitorChangeEdge(edge, int(ElectricActionLockScreen)); | | |||
181 | else if (lowerName == "krunner") monitorChangeEdge(edge, int(ElectricActionKRunner)); | | |||
182 | else if (lowerName == "activitymanager") monitorChangeEdge(edge, int(ElectricActionActivityManager)); | | |||
183 | else if (lowerName == "applicationlauncher") monitorChangeEdge(edge, int(ElectricActionApplicationLauncher)); | | |||
184 | } | | |||
185 | | ||||
186 | void KWinScreenEdgesConfig::monitorLoad() | | |||
187 | { | 175 | { | ||
188 | // Load ElectricBorderActions | 176 | // Load ElectricBorderActions | ||
189 | monitorLoadAction(ElectricTop, "Top"); | 177 | m_form->monitorChangeEdge(ElectricTop, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->top())); | ||
190 | monitorLoadAction(ElectricRight, "Right"); | 178 | m_form->monitorChangeEdge(ElectricRight, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->right())); | ||
191 | monitorLoadAction(ElectricBottom, "Bottom"); | 179 | m_form->monitorChangeEdge(ElectricBottom, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->bottom())); | ||
192 | monitorLoadAction(ElectricLeft, "Left"); | 180 | m_form->monitorChangeEdge(ElectricLeft, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->left())); | ||
193 | 181 | | |||
194 | // Load effect-specific actions: | 182 | // Load effect-specific actions: | ||
195 | 183 | | |||
196 | // Present Windows | | |||
197 | KConfigGroup presentWindowsConfig(m_config, "Effect-PresentWindows"); | | |||
198 | QList<int> list = QList<int>(); | | |||
199 | // PresentWindows BorderActivateAll | 184 | // Present Windows BorderActivateAll | ||
200 | list.append(int(ElectricTopLeft)); | 185 | m_form->monitorChangeEdge(m_settings->touchBorderActivateAll(), PresentWindowsAll); | ||
ervin: Since you're touching those lines anyway, please clean up the c-casts to int | |||||
201 | list = presentWindowsConfig.readEntry("TouchBorderActivateAll", list); | | |||
202 | foreach (int i, list) { | | |||
203 | monitorChangeEdge(ElectricBorder(i), int(PresentWindowsAll)); | | |||
204 | } | | |||
205 | // PresentWindows BorderActivate | 186 | // PresentWindows BorderActivate | ||
206 | list.clear(); | 187 | m_form->monitorChangeEdge(m_settings->touchBorderActivatePresentWindows(), PresentWindowsCurrent); | ||
207 | list.append(int(ElectricNone)); | | |||
208 | list = presentWindowsConfig.readEntry("TouchBorderActivate", list); | | |||
209 | foreach (int i, list) { | | |||
210 | monitorChangeEdge(ElectricBorder(i), int(PresentWindowsCurrent)); | | |||
211 | } | | |||
212 | // PresentWindows BorderActivateClass | 188 | // PresentWindows BorderActivateClass | ||
213 | list.clear(); | 189 | m_form->monitorChangeEdge(m_settings->touchBorderActivateClass(), PresentWindowsClass); | ||
214 | list.append(int(ElectricNone)); | | |||
215 | list = presentWindowsConfig.readEntry("TouchBorderActivateClass", list); | | |||
216 | foreach (int i, list) { | | |||
217 | monitorChangeEdge(ElectricBorder(i), int(PresentWindowsClass)); | | |||
218 | } | | |||
219 | 190 | | |||
220 | // Desktop Grid | 191 | // Desktop Grid BorderActivate | ||
221 | KConfigGroup gridConfig(m_config, "Effect-DesktopGrid"); | 192 | m_form->monitorChangeEdge(m_settings->touchBorderActivateDesktopGrid(), DesktopGrid); | ||
222 | list.clear(); | | |||
223 | list.append(int(ElectricNone)); | | |||
224 | list = gridConfig.readEntry("TouchBorderActivate", list); | | |||
225 | foreach (int i, list) { | | |||
226 | monitorChangeEdge(ElectricBorder(i), int(DesktopGrid)); | | |||
227 | } | | |||
228 | 193 | | |||
229 | // Desktop Cube | 194 | // Desktop Cube BorderActivate | ||
230 | KConfigGroup cubeConfig(m_config, "Effect-Cube"); | 195 | m_form->monitorChangeEdge(m_settings->touchBorderActivateCube(), Cube); | ||
231 | list.clear(); | 196 | // Desktop Cube BorderActivateCylinder | ||
232 | list.append(int(ElectricNone)); | 197 | m_form->monitorChangeEdge(m_settings->touchBorderActivateCylinder(), Cylinder); | ||
233 | list = cubeConfig.readEntry("TouchBorderActivate", list); | 198 | // Desktop Cube BorderActivateSphere | ||
234 | foreach (int i, list) { | 199 | m_form->monitorChangeEdge(m_settings->touchBorderActivateSphere(), Sphere); | ||
235 | monitorChangeEdge(ElectricBorder(i), int(Cube)); | | |||
236 | } | | |||
237 | list.clear(); | | |||
238 | list.append(int(ElectricNone)); | | |||
239 | list = cubeConfig.readEntry("TouchBorderActivateCylinder", list); | | |||
240 | foreach (int i, list) { | | |||
241 | monitorChangeEdge(ElectricBorder(i), int(Cylinder)); | | |||
242 | } | | |||
243 | list.clear(); | | |||
244 | list.append(int(ElectricNone)); | | |||
245 | list = cubeConfig.readEntry("TouchBorderActivateSphere", list); | | |||
246 | foreach (int i, list) { | | |||
247 | monitorChangeEdge(ElectricBorder(i), int(Sphere)); | | |||
248 | } | | |||
249 | 200 | | |||
250 | // TabBox | 201 | // TabBox BorderActivate | ||
251 | KConfigGroup tabBoxConfig(m_config, "TabBox"); | 202 | m_form->monitorChangeEdge(m_settings->touchBorderActivateTabBox(), TabBox); | ||
252 | list.clear(); | | |||
253 | // TabBox | | |||
254 | list.append(int(ElectricLeft)); | | |||
255 | list = tabBoxConfig.readEntry("TouchBorderActivate", list); | | |||
256 | foreach (int i, list) { | | |||
257 | monitorChangeEdge(ElectricBorder(i), int(TabBox)); | | |||
258 | } | | |||
259 | // Alternative TabBox | 203 | // Alternative TabBox | ||
260 | list.clear(); | 204 | m_form->monitorChangeEdge(m_settings->touchBorderAlternativeActivate(), TabBoxAlternative); | ||
261 | list.append(int(ElectricNone)); | | |||
262 | list = tabBoxConfig.readEntry("TouchBorderAlternativeActivate", list); | | |||
263 | foreach (int i, list) { | | |||
264 | monitorChangeEdge(ElectricBorder(i), int(TabBoxAlternative)); | | |||
265 | } | | |||
266 | 205 | | |||
206 | // Scripts | ||||
267 | for (int i=0; i < m_scripts.size(); i++) { | 207 | for (int i=0; i < m_scripts.size(); i++) { | ||
268 | int index = EffectCount + i; | 208 | int index = EffectCount + i; | ||
269 | KConfigGroup scriptConfig(m_config, "Script-"+m_scripts[i]); | 209 | m_form->monitorChangeEdge(m_scriptSettings[m_scripts[i]]->touchBorderActivate(), index); | ||
270 | list.append(int(ElectricNone)); | | |||
271 | list = scriptConfig.readEntry("TouchBorderActivate", list); | | |||
272 | for (int i: list) { | | |||
273 | monitorChangeEdge(ElectricBorder(i), index); | | |||
274 | } | | |||
275 | } | 210 | } | ||
276 | } | 211 | } | ||
277 | 212 | | |||
278 | void KWinScreenEdgesConfig::monitorSaveAction(int edge, const QString& configName) | 213 | void KWinScreenEdgesConfig::monitorLoadDefaultSettings() | ||
279 | { | 214 | { | ||
280 | KConfigGroup config(m_config, "TouchEdges"); | 215 | m_form->monitorChangeDefaultEdge(ElectricTop, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->defaultTopValue())); | ||
281 | int item = m_ui->monitor->selectedEdgeItem(edge); | 216 | m_form->monitorChangeDefaultEdge(ElectricRight, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->defaultRightValue())); | ||
282 | if (item == 1) | 217 | m_form->monitorChangeDefaultEdge(ElectricBottom, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->defaultBottomValue())); | ||
283 | config.writeEntry(configName, "ShowDesktop"); | 218 | m_form->monitorChangeDefaultEdge(ElectricLeft, KWinScreenEdgesConfig::electricBorderActionFromString(m_settings->defaultLeftValue())); | ||
284 | else if (item == 2) | 219 | | ||
285 | config.writeEntry(configName, "LockScreen"); | 220 | // Present Windows BorderActivateAll | ||
286 | else if (item == 3) | 221 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateAllValue(), PresentWindowsAll); | ||
287 | config.writeEntry(configName, "KRunner"); | 222 | // PresentWindows BorderActivate | ||
288 | else if (item == 4) | 223 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivatePresentWindowsValue(), PresentWindowsCurrent); | ||
289 | config.writeEntry(configName, "ActivityManager"); | 224 | // PresentWindows BorderActivateClass | ||
290 | else if (item == 5) | 225 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateClassValue(), PresentWindowsClass); | ||
291 | config.writeEntry(configName, "ApplicationLauncher"); | 226 | | ||
292 | else // Anything else | 227 | // Desktop Grid BorderActivate | ||
293 | config.writeEntry(configName, "None"); | 228 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateDesktopGridValue(), DesktopGrid); | ||
229 | | ||||
230 | // Desktop Cube BorderActivate | ||||
231 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateCubeValue(), Cube); | ||||
232 | // Desktop Cube BorderActivateCylinder | ||||
233 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateCylinderValue(), Cylinder); | ||||
234 | // Desktop Cube BorderActivateSphere | ||||
235 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateSphereValue(), Sphere); | ||||
236 | | ||||
237 | // TabBox BorderActivate | ||||
238 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderActivateTabBoxValue(), TabBox); | ||||
239 | // Alternative TabBox | ||||
240 | m_form->monitorChangeDefaultEdge(m_settings->defaultTouchBorderAlternativeActivateValue(), TabBoxAlternative); | ||||
294 | } | 241 | } | ||
295 | 242 | | |||
296 | void KWinScreenEdgesConfig::monitorSave() | 243 | void KWinScreenEdgesConfig::monitorSaveSettings() | ||
297 | { | 244 | { | ||
298 | // Save ElectricBorderActions | 245 | // Save ElectricBorderActions | ||
299 | monitorSaveAction(int(Monitor::Top), "Top"); | 246 | m_settings->setTop(KWinScreenEdgesConfig::electricBorderActionToString(m_form->selectedEdgeItem(ElectricTop))); | ||
300 | monitorSaveAction(int(Monitor::Right), "Right"); | 247 | m_settings->setRight(KWinScreenEdgesConfig::electricBorderActionToString(m_form->selectedEdgeItem(ElectricRight))); | ||
301 | monitorSaveAction(int(Monitor::Bottom), "Bottom"); | 248 | m_settings->setBottom(KWinScreenEdgesConfig::electricBorderActionToString(m_form->selectedEdgeItem(ElectricBottom))); | ||
302 | monitorSaveAction(int(Monitor::Left), "Left"); | 249 | m_settings->setLeft(KWinScreenEdgesConfig::electricBorderActionToString(m_form->selectedEdgeItem(ElectricLeft))); | ||
303 | 250 | | |||
304 | // Save effect-specific actions: | 251 | // Save effect-specific actions: | ||
305 | 252 | | |||
306 | // Present Windows | 253 | // Present Windows | ||
307 | KConfigGroup presentWindowsConfig(m_config, "Effect-PresentWindows"); | 254 | m_settings->setTouchBorderActivatePresentWindows(m_form->monitorCheckEffectHasEdge(PresentWindowsAll)); | ||
308 | presentWindowsConfig.writeEntry("TouchBorderActivate", | 255 | m_settings->setTouchBorderActivateAll(m_form->monitorCheckEffectHasEdge(PresentWindowsCurrent)); | ||
309 | monitorCheckEffectHasEdge(int(PresentWindowsAll))); | 256 | m_settings->setTouchBorderActivateClass(m_form->monitorCheckEffectHasEdge(PresentWindowsClass)); | ||
310 | presentWindowsConfig.writeEntry("TouchBorderActivateAll", | | |||
311 | monitorCheckEffectHasEdge(int(PresentWindowsCurrent))); | | |||
312 | presentWindowsConfig.writeEntry("TouchBorderActivateClass", | | |||
313 | monitorCheckEffectHasEdge(int(PresentWindowsClass))); | | |||
314 | 257 | | |||
315 | // Desktop Grid | 258 | // Desktop Grid | ||
316 | KConfigGroup gridConfig(m_config, "Effect-DesktopGrid"); | 259 | m_settings->setTouchBorderActivateDesktopGrid(m_form->monitorCheckEffectHasEdge(DesktopGrid)); | ||
317 | gridConfig.writeEntry("TouchBorderActivate", | | |||
318 | monitorCheckEffectHasEdge(int(DesktopGrid))); | | |||
319 | 260 | | |||
320 | // Desktop Cube | 261 | // Desktop Cube | ||
321 | KConfigGroup cubeConfig(m_config, "Effect-Cube"); | 262 | m_settings->setTouchBorderActivateCube(m_form->monitorCheckEffectHasEdge(Cube)); | ||
322 | cubeConfig.writeEntry("TouchBorderActivate", | 263 | m_settings->setTouchBorderActivateCylinder(m_form->monitorCheckEffectHasEdge(Cylinder)); | ||
323 | monitorCheckEffectHasEdge(int(Cube))); | 264 | m_settings->setTouchBorderActivateSphere(m_form->monitorCheckEffectHasEdge(Sphere)); | ||
324 | cubeConfig.writeEntry("TouchBorderActivateCylinder", | | |||
325 | monitorCheckEffectHasEdge(int(Cylinder))); | | |||
326 | cubeConfig.writeEntry("TouchBorderActivateSphere", | | |||
327 | monitorCheckEffectHasEdge(int(Sphere))); | | |||
328 | 265 | | |||
329 | // TabBox | 266 | // TabBox | ||
330 | KConfigGroup tabBoxConfig(m_config, "TabBox"); | 267 | m_settings->setTouchBorderActivateTabBox(m_form->monitorCheckEffectHasEdge(TabBox)); | ||
331 | tabBoxConfig.writeEntry("TouchBorderActivate", | 268 | m_settings->setTouchBorderAlternativeActivate(m_form->monitorCheckEffectHasEdge(TabBoxAlternative)); | ||
332 | monitorCheckEffectHasEdge(int(TabBox))); | | |||
333 | tabBoxConfig.writeEntry("TouchBorderAlternativeActivate", | | |||
334 | monitorCheckEffectHasEdge(int(TabBoxAlternative))); | | |||
335 | 269 | | |||
270 | // Scripts | ||||
336 | for (int i=0; i < m_scripts.size(); i++) { | 271 | for (int i = 0; i < m_scripts.size(); i++) { | ||
337 | int index = EffectCount + i; | 272 | int index = EffectCount + i; | ||
338 | KConfigGroup scriptConfig(m_config, "Script-"+m_scripts[i]); | 273 | m_scriptSettings[m_scripts[i]]->setTouchBorderActivate(m_form->monitorCheckEffectHasEdge(index)); | ||
339 | scriptConfig.writeEntry("TouchBorderActivate", | | |||
340 | monitorCheckEffectHasEdge(index)); | | |||
341 | } | | |||
342 | } | 274 | } | ||
343 | | ||||
344 | void KWinScreenEdgesConfig::monitorDefaults() | | |||
345 | { | | |||
346 | // Clear all edges | | |||
347 | for (int i = 0; i < 8; i++) | | |||
348 | m_ui->monitor->selectEdgeItem(i, 0); | | |||
349 | // select TabBox | | |||
350 | m_ui->monitor->selectEdgeItem(int(Monitor::Left), int(TabBox)); | | |||
351 | } | 275 | } | ||
352 | 276 | | |||
353 | void KWinScreenEdgesConfig::monitorShowEvent() | 277 | void KWinScreenEdgesConfig::monitorShowEvent() | ||
354 | { | 278 | { | ||
355 | // Check if they are enabled | 279 | // Check if they are enabled | ||
356 | KConfigGroup config(m_config, "Plugins"); | 280 | KConfigGroup config(m_config, "Plugins"); | ||
357 | 281 | | |||
358 | // Present Windows | 282 | // Present Windows | ||
359 | bool enabled = effectEnabled(BuiltInEffect::PresentWindows, config); | 283 | bool enabled = effectEnabled(BuiltInEffect::PresentWindows, config); | ||
360 | monitorItemSetEnabled(int(PresentWindowsCurrent), enabled); | 284 | m_form->monitorItemSetEnabled(PresentWindowsCurrent, enabled); | ||
361 | monitorItemSetEnabled(int(PresentWindowsAll), enabled); | 285 | m_form->monitorItemSetEnabled(PresentWindowsAll, enabled); | ||
362 | 286 | | |||
363 | // Desktop Grid | 287 | // Desktop Grid | ||
364 | enabled = effectEnabled(BuiltInEffect::DesktopGrid, config); | 288 | enabled = effectEnabled(BuiltInEffect::DesktopGrid, config); | ||
365 | monitorItemSetEnabled(int(DesktopGrid), enabled); | 289 | m_form->monitorItemSetEnabled(DesktopGrid, enabled); | ||
366 | 290 | | |||
367 | // Desktop Cube | 291 | // Desktop Cube | ||
368 | enabled = effectEnabled(BuiltInEffect::Cube, config); | 292 | enabled = effectEnabled(BuiltInEffect::Cube, config); | ||
369 | monitorItemSetEnabled(int(Cube), enabled); | 293 | m_form->monitorItemSetEnabled(Cube, enabled); | ||
370 | monitorItemSetEnabled(int(Cylinder), enabled); | 294 | m_form->monitorItemSetEnabled(Cylinder, enabled); | ||
371 | monitorItemSetEnabled(int(Sphere), enabled); | 295 | m_form->monitorItemSetEnabled(Sphere, enabled); | ||
372 | // tabbox, depends on reasonable focus policy. | 296 | // tabbox, depends on reasonable focus policy. | ||
373 | KConfigGroup config2(m_config, "Windows"); | 297 | KConfigGroup config2(m_config, "Windows"); | ||
374 | QString focusPolicy = config2.readEntry("FocusPolicy", QString()); | 298 | QString focusPolicy = config2.readEntry("FocusPolicy", QString()); | ||
375 | bool reasonable = focusPolicy != "FocusStrictlyUnderMouse" && focusPolicy != "FocusUnderMouse"; | 299 | bool reasonable = focusPolicy != "FocusStrictlyUnderMouse" && focusPolicy != "FocusUnderMouse"; | ||
376 | monitorItemSetEnabled(int(TabBox), reasonable); | 300 | m_form->monitorItemSetEnabled(TabBox, reasonable); | ||
377 | monitorItemSetEnabled(int(TabBoxAlternative), reasonable); | 301 | m_form->monitorItemSetEnabled(TabBoxAlternative, reasonable); | ||
378 | } | 302 | } | ||
379 | 303 | | |||
380 | void KWinScreenEdgesConfig::monitorChangeEdge(ElectricBorder border, int index) | 304 | ElectricBorderAction KWinScreenEdgesConfig::electricBorderActionFromString(const QString &string) | ||
381 | { | 305 | { | ||
382 | switch(border) { | 306 | QString lowerName = string.toLower(); | ||
383 | case ElectricTop: | 307 | if (lowerName == QStringLiteral("showdesktop")) { | ||
384 | m_ui->monitor->selectEdgeItem(int(Monitor::Top), index); | 308 | return ElectricActionShowDesktop; | ||
385 | break; | 309 | } | ||
386 | case ElectricTopRight: | 310 | if (lowerName == QStringLiteral("lockscreen")) { | ||
387 | m_ui->monitor->selectEdgeItem(int(Monitor::TopRight), index); | 311 | return ElectricActionLockScreen; | ||
388 | break; | 312 | } | ||
389 | case ElectricRight: | 313 | if (lowerName == QStringLiteral("krunner")) { | ||
390 | m_ui->monitor->selectEdgeItem(int(Monitor::Right), index); | 314 | return ElectricActionKRunner; | ||
391 | break; | 315 | } | ||
392 | case ElectricBottomRight: | 316 | if (lowerName == QStringLiteral("activitymanager")) { | ||
393 | m_ui->monitor->selectEdgeItem(int(Monitor::BottomRight), index); | 317 | return ElectricActionActivityManager; | ||
394 | break; | 318 | } | ||
395 | case ElectricBottom: | 319 | if (lowerName == QStringLiteral("applicationlauncher")) { | ||
396 | m_ui->monitor->selectEdgeItem(int(Monitor::Bottom), index); | 320 | return ElectricActionApplicationLauncher; | ||
397 | break; | 321 | } | ||
398 | case ElectricBottomLeft: | 322 | return ElectricActionNone; | ||
399 | m_ui->monitor->selectEdgeItem(int(Monitor::BottomLeft), index); | 323 | } | ||
400 | break; | 324 | | ||
401 | case ElectricLeft: | 325 | QString KWinScreenEdgesConfig::electricBorderActionToString(int action) | ||
402 | m_ui->monitor->selectEdgeItem(int(Monitor::Left), index); | 326 | { | ||
403 | break; | 327 | switch (action) { | ||
404 | case ElectricTopLeft: | 328 | case 1: | ||
405 | m_ui->monitor->selectEdgeItem(int(Monitor::TopLeft), index); | 329 | return QStringLiteral("ShowDesktop"); | ||
406 | break; | 330 | case 2: | ||
407 | default: // Nothing | 331 | return QStringLiteral("LockScreen"); | ||
408 | break; | 332 | case 3: | ||
409 | } | 333 | return QStringLiteral("KRunner"); | ||
410 | } | 334 | case 4: | ||
411 | 335 | return QStringLiteral("ActivityManager"); | |||
412 | void KWinScreenEdgesConfig::monitorHideEdge(ElectricBorder border, bool hidden) | 336 | case 5: | ||
413 | { | 337 | return QStringLiteral("ApplicationLauncher"); | ||
414 | switch(border) { | 338 | default: | ||
415 | case ElectricTop: | 339 | return QStringLiteral("None"); | ||
416 | m_ui->monitor->setEdgeHidden(int(Monitor::Top), hidden); | 340 | } | ||
417 | break; | | |||
418 | case ElectricTopRight: | | |||
419 | m_ui->monitor->setEdgeHidden(int(Monitor::TopRight), hidden); | | |||
420 | break; | | |||
421 | case ElectricRight: | | |||
422 | m_ui->monitor->setEdgeHidden(int(Monitor::Right), hidden); | | |||
423 | break; | | |||
424 | case ElectricBottomRight: | | |||
425 | m_ui->monitor->setEdgeHidden(int(Monitor::BottomRight), hidden); | | |||
426 | break; | | |||
427 | case ElectricBottom: | | |||
428 | m_ui->monitor->setEdgeHidden(int(Monitor::Bottom), hidden); | | |||
429 | break; | | |||
430 | case ElectricBottomLeft: | | |||
431 | m_ui->monitor->setEdgeHidden(int(Monitor::BottomLeft), hidden); | | |||
432 | break; | | |||
433 | case ElectricLeft: | | |||
434 | m_ui->monitor->setEdgeHidden(int(Monitor::Left), hidden); | | |||
435 | break; | | |||
436 | case ElectricTopLeft: | | |||
437 | m_ui->monitor->setEdgeHidden(int(Monitor::TopLeft), hidden); | | |||
438 | break; | | |||
439 | default: // Nothing | | |||
440 | break; | | |||
441 | } | | |||
442 | } | | |||
443 | | ||||
444 | QList<int> KWinScreenEdgesConfig::monitorCheckEffectHasEdge(int index) const | | |||
445 | { | | |||
446 | QList<int> list = QList<int>(); | | |||
447 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::Top)) == index) | | |||
448 | list.append(int(ElectricTop)); | | |||
449 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::TopRight)) == index) | | |||
450 | list.append(int(ElectricTopRight)); | | |||
451 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::Right)) == index) | | |||
452 | list.append(int(ElectricRight)); | | |||
453 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::BottomRight)) == index) | | |||
454 | list.append(int(ElectricBottomRight)); | | |||
455 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::Bottom)) == index) | | |||
456 | list.append(int(ElectricBottom)); | | |||
457 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::BottomLeft)) == index) | | |||
458 | list.append(int(ElectricBottomLeft)); | | |||
459 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::Left)) == index) | | |||
460 | list.append(int(ElectricLeft)); | | |||
461 | if (m_ui->monitor->selectedEdgeItem(int(Monitor::TopLeft)) == index) | | |||
462 | list.append(int(ElectricTopLeft)); | | |||
463 | | ||||
464 | if (list.isEmpty()) | | |||
465 | list.append(int(ElectricNone)); | | |||
466 | return list; | | |||
467 | } | 341 | } | ||
468 | 342 | | |||
469 | } // namespace | 343 | } // namespace | ||
470 | 344 | | |||
471 | #include "touch.moc" | 345 | #include "touch.moc" | ||
zzag: No short names
int a -> int action |
This would be better in the initialization list. Also this is leaked.