Changeset View
Changeset View
Standalone View
Standalone View
kcmkwin/common/effectmodel.cpp
Show First 20 Lines • Show All 381 Lines • ▼ Show 20 Line(s) | 330 | for (const KPluginMetaData &pluginEffect : pluginEffects) { | |||
---|---|---|---|---|---|
382 | ); | 382 | ); | ||
383 | 383 | | |||
384 | if (shouldStore(effect)) { | 384 | if (shouldStore(effect)) { | ||
385 | m_effectsList << effect; | 385 | m_effectsList << effect; | ||
386 | } | 386 | } | ||
387 | } | 387 | } | ||
388 | } | 388 | } | ||
389 | 389 | | |||
390 | void EffectModel::load() | 390 | void EffectModel::load(LoadOptions options) | ||
391 | { | 391 | { | ||
392 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 392 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
393 | 393 | | |||
394 | const QVector<EffectData> oldEffects = m_effectsList; | ||||
395 | | ||||
394 | beginResetModel(); | 396 | beginResetModel(); | ||
395 | m_effectsChanged.clear(); | | |||
396 | m_effectsList.clear(); | 397 | m_effectsList.clear(); | ||
397 | const KPluginInfo::List configs = KPluginTrader::self()->query(QStringLiteral("kwin/effects/configs/")); | 398 | const KPluginInfo::List configs = KPluginTrader::self()->query(QStringLiteral("kwin/effects/configs/")); | ||
398 | loadBuiltInEffects(kwinConfig, configs); | 399 | loadBuiltInEffects(kwinConfig, configs); | ||
399 | loadJavascriptEffects(kwinConfig); | 400 | loadJavascriptEffects(kwinConfig); | ||
400 | loadPluginEffects(kwinConfig, configs); | 401 | loadPluginEffects(kwinConfig, configs); | ||
401 | 402 | | |||
403 | if (options == LoadOptions::KeepDirty) { | ||||
404 | for (const EffectData &oldEffect : oldEffects) { | ||||
405 | if (!oldEffect.changed) { | ||||
406 | continue; | ||||
407 | } | ||||
408 | auto effectIt = std::find_if(m_effectsList.begin(), m_effectsList.end(), | ||||
409 | [serviceName = oldEffect.serviceName](const EffectData &data) { | ||||
410 | return data.serviceName == serviceName; | ||||
411 | } | ||||
412 | ); | ||||
413 | if (effectIt == m_effectsList.end()) { | ||||
414 | continue; | ||||
415 | } | ||||
416 | effectIt->effectStatus = oldEffect.effectStatus; | ||||
417 | effectIt->changed = effectIt->effectStatus != effectIt->originalStatus; | ||||
418 | } | ||||
419 | } | ||||
420 | | ||||
402 | qSort(m_effectsList.begin(), m_effectsList.end(), [](const EffectData &a, const EffectData &b) { | 421 | qSort(m_effectsList.begin(), m_effectsList.end(), [](const EffectData &a, const EffectData &b) { | ||
403 | if (a.category == b.category) { | 422 | if (a.category == b.category) { | ||
404 | if (a.exclusiveGroup == b.exclusiveGroup) { | 423 | if (a.exclusiveGroup == b.exclusiveGroup) { | ||
405 | return a.name < b.name; | 424 | return a.name < b.name; | ||
406 | } | 425 | } | ||
407 | return a.exclusiveGroup < b.exclusiveGroup; | 426 | return a.exclusiveGroup < b.exclusiveGroup; | ||
408 | } | 427 | } | ||
409 | return a.category < b.category; | 428 | return a.category < b.category; | ||
Show All 35 Lines | 459 | if ((*it).supported != supportedValue) { | |||
445 | } | 464 | } | ||
446 | } | 465 | } | ||
447 | } | 466 | } | ||
448 | } | 467 | } | ||
449 | } | 468 | } | ||
450 | self->deleteLater(); | 469 | self->deleteLater(); | ||
451 | }); | 470 | }); | ||
452 | } | 471 | } | ||
453 | 472 | | |||
454 | m_effectsChanged = m_effectsList; | | |||
455 | endResetModel(); | 473 | endResetModel(); | ||
davidedmundson: I think there's a problem here.
Previously:
m_effectsList is the current state that we think… | |||||
456 | } | 474 | } | ||
457 | 475 | | |||
458 | void EffectModel::syncEffectsToKWin() | | |||
459 | { | | |||
460 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | | |||
461 | QStringLiteral("/Effects"), | | |||
462 | QDBusConnection::sessionBus()); | | |||
463 | for (int it = 0; it < m_effectsList.size(); it++) { | | |||
464 | if (m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus) { | | |||
465 | continue; | | |||
466 | } | | |||
467 | if (m_effectsList.at(it).effectStatus != Status::Disabled) { | | |||
468 | interface.loadEffect(m_effectsList.at(it).serviceName); | | |||
469 | } else { | | |||
470 | interface.unloadEffect(m_effectsList.at(it).serviceName); | | |||
471 | } | | |||
472 | } | | |||
473 | | ||||
474 | m_effectsChanged = m_effectsList; | | |||
475 | } | | |||
476 | | ||||
477 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | 476 | void EffectModel::updateEffectStatus(const QModelIndex &rowIndex, Status effectState) | ||
478 | { | 477 | { | ||
479 | setData(rowIndex, static_cast<int>(effectState), EffectModel::EffectStatusRole); | 478 | setData(rowIndex, static_cast<int>(effectState), EffectModel::EffectStatusRole); | ||
480 | } | 479 | } | ||
481 | 480 | | |||
482 | void EffectModel::save() | 481 | void EffectModel::save() | ||
483 | { | 482 | { | ||
484 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | 483 | KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), "Plugins"); | ||
485 | 484 | | |||
486 | for (auto it = m_effectsList.begin(); it != m_effectsList.end(); it++) { | 485 | QVector<EffectData> dirtyEffects; | ||
487 | EffectData &effect = *(it); | 486 | | ||
487 | for (EffectData &effect : m_effectsList) { | ||||
488 | if (!effect.changed) { | 488 | if (!effect.changed) { | ||
489 | continue; | 489 | continue; | ||
490 | } | 490 | } | ||
491 | | ||||
491 | effect.changed = false; | 492 | effect.changed = false; | ||
492 | effect.originalStatus = effect.effectStatus; | 493 | effect.originalStatus = effect.effectStatus; | ||
493 | 494 | | |||
494 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | 495 | const QString key = effect.serviceName + QStringLiteral("Enabled"); | ||
495 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | 496 | const bool shouldEnable = (effect.effectStatus != Status::Disabled); | ||
496 | const bool restoreToDefault = effect.enabledByDefaultFunction | 497 | const bool restoreToDefault = effect.enabledByDefaultFunction | ||
497 | ? effect.effectStatus == Status::EnabledUndeterminded | 498 | ? effect.effectStatus == Status::EnabledUndeterminded | ||
498 | : shouldEnable == effect.enabledByDefault; | 499 | : shouldEnable == effect.enabledByDefault; | ||
499 | if (restoreToDefault) { | 500 | if (restoreToDefault) { | ||
500 | kwinConfig.deleteEntry(key); | 501 | kwinConfig.deleteEntry(key); | ||
501 | } else { | 502 | } else { | ||
502 | kwinConfig.writeEntry(key, shouldEnable); | 503 | kwinConfig.writeEntry(key, shouldEnable); | ||
503 | } | 504 | } | ||
505 | | ||||
506 | dirtyEffects.append(effect); | ||||
507 | } | ||||
508 | | ||||
509 | if (dirtyEffects.isEmpty()) { | ||||
510 | return; | ||||
504 | } | 511 | } | ||
505 | 512 | | |||
506 | kwinConfig.sync(); | 513 | kwinConfig.sync(); | ||
507 | syncEffectsToKWin(); | 514 | | ||
515 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||||
516 | QStringLiteral("/Effects"), | ||||
517 | QDBusConnection::sessionBus()); | ||||
518 | | ||||
519 | if (!interface.isValid()) { | ||||
520 | return; | ||||
521 | } | ||||
522 | | ||||
523 | for (const EffectData &effect : dirtyEffects) { | ||||
524 | if (effect.effectStatus != Status::Disabled) { | ||||
525 | interface.loadEffect(effect.serviceName); | ||||
526 | } else { | ||||
527 | interface.unloadEffect(effect.serviceName); | ||||
528 | } | ||||
529 | } | ||||
508 | } | 530 | } | ||
509 | 531 | | |||
510 | void EffectModel::defaults() | 532 | void EffectModel::defaults() | ||
511 | { | 533 | { | ||
512 | for (int i = 0; i < m_effectsList.count(); ++i) { | 534 | for (int i = 0; i < m_effectsList.count(); ++i) { | ||
513 | const auto &effect = m_effectsList.at(i); | 535 | const auto &effect = m_effectsList.at(i); | ||
514 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | 536 | if (effect.enabledByDefaultFunction && effect.effectStatus != Status::EnabledUndeterminded) { | ||
515 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | 537 | updateEffectStatus(index(i, 0), Status::EnabledUndeterminded); | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |
I think there's a problem here.
Previously:
m_effectsList is the current state that we think kwin has
m_effectsChanged is what the user has set
we're now losing what we think kwin has
In ::syncEffectsToKWin (line 484 here)
we compare the .effectsStatus of both
If a user makes a change, and then we call reload, and then the user saves:
m_effectsList[0]->effectStatus is the user set value
m_effectsList[0]->changed is true
so we'll write out the correct value in the config file all successfully
but m_effectsList.at(it).effectStatus == m_effectsChanged.at(it).effectStatus so we won't notify kwin.