Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
AlgorithmRegistry.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 <phosphortiles_export.h>
8#include "AutotileConstants.h"
10#include <QLatin1String>
11#include <QList>
12#include <QMutex>
13#include <QMutexLocker>
14#include <QObject>
15#include <QString>
16#include <QStringList>
17#include <QVariantList>
18#include <QVariantMap>
19#include <functional>
20#include <memory>
21
22namespace PhosphorTiles {
23
24class TilingAlgorithm;
25
54class PHOSPHORTILES_EXPORT AlgorithmRegistry : public ITileAlgorithmRegistry
55{
56 Q_OBJECT
57 Q_DISABLE_COPY_MOVE(AlgorithmRegistry)
58
59public:
82 void cleanup();
83
84 // ─── ITileAlgorithmRegistry implementation ─────────────────────────────
85
86 void registerAlgorithm(const QString& id, TilingAlgorithm* algorithm) override;
87 bool unregisterAlgorithm(const QString& id) override;
88 TilingAlgorithm* algorithm(const QString& id) const override;
89 QStringList availableAlgorithms() const override;
90 QList<TilingAlgorithm*> allAlgorithms() const override;
91 bool hasAlgorithm(const QString& id) const override;
93
106 QString defaultAlgorithmId() const override
107 {
108 return staticDefaultAlgorithmId();
109 }
110
114 static QString staticDefaultAlgorithmId();
115
116 // ═══════════════════════════════════════════════════════════════════════════
117 // Preview utilities for unified layout model (shared by zone selector,
118 // overlay service, daemon OSD, and KCM algorithm preview)
119 // ═══════════════════════════════════════════════════════════════════════════
120
125 static constexpr int PreviewCanvasSize = 1000;
126
127 // ─── Preview params (ITileAlgorithmRegistry overrides) ─────────────────
128
129 void setPreviewParams(const AlgorithmPreviewParams& params) override;
130 const AlgorithmPreviewParams& previewParams() const noexcept override;
131
135 explicit AlgorithmRegistry(QObject* parent = nullptr);
136 ~AlgorithmRegistry() override;
137
138private:
144 void registerBuiltInAlgorithms();
145
152 class Impl;
153 std::unique_ptr<Impl> m_impl;
154};
155
159struct PHOSPHORTILES_EXPORT PendingAlgorithmRegistration
160{
161 QString id;
163 std::function<TilingAlgorithm*()> factory;
164};
165
180PHOSPHORTILES_EXPORT QList<PendingAlgorithmRegistration>& pendingAlgorithmRegistrations();
181
186PHOSPHORTILES_EXPORT class QMutex& pendingAlgorithmRegistrationsMutex();
187
205template<typename T>
207{
208public:
215 explicit AlgorithmRegistrar(const QString& id, int priority = 100)
216 {
217 // Store in the global (non-template) pending list. Locked so
218 // multiple algorithm libraries' static-init can run concurrently
219 // (Qt plugin loader on a worker thread, parallel test binaries
220 // sharing a process) without corrupting the QList.
221 QMutexLocker locker(&pendingAlgorithmRegistrationsMutex());
222 pendingAlgorithmRegistrations().append({id, priority, []() {
223 return new T();
224 }});
225 }
226};
227
228} // namespace PhosphorTiles
Algorithm-layer constants for the autotile/tile primitives.
Helper for static self-registration of built-in algorithms.
Definition AlgorithmRegistry.h:207
AlgorithmRegistrar(const QString &id, int priority=100)
Register an algorithm at static initialization time.
Definition AlgorithmRegistry.h:215
Concrete tiling-algorithm registry.
Definition AlgorithmRegistry.h:55
bool hasAlgorithm(const QString &id) const override
Whether an algorithm is registered under id.
void cleanup()
Early cleanup of all registered algorithms.
void setPreviewParams(const AlgorithmPreviewParams &params) override
Apply the user-configured tiling parameters.
QStringList availableAlgorithms() const override
All registered algorithm ids.
QString defaultAlgorithmId() const override
Get the library's recommended default algorithm ID.
Definition AlgorithmRegistry.h:106
TilingAlgorithm * defaultAlgorithm() const override
Convenience: the registry's recommended default algorithm.
bool unregisterAlgorithm(const QString &id) override
Unregister and delete the algorithm with id.
const AlgorithmPreviewParams & previewParams() const noexcept override
The currently-configured preview parameters.
TilingAlgorithm * algorithm(const QString &id) const override
Resolve an algorithm by its stable id.
void registerAlgorithm(const QString &id, TilingAlgorithm *algorithm) override
Register an algorithm under id.
static QString staticDefaultAlgorithmId()
Static accessor for the same id defaultAlgorithmId() returns.
QList< TilingAlgorithm * > allAlgorithms() const override
Every registered algorithm pointer.
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Abstract base class for tiling algorithms.
Definition TilingAlgorithm.h:51
Definition AutotileEngine.h:46
PHOSPHORTILES_EXPORT QList< PendingAlgorithmRegistration > & pendingAlgorithmRegistrations()
Global list of pending algorithm registrations.
PHOSPHORTILES_EXPORT class QMutex & pendingAlgorithmRegistrationsMutex()
Mutex protecting pendingAlgorithmRegistrations().
User-configured tiling parameters that affect algorithm preview generation.
Definition AlgorithmPreviewParams.h:20
Pending algorithm registration data.
Definition AlgorithmRegistry.h:160
QString id
Definition AlgorithmRegistry.h:161
int priority
Definition AlgorithmRegistry.h:162