Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
PhosphorTiles::AlgorithmRegistry Class Reference

Concrete tiling-algorithm registry. More...

#include <phosphor-tiles/include/PhosphorTiles/AlgorithmRegistry.h>

Inheritance diagram for PhosphorTiles::AlgorithmRegistry:
[legend]

Public Member Functions

void cleanup ()
 Early cleanup of all registered algorithms.
 
void registerAlgorithm (const QString &id, TilingAlgorithm *algorithm) override
 Register an algorithm under id.
 
bool unregisterAlgorithm (const QString &id) override
 Unregister and delete the algorithm with id.
 
TilingAlgorithmalgorithm (const QString &id) const override
 Resolve an algorithm by its stable id.
 
QStringList availableAlgorithms () const override
 All registered algorithm ids.
 
QList< TilingAlgorithm * > allAlgorithms () const override
 Every registered algorithm pointer.
 
bool hasAlgorithm (const QString &id) const override
 Whether an algorithm is registered under id.
 
TilingAlgorithmdefaultAlgorithm () const override
 Convenience: the registry's recommended default algorithm.
 
QString defaultAlgorithmId () const override
 Get the library's recommended default algorithm ID.
 
void setPreviewParams (const AlgorithmPreviewParams &params) override
 Apply the user-configured tiling parameters.
 
const AlgorithmPreviewParamspreviewParams () const noexcept override
 The currently-configured preview parameters.
 
 AlgorithmRegistry (QObject *parent=nullptr)
 Composition roots (daemon, editor, settings, tests) construct their own registry instance.
 
 ~AlgorithmRegistry () override
 
- Public Member Functions inherited from PhosphorTiles::ITileAlgorithmRegistry
 ITileAlgorithmRegistry (QObject *parent=nullptr)
 
 ~ITileAlgorithmRegistry () override
 
- Public Member Functions inherited from PhosphorLayout::ILayoutSourceRegistry
 ILayoutSourceRegistry (QObject *parent=nullptr)
 
 ~ILayoutSourceRegistry () override
 

Static Public Member Functions

static QString staticDefaultAlgorithmId ()
 Static accessor for the same id defaultAlgorithmId() returns.
 

Static Public Attributes

static constexpr int PreviewCanvasSize = 1000
 Canvas edge length used by every preview path that converts algorithm output into relative (0.0–1.0) geometry.
 

Additional Inherited Members

- Signals inherited from PhosphorTiles::ITileAlgorithmRegistry
void algorithmRegistered (const QString &id)
 An algorithm has been registered.
 
void algorithmUnregistered (const QString &id, bool replacing)
 An algorithm has been unregistered or is being replaced.
 
void previewParamsChanged ()
 Preview parameters changed via setPreviewParams.
 
- Signals inherited from PhosphorLayout::ILayoutSourceRegistry
void contentsChanged ()
 Emitted when the set of layouts this registry produces changes in any way that invalidates cached previews — entries added, removed, renamed, or re-parameterised.
 

Detailed Description

Concrete tiling-algorithm registry.

Implements the ITileAlgorithmRegistry contract. Composition roots (daemon, editor, settings, tests) construct their own instance and inject it into every consumer that needs algorithm enumeration / lookup / preview-param access. There is no process-global singleton — plugin-based compositor/WM/shell deployment requires per-instance ownership so plugins cannot corrupt each other's registry state.

The bundled algorithms (BSP, Master-Stack, Columns, …) ship as Luau scripts in data/algorithms and are loaded by ScriptedAlgorithmLoader against an injected registry, alongside user scripts. The AlgorithmRegistrar / pendingAlgorithmRegistrations machinery remains as the extension point for a future compiled-in C++ algorithm, but no in-tree algorithm currently uses it.

Note
Thread Safety: the underlying id-keyed store (a thread-safe PhosphorRegistry::Registry) makes the read operations (algorithm, availableAlgorithms, hasAlgorithm) safe to call from any thread. Registration/unregistration must still occur on the thread that owns the registry (typically the main thread) — not because of the store, but because they drive deleteLater() and Qt signal emission, which are thread-affine.
See also
TilingAlgorithm for the algorithm interface
ITileAlgorithmRegistry for the abstract contract

Constructor & Destructor Documentation

◆ AlgorithmRegistry()

PhosphorTiles::AlgorithmRegistry::AlgorithmRegistry ( QObject *  parent = nullptr)
explicit

Composition roots (daemon, editor, settings, tests) construct their own registry instance.

Built-in algorithms register automatically in the constructor.

◆ ~AlgorithmRegistry()

PhosphorTiles::AlgorithmRegistry::~AlgorithmRegistry ( )
override

Member Function Documentation

◆ algorithm()

TilingAlgorithm * PhosphorTiles::AlgorithmRegistry::algorithm ( const QString &  id) const
overridevirtual

Resolve an algorithm by its stable id.

Returns nullptr when no algorithm with that id is registered.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ allAlgorithms()

QList< TilingAlgorithm * > PhosphorTiles::AlgorithmRegistry::allAlgorithms ( ) const
overridevirtual

Every registered algorithm pointer.

Ownership stays with the registry.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ availableAlgorithms()

QStringList PhosphorTiles::AlgorithmRegistry::availableAlgorithms ( ) const
overridevirtual

All registered algorithm ids.

Order is not part of the contract — the concrete AlgorithmRegistry returns them sorted for a stable cross-platform order; callers must not rely on a specific ordering.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ cleanup()

void PhosphorTiles::AlgorithmRegistry::cleanup ( )

Early cleanup of all registered algorithms.

Wired to QCoreApplication::aboutToQuit so algorithm objects (especially LuauTileAlgorithm instances with lua_State internals) are destroyed while Qt is still fully alive, avoiding teardown crashes if an instance outlives QCoreApplication.

Drains exclusively this registry's own algorithms — it snapshots them before clear()ing the registry (each entry's shared_ptr deleter then schedules a deleteLater()) and calls QCoreApplication::sendPostedEvents(algo, QEvent::DeferredDelete) per algorithm, never the process-wide DeferredDelete queue. This narrow scoping is load-bearing after the singleton kill in PR #343: multiple registries (daemon, editor, settings) each connect to aboutToQuit, and a process-wide drain from one registry would force-delete pending deleteLater() events for unrelated subsystems whose owners have not yet run their teardown.

Safe to call from the destructor as well — idempotent after the first invocation.

◆ defaultAlgorithm()

TilingAlgorithm * PhosphorTiles::AlgorithmRegistry::defaultAlgorithm ( ) const
overridevirtual

Convenience: the registry's recommended default algorithm.

Resolves defaultAlgorithmId() via algorithm() and falls back to the first-registered algorithm if the configured default isn't present. Concrete registries override defaultAlgorithmId to publish their policy id; tests can override either to inject a fake.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ defaultAlgorithmId()

QString PhosphorTiles::AlgorithmRegistry::defaultAlgorithmId ( ) const
inlineoverridevirtual

Get the library's recommended default algorithm ID.

Owned by the algorithm layer itself (not the application config layer) so the registry remains self-contained. Application config layers may expose their own user-facing default; that is intentionally independent.

Returns the same id from any instance (type-level policy, not per-instance state) — the static helper defaultAlgorithmId() is still available for callers that don't hold a registry pointer.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ hasAlgorithm()

bool PhosphorTiles::AlgorithmRegistry::hasAlgorithm ( const QString &  id) const
overridevirtual

Whether an algorithm is registered under id.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ previewParams()

const AlgorithmPreviewParams & PhosphorTiles::AlgorithmRegistry::previewParams ( ) const
overridevirtualnoexcept

The currently-configured preview parameters.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ registerAlgorithm()

void PhosphorTiles::AlgorithmRegistry::registerAlgorithm ( const QString &  id,
TilingAlgorithm algorithm 
)
overridevirtual

Register an algorithm under id.

Ownership transfers to the registry. Re-registering an existing id replaces the old algorithm; algorithmUnregistered(id, replacing=true) fires before algorithmRegistered(id).

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ setPreviewParams()

void PhosphorTiles::AlgorithmRegistry::setPreviewParams ( const AlgorithmPreviewParams params)
overridevirtual

Apply the user-configured tiling parameters.

Emits previewParamsChanged when the stored value differs from the new one; AutotileLayoutSource reacts by invalidating its preview cache.

Implements PhosphorTiles::ITileAlgorithmRegistry.

◆ staticDefaultAlgorithmId()

static QString PhosphorTiles::AlgorithmRegistry::staticDefaultAlgorithmId ( )
static

Static accessor for the same id defaultAlgorithmId() returns.

Provided for callers that already had a hard dependency on the concrete AlgorithmRegistry type.

◆ unregisterAlgorithm()

bool PhosphorTiles::AlgorithmRegistry::unregisterAlgorithm ( const QString &  id)
overridevirtual

Unregister and delete the algorithm with id.

Returns true when an algorithm was found and removed.

Implements PhosphorTiles::ITileAlgorithmRegistry.

Member Data Documentation

◆ PreviewCanvasSize

constexpr int PhosphorTiles::AlgorithmRegistry::PreviewCanvasSize = 1000
staticconstexpr

Canvas edge length used by every preview path that converts algorithm output into relative (0.0–1.0) geometry.

Exposed publicly so external callers (e.g. AutotileLayoutSource, SettingsController's live-param preview) scale against the same canvas without drift.


The documentation for this class was generated from the following file: