Pluggable global-shortcut backends behind a single registration API: KGlobalAccel (Plasma-native), XDG Portal (xdg-desktop-portal.GlobalShortcuts), and a D-Bus ad-hoc fallback.
"Super+1 snaps to zone 1" needs to register a global shortcut from a userspace process. On Plasma that goes through KGlobalAccel. On generic Wayland compositors that support the portal, it goes through org.freedesktop.portal.GlobalShortcuts. On compositors with neither, there's no standard, so the ad-hoc D-Bus fallback exists for compositor-script or compositor-provided shortcut dispatch.
The consumer shouldn't care which backend is active. phosphor-shortcuts:
| Type | Purpose |
|---|---|
| PhosphorShortcuts::Registry | Front-end: bind() a shortcut id and callback |
| PhosphorShortcuts::IBackend | Abstract backend. Shipped implementations: KGlobalAccel, XDG-Portal, D-Bus |
| PhosphorShortcutsIntegration::IAdhocRegistrar | Short-lived registrations that skip persistent storage |
| PhosphorShortcuts::createBackend | Selects the right backend based on running environment |
#include <PhosphorShortcuts/Registry.h>
#include <PhosphorShortcuts/Factory.h>
using namespace PhosphorShortcuts;
auto backend = createBackend(); // picks KGlobalAccel on Plasma
Registry registry(backend.get());
registry.bind(
/*id*/ QStringLiteral("snap-to-quick-1"),
/*defaultSeq*/ QKeySequence(QStringLiteral("Meta+1")),
/*description*/ tr("Snap active window to Quick Layout 1"),
/*callback*/ [] { engine.snapTo(1); },
/*persistent*/ true
);Switching backends is a one-liner. The Registry API stays the same, and you pass a different IBackend.
auto portalBackend = createBackend(BackendHint::Portal);
Registry adhoc(portalBackend.get());
adhoc.bind(id, seq, desc, cb, /*persistent*/ false);