presentation/SystemMotionPreference.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QDBusVariant> | ||
| 4 | #include <QObject> | ||
| 5 | #include <QString> | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <optional> | ||
| 9 | |||
| 10 | // Q10/Q13 (B3 obligation): the desktop's reduced-motion preference. | ||
| 11 | // The query follows the XDG settings-portal contract | ||
| 12 | // (org.freedesktop.portal.Desktop / Settings, namespace | ||
| 13 | // "org.freedesktop.appearance", key "animations": false means the desktop | ||
| 14 | // requests reduced animation). Desktops without that key, headless | ||
| 15 | // sessions or a missing session bus report "unknown" - the manual | ||
| 16 | // preference then governs exactly as before. | ||
| 17 | class SystemMotionPreference final : public QObject { | ||
| 18 | Q_OBJECT | ||
| 19 | public: | ||
| 20 | // Injectable probe (tests, headless environments). Returns | ||
| 21 | // nullopt when the system preference is unavailable. | ||
| 22 | using Probe = std::function<std::optional<bool>()>; | ||
| 23 | |||
| 24 | explicit SystemMotionPreference(QObject *parent = nullptr); | ||
| 25 | |||
| 26 | // The current desktop preference, read on every call. The portal's | ||
| 27 | // SettingChanged signal for this key calls refresh() (S106-353: the | ||
| 28 | // subscription was missing, a desktop change waited for a restart). | ||
| 29 |
1/2✓ Branch 3 → 4 taken 786 times.
✗ Branch 3 → 5 not taken.
|
786 | std::optional<bool> systemReducedMotion() const { return m_probe ? m_probe() : std::optional<bool>{}; } |
| 30 | |||
| 31 | 7 | void setProbe(Probe probe) { m_probe = std::move(probe); } | |
| 32 | |||
| 33 | // Re-reads the preference and reports whether the value changed since | ||
| 34 | // the last refresh. | ||
| 35 | bool refresh(); | ||
| 36 | |||
| 37 | static std::optional<bool> queryPortal(); | ||
| 38 | |||
| 39 | signals: | ||
| 40 | void changed(); | ||
| 41 | |||
| 42 | private slots: | ||
| 43 | void settingChanged(const QString &nameSpace, const QString &key, const QDBusVariant &value); | ||
| 44 | |||
| 45 | private: | ||
| 46 | Probe m_probe; | ||
| 47 | std::optional<bool> m_last; | ||
| 48 | }; | ||
| 49 |