Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
IBackend.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 <QKeySequence>
7#include <QObject>
8#include <QString>
9#include <QStringList>
10
11#include <optional>
12
13#include "phosphorshortcuts_export.h"
14
15namespace PhosphorShortcuts {
16
31class PHOSPHORSHORTCUTS_EXPORT IBackend : public QObject
32{
33 Q_OBJECT
34public:
35 explicit IBackend(QObject* parent = nullptr)
36 : QObject(parent)
37 {
38 }
39 ~IBackend() override = default;
40
83 virtual void registerShortcut(const QString& id, const QKeySequence& defaultSeq, const QKeySequence& currentSeq,
84 const QString& description, bool persistent = true) = 0;
85
103 virtual void updateShortcut(const QString& id, const QKeySequence& defaultSeq, const QKeySequence& newTrigger) = 0;
104
117 virtual void unregisterShortcut(const QString& id) = 0;
118
140 virtual void suspendShortcut(const QString& id)
141 {
143 }
144
159 virtual void storeShortcut(const QString& id, const QKeySequence& seq)
160 {
161 Q_UNUSED(id);
162 Q_UNUSED(seq);
163 }
164
175 virtual void forgetShortcut(const QString& id)
176 {
177 Q_UNUSED(id);
178 }
179
186 virtual std::optional<QStringList> storedShortcutIds() const
187 {
188 return std::nullopt;
189 }
190
198 virtual bool suspendReleasesGrab() const
199 {
200 return true;
201 }
202
210 virtual bool registersUnboundIds() const
211 {
212 return false;
213 }
214
221 virtual void flush() = 0;
222
255 virtual std::optional<QStringList> currentTriggers(const QString& id) const
256 {
257 Q_UNUSED(id);
258 return std::nullopt;
259 }
260
273 virtual bool setForeignShortcuts(const QString& componentName, const QString& actionName,
274 const QList<QKeySequence>& sequences)
275 {
276 Q_UNUSED(componentName);
277 Q_UNUSED(actionName);
278 Q_UNUSED(sequences);
279 return false;
280 }
281
305 virtual std::optional<QList<QKeySequence>> foreignShortcuts(const QString& componentName,
306 const QString& actionName) const
307 {
308 Q_UNUSED(componentName);
309 Q_UNUSED(actionName);
310 return std::nullopt;
311 }
312
313Q_SIGNALS:
318 void activated(QString id);
319
325 void ready();
326
335 void triggersChanged(QString id);
336};
337
338} // namespace PhosphorShortcuts
virtual std::optional< QStringList > currentTriggers(const QString &id) const
The key sequence(s) the backend believes are EFFECTIVELY bound for an id right now — i....
Definition IBackend.h:255
virtual std::optional< QStringList > storedShortcutIds() const
Every id the platform holds a persistent record for under this process's component,...
Definition IBackend.h:186
void ready()
Emitted after flush() completes.
void activated(QString id)
Emitted when the backend observes the user triggering a registered shortcut.
virtual bool suspendReleasesGrab() const
Whether suspendShortcut() and unregisterShortcut() actually release the key grab.
Definition IBackend.h:198
IBackend(QObject *parent=nullptr)
Definition IBackend.h:35
virtual void registerShortcut(const QString &id, const QKeySequence &defaultSeq, const QKeySequence &currentSeq, const QString &description, bool persistent=true)=0
Register a new shortcut id.
virtual void suspendShortcut(const QString &id)
Release the key grab for an id WITHOUT destroying whatever the platform persists about it.
Definition IBackend.h:140
virtual bool setForeignShortcuts(const QString &componentName, const QString &actionName, const QList< QKeySequence > &sequences)
Rebind ANOTHER component's global shortcut (kglobalaccel's setForeignShortcutKeys,...
Definition IBackend.h:273
virtual void storeShortcut(const QString &id, const QKeySequence &seq)
Write seq into the platform's persistent record for an id that this backend does not currently hold (...
Definition IBackend.h:159
virtual bool registersUnboundIds() const
Whether an id with an empty current sequence must still be registered.
Definition IBackend.h:210
virtual void forgetShortcut(const QString &id)
Delete the platform's persistent record for an id, releasing any grab that record still holds.
Definition IBackend.h:175
virtual std::optional< QList< QKeySequence > > foreignShortcuts(const QString &componentName, const QString &actionName) const
The current bindings of another component's action, every sequence it answers to, in the order the bi...
Definition IBackend.h:305
virtual void updateShortcut(const QString &id, const QKeySequence &defaultSeq, const QKeySequence &newTrigger)=0
Change the active binding for an already-registered id.
virtual void unregisterShortcut(const QString &id)=0
Release the key grab for an id.
virtual void flush()=0
Commit any queued register/update ops.
void triggersChanged(QString id)
Emitted when the effective binding for an id changes outside the register/update flow — e....
~IBackend() override=default
Definition Factory.h:12