The one place a presetId on an assignment turns into parameters. More...
#include <PhosphorShaders/ShaderPresetRegistry.h>
Signals | |
| void | presetsChanged (PhosphorShaders::ShaderFamily family, const QString &packId) |
The presets offered for (family, packId) changed: one was added, removed, renamed, or retuned. | |
Public Member Functions | |
| ShaderPresetRegistry (QObject *parent=nullptr) | |
| ~ShaderPresetRegistry () override | |
| QList< ShaderPreset > | presetsFor (ShaderFamily family, const QString &packId) const |
Every preset offered for packId in family, user presets first, each group sorted by display name so the picker order is stable across restarts (a QHash iteration order is not). | |
| ShaderPreset | preset (ShaderFamily family, const QString &packId, const QString &presetId) const |
The preset presetId names, or an invalid preset when it names none. | |
| ShaderPreset | presetById (ShaderFamily family, const QString &presetId) const |
The preset presetId names, searched across every pack in family. | |
| QVariantMap | resolveParams (ShaderFamily family, const QString &packId, const QString &presetId, const QVariantMap &deltas) const |
The effective parameter map for an assignment: the preset's parameters overlaid with deltas, the assignment's own edits. | |
| void | setPackPresets (ShaderFamily family, const QString &packId, const PackPresets &presets, const PresetValueBounds &bounds={}) |
Replace every pack-declared preset for packId in family. | |
| void | setPackPresetsForFamily (ShaderFamily family, const QHash< QString, PackPresets > &byPackId, const QHash< QString, PresetValueBounds > &boundsByPackId={}) |
Replace every pack-declared preset for EVERY pack in family at once. | |
| void | setUserPresets (ShaderFamily family, const QList< ShaderPreset > &presets) |
Replace every user preset in family with presets. | |
The one place a presetId on an assignment turns into parameters.
Holds both provenances behind a single lookup, so a consumer resolving an assignment never has to care whether the preset came from a pack's metadata.json or from a file the user saved:
• Pack-declared presets arrive via setPackPresets, called by whoever owns the family's pack registry whenever that registry reloads (the existing effectsChanged / shadersChanged edge). • User presets arrive via setUserPresets, called by ShaderPresetStore on each rescan of the user preset directories.
On a collision the USER preset wins, matching the user-wins layering every other Phosphor loader applies to a user file shadowing a system one.
All four consumers resolve presets: the settings app (to show and edit them), the daemon (overlay and OSD surfaces), the KWin effect (window animations, decorations, pointer) and the shell (its own surface chrome). The effect has no access to the config file — it pulls the assignment trees from the daemon over D-Bus — but it DOES read pack and data directories from disk itself, exactly as it already does for pack registries. Putting the store here, in the one library all four already link, lets every process resolve a preset by the same rule from the same files, instead of inventing a second flattened wire shape.
GUI-thread only, like the pack registries it sits beside.
|
explicit |
|
override |
| ShaderPreset PhosphorShaders::ShaderPresetRegistry::preset | ( | ShaderFamily | family, |
| const QString & | packId, | ||
| const QString & | presetId ) const |
The preset presetId names, or an invalid preset when it names none.
A MISS IS NORMAL, not an error: an assignment can outlive the preset it points at (the user deleted it, or a pack update dropped it). Callers resolve a miss to the pack's declared defaults plus the assignment's own deltas, which is the same look the assignment would have had with no preset — degraded, never broken.
| ShaderPreset PhosphorShaders::ShaderPresetRegistry::presetById | ( | ShaderFamily | family, |
| const QString & | presetId ) const |
The preset presetId names, searched across every pack in family.
Ids are MEANT to be unique within a family — the settings app mints a UUID for each user preset, and a pack-declared id is namespaced by its pack. Nothing enforces it, though: a user preset's id comes from a hand-editable file, so two packs can carry the same id. The search is therefore over sorted keys, so the answer is at least the SAME one on every run rather than whichever bucket QHash happened to yield first; setUserPresets warns when it sees a duplicate.
The WRITE side needs this: it acts on a preset the user picked by id and has to learn which pack it belongs to in order to write it back.
Prefer the pack-scoped preset() for RESOLUTION, which must not match a preset belonging to a different pack than the assignment resolved to.
|
signal |
The presets offered for (family, packId) changed: one was added, removed, renamed, or retuned.
Consumers hang re-resolution off this. For the compositor that means the same handler effectsChanged already uses, since a retuned preset changes parameters that are baked into a compiled surface pack.
| QList< ShaderPreset > PhosphorShaders::ShaderPresetRegistry::presetsFor | ( | ShaderFamily | family, |
| const QString & | packId ) const |
Every preset offered for packId in family, user presets first, each group sorted by display name so the picker order is stable across restarts (a QHash iteration order is not).
| QVariantMap PhosphorShaders::ShaderPresetRegistry::resolveParams | ( | ShaderFamily | family, |
| const QString & | packId, | ||
| const QString & | presetId, | ||
| const QVariantMap & | deltas ) const |
The effective parameter map for an assignment: the preset's parameters overlaid with deltas, the assignment's own edits.
With an empty presetId, or one naming no preset, this is just deltas — so a consumer can route EVERY assignment through here and stop special-casing "has a preset".
Every value returned is clamped to the pack's declared range when the seeding consumer supplied one (see setPackPresets). This is the single funnel preset values leave by, so clamping here covers a pack-declared preset, a hand-written user preset file and an assignment's own deltas alike. Unclamped, any of the three could drive a pack's GLSL loop bound past what the shader can afford.
| void PhosphorShaders::ShaderPresetRegistry::setPackPresets | ( | ShaderFamily | family, |
| const QString & | packId, | ||
| const PackPresets & | presets, | ||
| const PresetValueBounds & | bounds = {} ) |
Replace every pack-declared preset for packId in family.
Called on the pack registry's reload edge. Emits presetsChanged only when the resulting set actually differs, because that signal drops the compiled-pack caches in the compositor and a reload that changed nothing must not cost a recompile.
bounds are the pack's declared parameter ranges, which resolveParams clamps every value to. Build it with presetBoundsFrom(info.parameters) at the call site — the caller already has the declared parameter list, and this library deliberately does not depend on the four pack registries. Passing an empty map leaves that pack's values unclamped.
| void PhosphorShaders::ShaderPresetRegistry::setPackPresetsForFamily | ( | ShaderFamily | family, |
| const QHash< QString, PackPresets > & | byPackId, | ||
| const QHash< QString, PresetValueBounds > & | boundsByPackId = {} ) |
Replace every pack-declared preset for EVERY pack in family at once.
Prefer this over looping setPackPresets, because a loop driven by the packs that currently exist can never name a pack that has GONE: it simply does not visit it, so an uninstalled pack's presets survive for the process lifetime and keep being offered by presetsFor and returned by presetById. This overload diffs against everything already held for the family, so a vanished pack is retracted by construction — the same property setUserPresets has, and for the same reason.
Emits presetsChanged once per pack whose set actually changed.
| void PhosphorShaders::ShaderPresetRegistry::setUserPresets | ( | ShaderFamily | family, |
| const QList< ShaderPreset > & | presets ) |
Replace every user preset in family with presets.
Whole-family replace rather than per-file update, because that is the shape DirectoryLoader commits in: one batch per rescan, carrying every file currently on disk. Emits presetsChanged once per pack whose set actually changed, so one rescan that touched one file does not invalidate every pack's compiled shaders.