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

Consumer-facing facade over IBackend. More...

#include <phosphor-shortcuts/include/PhosphorShortcuts/Registry.h>

Inheritance diagram for Phosphor::Shortcuts::Registry:
[legend]

Classes

struct  Binding
 

Signals

void triggered (QString id)
 Emitted on every activation, regardless of whether the binding has a callback.
 
void ready ()
 Forwarded from IBackend::ready().
 

Public Member Functions

 Registry (IBackend *backend, QObject *parent=nullptr)
 
 ~Registry () override
 
void bind (const QString &id, const QKeySequence &defaultSeq, const QString &description={}, std::function< void()> callback={}, bool persistent=true)
 Register a shortcut.
 
void rebind (const QString &id, const QKeySequence &seq)
 Change the active binding for an already-registered id.
 
void unbind (const QString &id)
 Drop a binding entirely.
 
void flush ()
 Forward queued bind/rebind ops to the backend.
 
QKeySequence shortcut (const QString &id) const
 
QVector< Bindingbindings (bool persistentOnly=false) const
 Enumerate registered bindings, sorted by id for deterministic output.
 

Detailed Description

Consumer-facing facade over IBackend.

Owns a table of (id, default sequence, current sequence, description, optional callback) rows. Forwards registration + rebind calls to the backend and fans activation signals out as either per-id callbacks or the triggered() signal — consumers may use either pattern interchangeably.

The Registry does not own the backend; the caller keeps the backend alive for the Registry's lifetime. Passing a null backend is a programming error.

Constructor & Destructor Documentation

◆ Registry()

Phosphor::Shortcuts::Registry::Registry ( IBackend backend,
QObject *  parent = nullptr 
)
explicit

◆ ~Registry()

Phosphor::Shortcuts::Registry::~Registry ( )
override

Member Function Documentation

◆ bind()

void Phosphor::Shortcuts::Registry::bind ( const QString &  id,
const QKeySequence &  defaultSeq,
const QString &  description = {},
std::function< void()>  callback = {},
bool  persistent = true 
)

Register a shortcut.

Safe to call multiple times for the same id — subsequent calls update the default sequence, description, and callback in place but PRESERVE the current sequence (any user-applied rebind is kept). Takes effect after flush().

Parameters
callbackOptional. Invoked on activation in addition to the triggered() signal. Nullptr callbacks are stored but never invoked; consumers relying purely on the signal can omit the argument.
persistentIf false, the binding is considered transient (e.g. a grab bound around a specific UI state) and is excluded from bindings(true) enumeration. Does not affect backend behaviour. Defaults to true.

Note: descriptions are captured at first-flush time and NOT forwarded on subsequent bind() calls — IBackend::updateShortcut doesn't carry a description argument. Description changes at runtime are local-only.

◆ bindings()

QVector< Binding > Phosphor::Shortcuts::Registry::bindings ( bool  persistentOnly = false) const

Enumerate registered bindings, sorted by id for deterministic output.

Parameters
persistentOnlyIf true, transient bindings (those registered with persistent=false) are excluded. Intended for settings UIs that should not expose internal ad-hoc grabs to the user. Defaults to false so tests and library-internal callers see everything.

◆ flush()

void Phosphor::Shortcuts::Registry::flush ( )

Forward queued bind/rebind ops to the backend.

Does NOT include unbind() — those are applied immediately at the call site. Matches the backend's queue-then-flush model for register / update.

ready() fires after EVERY flush, including no-op flushes where no entry actually changed. This matches the backend contract (each IBackend::flush() emits ready) and lets consumers gate UI on "any flush has settled" without per-entry bookkeeping. If you need "only fire when something actually changed", track that on the caller side.

◆ ready

void Phosphor::Shortcuts::Registry::ready ( )
signal

Forwarded from IBackend::ready().

◆ rebind()

void Phosphor::Shortcuts::Registry::rebind ( const QString &  id,
const QKeySequence &  seq 
)

Change the active binding for an already-registered id.

Takes effect after flush(). Unknown ids are logged and ignored. Passing an empty QKeySequence routes through unbind() — releasing the grab cleanly rather than leaving an empty sequence registered.

◆ shortcut()

QKeySequence Phosphor::Shortcuts::Registry::shortcut ( const QString &  id) const

◆ triggered

void Phosphor::Shortcuts::Registry::triggered ( QString  id)
signal

Emitted on every activation, regardless of whether the binding has a callback.

Use this for centralised dispatch (one slot, switch on id).

Signature matches IBackend::activated (QString by value) so the two signals can be cross-connected without adapter slots.

◆ unbind()

void Phosphor::Shortcuts::Registry::unbind ( const QString &  id)

Drop a binding entirely.

Releases any key grab and forgets the callback. Idempotent. Applied immediately — NOT batched until flush() — because the backends' unregister paths all act synchronously or with trivial state, and a late flush would be surprising for a "release this grab now" API.


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