| 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | #include "settings.h" |
| 3 | #include <QApplication> |
| 4 | #include <QPluginLoader> |
| 5 | #include <KPluginFactory> |
| 6 | #include <KCModule> |
| 7 | #include <QComboBox> |
| 8 | #include <QSpinBox> |
| 9 | #include <cmath> |
| 10 | #include <QDBusConnection> |
| 11 | #include <QElapsedTimer> |
| 12 | #include <QThread> |
| 13 | class EffectReceiver : public QObject { |
| 14 | Q_OBJECT |
| 15 | Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.Effects") |
| 16 | public: |
| 17 | QString received; |
| 18 | public slots: |
| 19 | void reconfigureEffect(const QString &name) { received = name; } |
| 20 | }; |
| 21 | int main(int argc, char **argv) { |
| 22 | QApplication app(argc, argv); |
| 23 | EffectReceiver receiver; |
| 24 | auto bus = QDBusConnection::sessionBus(); |
| 25 | if (!bus.registerService(QStringLiteral("org.kde.KWin")) || |
| 26 | !bus.registerObject(QStringLiteral("/Effects"), &receiver, QDBusConnection::ExportAllSlots)) return 9; |
| 27 | QPluginLoader loader(QString::fromLocal8Bit(argv[1])); |
| 28 | auto *factory = qobject_cast<KPluginFactory *>(loader.instance()); |
| 29 | if (!factory) return 1; |
| 30 | auto *module = factory->create<KCModule>(); |
| 31 | if (!module) return 2; |
| 32 | const auto combos = module->widget()->findChildren<QComboBox *>(); |
| 33 | const auto spins = module->widget()->findChildren<QSpinBox *>(); |
| 34 | if (combos.size() != 2 || spins.size() != 2) return 3; |
| 35 | for (auto *combo : combos) if (combo->count() != 31) return 4; |
| 36 | auto hasDefaults = [&] { |
| 37 | return spins[0]->value() == 150 && spins[1]->value() == 720 |
| 38 | && combos[0]->currentText() == QLatin1String("easeOutBack") |
| 39 | && combos[1]->currentText() == QLatin1String("easeOutElastic"); |
| 40 | }; |
| 41 | if (!hasDefaults()) return 5; |
| 42 | spins[0]->setValue(42); |
| 43 | combos[0]->setCurrentText(QStringLiteral("Linear")); |
| 44 | module->defaults(); |
| 45 | if (!hasDefaults()) return 5; |
| 46 | spins[0]->setValue(333); |
| 47 | combos[1]->setCurrentText(QStringLiteral("easeOutElastic")); |
| 48 | module->save(); |
| 49 | QElapsedTimer timer; |
| 50 | timer.start(); |
| 51 | while (receiver.received.isEmpty() && timer.elapsed() < 2000) { |
| 52 | app.processEvents(); |
| 53 | QThread::msleep(1); |
| 54 | } |
| 55 | if (receiver.received != QLatin1String("kwin_effect_clicktween")) return 10; |
| 56 | module->load(); |
| 57 | if (spins[0]->value() != 333 || combos[1]->currentText() != QLatin1String("easeOutElastic")) return 6; |
| 58 | for (const auto &entry : ClickTween::curves) { |
| 59 | QEasingCurve curve(ClickTween::curveType(QString::fromLatin1(entry.name))); |
| 60 | if (std::abs(curve.valueForProgress(0)) > 1e-6 || std::abs(curve.valueForProgress(1) - 1) > 1e-6) return 7; |
| 61 | for (int i = 0; i <= 100; ++i) if (!std::isfinite(curve.valueForProgress(i / 100.0))) return 8; |
| 62 | } |
| 63 | delete module; |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | #include "check-config.moc" |