Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/kwincompositing/compositing.cpp
Show All 26 Lines | |||||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | #include <KSharedConfig> | 28 | #include <KSharedConfig> | ||
29 | 29 | | |||
30 | #include <QDBusInterface> | 30 | #include <QDBusInterface> | ||
31 | #include <QDBusReply> | 31 | #include <QDBusReply> | ||
32 | #include <QHash> | 32 | #include <QHash> | ||
33 | #include <QDebug> | 33 | #include <QDebug> | ||
34 | 34 | | |||
35 | #include "kwincompositing_setting.h" | ||||
36 | | ||||
35 | namespace KWin { | 37 | namespace KWin { | ||
36 | namespace Compositing { | 38 | namespace Compositing { | ||
37 | 39 | | |||
38 | Compositing::Compositing(QObject *parent) | 40 | Compositing::Compositing(QObject *parent) | ||
39 | : QObject(parent) | 41 | : QObject(parent) | ||
40 | , m_animationSpeed(1.0) | 42 | , m_animationSpeed(1.0) | ||
41 | , m_windowThumbnail(0) | 43 | , m_windowThumbnail(0) | ||
42 | , m_glScaleFilter(0) | 44 | , m_glScaleFilter(0) | ||
43 | , m_xrScaleFilter(false) | 45 | , m_xrScaleFilter(false) | ||
44 | , m_glSwapStrategy(0) | 46 | , m_glSwapStrategy(0) | ||
45 | , m_compositingType(0) | 47 | , m_compositingType(0) | ||
46 | , m_compositingEnabled(true) | 48 | , m_compositingEnabled(true) | ||
47 | , m_changed(false) | | |||
48 | , m_openGLPlatformInterfaceModel(new OpenGLPlatformInterfaceModel(this)) | 49 | , m_openGLPlatformInterfaceModel(new OpenGLPlatformInterfaceModel(this)) | ||
49 | , m_openGLPlatformInterface(0) | 50 | , m_openGLPlatformInterface(0) | ||
50 | , m_windowsBlockCompositing(true) | 51 | , m_windowsBlockCompositing(true) | ||
51 | , m_compositingInterface(new OrgKdeKwinCompositingInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Compositor"), QDBusConnection::sessionBus(), this)) | 52 | , m_compositingInterface(new OrgKdeKwinCompositingInterface(QStringLiteral("org.kde.KWin"), QStringLiteral("/Compositor"), QDBusConnection::sessionBus(), this)) | ||
52 | , m_config(KSharedConfig::openConfig("kwinrc")) | 53 | , m_settings(new KWinCompositingSetting(parent)) | ||
53 | { | 54 | { | ||
54 | reset(); | 55 | load(); | ||
55 | connect(this, &Compositing::animationSpeedChanged, this, &Compositing::changed); | 56 | connect(this, &Compositing::animationSpeedChanged, this, &Compositing::updateSettings); | ||
zzag: Naming nitpick: onChanged isn't really a great name for a signal. Usually, "on" is used with… | |||||
56 | connect(this, &Compositing::windowThumbnailChanged, this, &Compositing::changed); | 57 | connect(this, &Compositing::windowThumbnailChanged, this, &Compositing::updateSettings); | ||
57 | connect(this, &Compositing::glScaleFilterChanged, this, &Compositing::changed); | 58 | connect(this, &Compositing::glScaleFilterChanged, this, &Compositing::updateSettings); | ||
58 | connect(this, &Compositing::xrScaleFilterChanged, this, &Compositing::changed); | 59 | connect(this, &Compositing::xrScaleFilterChanged, this, &Compositing::updateSettings); | ||
59 | connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::changed); | 60 | connect(this, &Compositing::glSwapStrategyChanged, this, &Compositing::updateSettings); | ||
60 | connect(this, &Compositing::compositingTypeChanged, this, &Compositing::changed); | 61 | connect(this, &Compositing::compositingTypeChanged, this, &Compositing::updateSettings); | ||
61 | connect(this, &Compositing::compositingEnabledChanged, this, &Compositing::changed); | 62 | connect(this, &Compositing::compositingEnabledChanged, this, &Compositing::updateSettings); | ||
62 | connect(this, &Compositing::openGLPlatformInterfaceChanged, this, &Compositing::changed); | 63 | connect(this, &Compositing::openGLPlatformInterfaceChanged, this, &Compositing::updateSettings); | ||
63 | connect(this, &Compositing::windowsBlockCompositingChanged, this, &Compositing::changed); | 64 | connect(this, &Compositing::windowsBlockCompositingChanged, this, &Compositing::updateSettings); | ||
64 | 65 | | |||
65 | connect(this, &Compositing::changed, [this]{ | 66 | connect(this, &Compositing::onChanged, [this]{ | ||
66 | m_changed = true; | 67 | updateSettings(); | ||
67 | }); | 68 | }); | ||
zzag: Shouldn't the parent be `this`? | |||||
68 | } | 69 | } | ||
69 | 70 | | |||
70 | void Compositing::reset() | 71 | void Compositing::load() | ||
71 | { | 72 | { | ||
72 | KConfigGroup globalConfig(m_config, QStringLiteral("KDE")); | 73 | m_settings->load(); | ||
73 | setAnimationSpeed(globalConfig.readEntry("AnimationDurationFactor", 1.0)); | | |||
74 | | ||||
75 | KConfigGroup kwinConfig(m_config, QStringLiteral("Compositing")); | | |||
76 | setWindowThumbnail(kwinConfig.readEntry("HiddenPreviews", 5) - 4); | | |||
77 | setGlScaleFilter(kwinConfig.readEntry("GLTextureFilter", 2)); | | |||
78 | setXrScaleFilter(kwinConfig.readEntry("XRenderSmoothScale", false)); | | |||
79 | setCompositingEnabled(kwinConfig.readEntry("Enabled", true)); | | |||
80 | 74 | | |||
81 | auto swapStrategy = [&kwinConfig]() { | 75 | applyValues(); | ||
82 | const QString glSwapStrategyValue = kwinConfig.readEntry("GLPreferBufferSwap", "a"); | | |||
83 | 76 | | |||
84 | if (glSwapStrategyValue == "n") { | 77 | emit changed(false); | ||
85 | return 0; | 78 | emit defaulted(m_settings->isDefaults()); | ||
86 | } else if (glSwapStrategyValue == "a") { | | |||
87 | return 1; | | |||
88 | } else if (glSwapStrategyValue == "e") { | | |||
89 | return 2; | | |||
90 | } else if (glSwapStrategyValue == "p") { | | |||
91 | return 3; | | |||
92 | } else if (glSwapStrategyValue == "c") { | | |||
93 | return 4; | | |||
94 | } | 79 | } | ||
95 | return 0; | | |||
96 | }; | | |||
97 | setGlSwapStrategy(swapStrategy()); | | |||
98 | 80 | | |||
99 | auto type = [&kwinConfig]{ | 81 | void Compositing::applyValues() | ||
100 | const QString backend = kwinConfig.readEntry("Backend", "OpenGL"); | 82 | { | ||
101 | const bool glCore = kwinConfig.readEntry("GLCore", false); | 83 | setAnimationSpeed(m_settings->animationDurationFactor()); | ||
84 | setWindowThumbnail(m_settings->hiddenPreviews() - 4); | ||||
ervin: That `- 4` is very obscure here | |||||
Heh, - 4 and + 4 were obscure before so this patch doesn't make things better or worse. Just for context, we add and subtract 4 because long time ago HiddenPreviews had values with different meaning than what we have now. In order to break backwards compatibility, the new values were shifted by 4. zzag: Heh, `- 4` and `+ 4` were obscure before so this patch doesn't make things better or worse. | |||||
ervin: And we didn't wrap that in conversion functions? :-) | |||||
85 | setGlScaleFilter(m_settings->gLTextureFilter()); | ||||
Would be nice to use key + name in the kcfg to have proper capitalization for "gl" ervin: Would be nice to use key + name in the kcfg to have proper capitalization for "gl" | |||||
86 | setXrScaleFilter(m_settings->xRenderSmoothScale()); | ||||
87 | setCompositingEnabled(m_settings->enabled()); | ||||
88 | setGlSwapStrategy(m_settings->gLPreferBufferSwap()); | ||||
ervin: ditto | |||||
89 | | ||||
90 | const auto type = [this]{ | ||||
91 | const int backend = m_settings->backend(); | ||||
92 | const bool glCore = m_settings->gLCore(); | ||||
102 | 93 | | |||
103 | if (backend == QStringLiteral("OpenGL")) { | 94 | if (backend == KWinCompositingSetting::EnumBackend::OpenGL) { | ||
104 | if (glCore) { | 95 | if (glCore) { | ||
105 | return CompositingType::OPENGL31_INDEX; | 96 | return CompositingType::OPENGL31_INDEX; | ||
106 | } else { | 97 | } else { | ||
107 | return CompositingType::OPENGL20_INDEX; | 98 | return CompositingType::OPENGL20_INDEX; | ||
108 | } | 99 | } | ||
109 | } else { | 100 | } else { | ||
110 | return CompositingType::XRENDER_INDEX; | 101 | return CompositingType::XRENDER_INDEX; | ||
111 | } | 102 | } | ||
112 | }; | 103 | }; | ||
113 | setCompositingType(type()); | 104 | setCompositingType(type()); | ||
114 | 105 | | |||
115 | const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(kwinConfig.readEntry("GLPlatformInterface", "glx")); | 106 | const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(m_settings->gLPlatformInterface()); | ||
ervin: ditto | |||||
116 | setOpenGLPlatformInterface(index.isValid() ? index.row() : 0); | 107 | setOpenGLPlatformInterface(index.isValid() ? index.row() : 0); | ||
117 | 108 | | |||
118 | setWindowsBlockCompositing(kwinConfig.readEntry("WindowsBlockCompositing", true)); | 109 | setWindowsBlockCompositing(m_settings->windowsBlockCompositing()); | ||
119 | | ||||
120 | m_changed = false; | | |||
121 | } | 110 | } | ||
122 | 111 | | |||
123 | void Compositing::defaults() | 112 | void Compositing::defaults() | ||
124 | { | 113 | { | ||
125 | setAnimationSpeed(1.0); | 114 | m_settings->setDefaults(); | ||
126 | setWindowThumbnail(1); | 115 | | ||
127 | setGlScaleFilter(2); | 116 | applyValues(); | ||
128 | setXrScaleFilter(false); | 117 | | ||
129 | setGlSwapStrategy(1); | 118 | emit changed(m_settings->isSaveNeeded()); | ||
130 | setCompositingType(CompositingType::OPENGL20_INDEX); | 119 | emit defaulted(m_settings->isDefaults()); | ||
131 | const QModelIndex index = m_openGLPlatformInterfaceModel->indexForKey(QStringLiteral("glx")); | | |||
132 | setOpenGLPlatformInterface(index.isValid() ? index.row() : 0); | | |||
133 | setWindowsBlockCompositing(true); | | |||
134 | m_changed = true; | | |||
135 | } | 120 | } | ||
136 | 121 | | |||
137 | bool Compositing::OpenGLIsUnsafe() const | 122 | bool Compositing::OpenGLIsUnsafe() const | ||
138 | { | 123 | { | ||
139 | KConfigGroup kwinConfig(m_config, "Compositing"); | 124 | return m_settings->openGLIsUnsafe(); | ||
140 | return kwinConfig.readEntry("OpenGLIsUnsafe", true); | | |||
141 | } | 125 | } | ||
142 | 126 | | |||
143 | bool Compositing::OpenGLIsBroken() | 127 | bool Compositing::OpenGLIsBroken() | ||
144 | { | 128 | { | ||
145 | KConfigGroup kwinConfig(m_config, "Compositing"); | 129 | const int oldBackend = m_settings->backend(); | ||
146 | 130 | m_settings->setBackend(KWinCompositingSetting::EnumBackend::OpenGL); | |||
147 | QString oldBackend = kwinConfig.readEntry("Backend", "OpenGL"); | 131 | m_settings->save(); | ||
148 | kwinConfig.writeEntry("Backend", "OpenGL"); | | |||
149 | kwinConfig.sync(); | | |||
150 | 132 | | |||
151 | if (m_compositingInterface->openGLIsBroken()) { | 133 | if (m_compositingInterface->openGLIsBroken()) { | ||
152 | kwinConfig.writeEntry("Backend", oldBackend); | 134 | m_settings->setBackend(oldBackend); | ||
153 | kwinConfig.sync(); | 135 | m_settings->save(); | ||
154 | return true; | 136 | return true; | ||
155 | } | 137 | } | ||
156 | 138 | | |||
157 | kwinConfig.writeEntry("OpenGLIsUnsafe", false); | 139 | m_settings->setOpenGLIsUnsafe(false); | ||
158 | kwinConfig.sync(); | 140 | m_settings->save(); | ||
159 | return false; | 141 | return false; | ||
160 | } | 142 | } | ||
161 | 143 | | |||
162 | void Compositing::reenableOpenGLDetection() | 144 | void Compositing::reenableOpenGLDetection() | ||
163 | { | 145 | { | ||
164 | KConfigGroup kwinConfig(m_config, "Compositing"); | 146 | m_settings->setOpenGLIsUnsafe(false); | ||
165 | kwinConfig.writeEntry("OpenGLIsUnsafe", false); | 147 | m_settings->save(); | ||
166 | kwinConfig.sync(); | | |||
167 | } | 148 | } | ||
168 | 149 | | |||
169 | qreal Compositing::animationSpeed() const | 150 | qreal Compositing::animationSpeed() const | ||
170 | { | 151 | { | ||
171 | return m_animationSpeed; | 152 | return m_animationSpeed; | ||
172 | } | 153 | } | ||
173 | 154 | | |||
174 | int Compositing::windowThumbnail() const | 155 | int Compositing::windowThumbnail() const | ||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Line(s) | 240 | { | |||
263 | if (enabled == m_compositingEnabled) { | 244 | if (enabled == m_compositingEnabled) { | ||
264 | return; | 245 | return; | ||
265 | } | 246 | } | ||
266 | 247 | | |||
267 | m_compositingEnabled = enabled; | 248 | m_compositingEnabled = enabled; | ||
268 | emit compositingEnabledChanged(enabled); | 249 | emit compositingEnabledChanged(enabled); | ||
269 | } | 250 | } | ||
270 | 251 | | |||
271 | void Compositing::save() | 252 | void Compositing::updateSettings() | ||
272 | { | 253 | { | ||
273 | // this writes to the KDE group of the kwinrc, when loading we rely on kconfig cascading to | 254 | // this writes to the KDE group of the kwinrc, when loading we rely on kconfig cascading to | ||
274 | // load a global value, or allow a kwin override | 255 | // load a global value, or allow a kwin override | ||
275 | KConfigGroup generalConfig(m_config, "KDE"); | | |||
276 | if (!isRunningPlasma()) { | 256 | if (!isRunningPlasma()) { | ||
277 | generalConfig.writeEntry("AnimationDurationFactor", animationSpeed()); | 257 | m_settings->setAnimationDurationFactor(animationSpeed()); | ||
278 | } | 258 | } | ||
279 | KConfigGroup kwinConfig(m_config, "Compositing"); | | |||
280 | 259 | | |||
281 | kwinConfig.writeEntry("HiddenPreviews", windowThumbnail() + 4); | 260 | m_settings->setHiddenPreviews(windowThumbnail() + 4); | ||
282 | kwinConfig.writeEntry("GLTextureFilter", glScaleFilter()); | 261 | m_settings->setGLTextureFilter(glScaleFilter()); | ||
283 | kwinConfig.writeEntry("XRenderSmoothScale", xrScaleFilter()); | 262 | m_settings->setXRenderSmoothScale(xrScaleFilter()); | ||
284 | if (!compositingRequired()) { | 263 | if (!compositingRequired()) { | ||
285 | kwinConfig.writeEntry("Enabled", compositingEnabled()); | 264 | m_settings->setEnabled(compositingEnabled()); | ||
286 | } | | |||
287 | auto swapStrategy = [this] { | | |||
288 | switch (glSwapStrategy()) { | | |||
289 | case 0: | | |||
290 | return QStringLiteral("n"); | | |||
291 | case 2: | | |||
292 | return QStringLiteral("e"); | | |||
293 | case 3: | | |||
294 | return QStringLiteral("p"); | | |||
295 | case 4: | | |||
296 | return QStringLiteral("c"); | | |||
297 | case 1: | | |||
298 | default: | | |||
299 | return QStringLiteral("a"); | | |||
300 | } | 265 | } | ||
301 | }; | 266 | m_settings->setGLPreferBufferSwap(glSwapStrategy()); | ||
302 | kwinConfig.writeEntry("GLPreferBufferSwap", swapStrategy()); | 267 | int backend; | ||
ervin: would be nice to initialize it | |||||
303 | QString backend; | | |||
304 | bool glCore = false; | 268 | bool glCore = false; | ||
305 | switch (compositingType()) { | 269 | switch (compositingType()) { | ||
306 | case CompositingType::OPENGL31_INDEX: | 270 | case CompositingType::OPENGL31_INDEX: | ||
307 | backend = "OpenGL"; | 271 | backend = KWinCompositingSetting::EnumBackend::OpenGL; | ||
308 | glCore = true; | 272 | glCore = true; | ||
309 | break; | 273 | break; | ||
310 | case CompositingType::OPENGL20_INDEX: | 274 | case CompositingType::OPENGL20_INDEX: | ||
311 | backend = "OpenGL"; | 275 | backend = KWinCompositingSetting::EnumBackend::OpenGL; | ||
312 | glCore = false; | 276 | glCore = false; | ||
313 | break; | 277 | break; | ||
314 | case CompositingType::XRENDER_INDEX: | 278 | case CompositingType::XRENDER_INDEX: | ||
315 | backend = "XRender"; | 279 | backend = KWinCompositingSetting::EnumBackend::XRender; | ||
316 | glCore = false; | 280 | glCore = false; | ||
317 | break; | 281 | break; | ||
318 | } | 282 | } | ||
319 | kwinConfig.writeEntry("Backend", backend); | 283 | m_settings->setBackend(backend); | ||
320 | kwinConfig.writeEntry("GLCore", glCore); | 284 | m_settings->setGLCore(glCore); | ||
321 | if (!compositingRequired()) { | 285 | if (!compositingRequired()) { | ||
322 | kwinConfig.writeEntry("WindowsBlockCompositing", windowsBlockCompositing()); | 286 | m_settings->setWindowsBlockCompositing(windowsBlockCompositing()); | ||
287 | } | ||||
288 | | ||||
289 | emit changed(m_settings->isSaveNeeded()); | ||||
290 | emit defaulted(m_settings->isDefaults()); | ||||
323 | } | 291 | } | ||
324 | kwinConfig.sync(); | | |||
325 | 292 | | |||
326 | if (m_changed) { | 293 | void Compositing::save() | ||
294 | { | ||||
295 | if (m_settings->isSaveNeeded()) { | ||||
296 | | ||||
297 | m_settings->save(); | ||||
298 | | ||||
Given that m_changed is not set to true when anything has been changed, there is a chance that we won't send a reinit request. We probably need to save the return value of m_settings->isSaveNeeded() before calling m_settings->save() and check it here. zzag: Given that m_changed is not set to true when anything has been changed, there is a chance that… | |||||
327 | // Send signal to all kwin instances | 299 | // Send signal to all kwin instances | ||
328 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Compositor"), | 300 | QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/Compositor"), | ||
329 | QStringLiteral("org.kde.kwin.Compositing"), | 301 | QStringLiteral("org.kde.kwin.Compositing"), | ||
330 | QStringLiteral("reinit")); | 302 | QStringLiteral("reinit")); | ||
331 | QDBusConnection::sessionBus().send(message); | 303 | QDBusConnection::sessionBus().send(message); | ||
332 | m_changed = false; | | |||
333 | } | 304 | } | ||
334 | } | 305 | } | ||
335 | 306 | | |||
336 | OpenGLPlatformInterfaceModel *Compositing::openGLPlatformInterfaceModel() const | 307 | OpenGLPlatformInterfaceModel *Compositing::openGLPlatformInterfaceModel() const | ||
337 | { | 308 | { | ||
338 | return m_openGLPlatformInterfaceModel; | 309 | return m_openGLPlatformInterfaceModel; | ||
339 | } | 310 | } | ||
340 | 311 | | |||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 384 | { | |||
414 | QHash<int, QByteArray> roleNames; | 385 | QHash<int, QByteArray> roleNames; | ||
415 | roleNames[NameRole] = "NameRole"; | 386 | roleNames[NameRole] = "NameRole"; | ||
416 | roleNames[TypeRole] = QByteArrayLiteral("type"); | 387 | roleNames[TypeRole] = QByteArrayLiteral("type"); | ||
417 | return roleNames; | 388 | return roleNames; | ||
418 | } | 389 | } | ||
419 | 390 | | |||
420 | QModelIndex CompositingType::index(int row, int column, const QModelIndex &parent) const | 391 | QModelIndex CompositingType::index(int row, int column, const QModelIndex &parent) const | ||
421 | { | 392 | { | ||
422 | | ||||
423 | if (parent.isValid() || column > 0 || column < 0 || row < 0 || row >= m_compositingList.count()) { | 393 | if (parent.isValid() || column > 0 || column < 0 || row < 0 || row >= m_compositingList.count()) { | ||
424 | return QModelIndex(); | 394 | return QModelIndex(); | ||
425 | } | 395 | } | ||
426 | 396 | | |||
427 | return createIndex(row, column); | 397 | return createIndex(row, column); | ||
428 | } | 398 | } | ||
429 | 399 | | |||
430 | QModelIndex CompositingType::parent(const QModelIndex &child) const | 400 | QModelIndex CompositingType::parent(const QModelIndex &child) const | ||
▲ Show 20 Lines • Show All 116 Lines • Show Last 20 Lines |
Naming nitpick: onChanged isn't really a great name for a signal. Usually, "on" is used with slots.
What about connecting Compositing::animationSpeedChanged to Compositing::updateSettings? e.g.