Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
QtQuickClockManager.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorAnimation/phosphoranimation_export.h>
7
8#include <QtCore/QMetaObject>
9#include <QtCore/QObject>
10#include <QtCore/QPointer>
11
12#include <atomic>
13#include <memory>
14#include <mutex>
15#include <unordered_map>
16
17QT_BEGIN_NAMESPACE
18class QQuickWindow;
19QT_END_NAMESPACE
20
21namespace PhosphorAnimation {
22
23class IMotionClock;
24class QtQuickClock;
25
134class PHOSPHORANIMATION_EXPORT QtQuickClockManager
135{
136public:
139
147
153
169 IMotionClock* clockFor(QQuickWindow* window);
170
178 void releaseClockFor(QQuickWindow* window);
179
180 // ─── Test helpers ───
181
186 int entryCount() const;
187
192
193 // Non-copyable — owns a registry of unique window->clock entries.
196
197private:
205 static std::atomic<QtQuickClockManager*> s_defaultManager;
206
207 struct Entry
208 {
209 QPointer<QQuickWindow> window;
210 std::unique_ptr<QtQuickClock> clock;
219 QMetaObject::Connection destroyedConnection;
220 };
221
222 mutable std::mutex m_mutex;
223 // std::unordered_map (not QHash) because `Entry` contains a
224 // move-only `unique_ptr<QtQuickClock>` — Qt6's QHash still requires
225 // copy-constructible values for its internal Node type. Same
226 // rationale as `AnimationController::m_animations` in Phase 3.
227 // Keyed on raw pointer so hash / equality are cheap. `QPointer`
228 // inside `Entry` is consulted on lookup to detect stale windows;
229 // keying on `QPointer` directly would be possible but hash /
230 // comparison against raw `QQuickWindow*` keys in callers would
231 // demand conversions on every lookup.
232 std::unordered_map<QQuickWindow*, Entry> m_entries;
233};
234
235} // namespace PhosphorAnimation
Abstract clock interface for the motion runtime.
Definition IMotionClock.h:18
Enforces "one QtQuickClock per QQuickWindow" within a single composition-root-owned manager instance.
Definition QtQuickClockManager.h:135
IMotionClock * clockFor(QQuickWindow *window)
Return the clock for window, constructing it on first call.
QtQuickClockManager & operator=(const QtQuickClockManager &)=delete
int entryCount() const
Current number of active entries.
void clearForTest()
Drop every entry.
static void setDefaultManager(QtQuickClockManager *manager)
Publish manager as the process-wide default for QML-side consumers (PhosphorAnimatedValueBase::resolv...
void releaseClockFor(QQuickWindow *window)
Drop the clock entry for window, if any.
static QtQuickClockManager * defaultManager()
Read-only view of the manager pointer published by setDefaultManager.
QtQuickClockManager(const QtQuickClockManager &)=delete
Definition AnimatedValue.h:31