mutterkey
KDE-first push-to-talk transcription tool for KDE Plasma
Loading...
Searching...
No Matches
hotkeymanager.h
Go to the documentation of this file.
1#pragma once
2
3#include "config.h"
4
5#include <QJsonArray>
6#include <QJsonObject>
7#include <QKeySequence>
8#include <QObject>
9
10class QAction;
11
17[[nodiscard]] QJsonArray keySequenceToDiagnosticJson(const QKeySequence &sequence);
18
24[[nodiscard]] QString keySequenceListToPortableText(const QList<QKeySequence> &sequences);
25
31[[nodiscard]] QKeySequence parseConfiguredKeySequence(const QString &sequenceText);
32
44class HotkeyManager final : public QObject
45{
46 Q_OBJECT
47
48public:
54 explicit HotkeyManager(ShortcutConfig config, QObject *parent = nullptr);
55
59 ~HotkeyManager() override;
60
61 Q_DISABLE_COPY_MOVE(HotkeyManager)
62
63
68 bool registerShortcut(QString *errorMessage = nullptr);
69
74
80 bool invokeShortcut(QString *errorMessage = nullptr);
81
86 [[nodiscard]] QJsonObject diagnostics() const;
87
88signals:
93
98
99private Q_SLOTS:
105 void onGlobalShortcutActiveChanged(QAction *action, bool active);
106
107private:
114 bool parseSequence(QKeySequence *sequence, QString *errorMessage = nullptr) const;
115
117 ShortcutConfig m_config;
119 QAction *m_action = nullptr;
121 QKeySequence m_assignedSequence;
123 int m_pressedEvents = 0;
125 int m_releasedEvents = 0;
127 bool m_registered = false;
129 bool m_shortcutActive = false;
130};
Wraps KGlobalAccel registration for Mutterkey's push-to-talk shortcut.
~HotkeyManager() override
Unregisters the shortcut and releases owned KDE objects.
void shortcutReleased()
Emitted when the registered shortcut is released.
QJsonObject diagnostics() const
Returns diagnostic state about registration and event counts.
void shortcutPressed()
Emitted when the registered shortcut becomes active.
bool registerShortcut(QString *errorMessage=nullptr)
Registers the configured shortcut with KDE global accel.
bool invokeShortcut(QString *errorMessage=nullptr)
Simulates shortcut invocation through the KDE action object.
void unregisterShortcut()
Unregisters the shortcut if it is currently active.
HotkeyManager(ShortcutConfig config, QObject *parent=nullptr)
Creates a hotkey manager with a fixed shortcut configuration.
Runtime configuration types, defaults, and JSON loading entrypoints.
QString keySequenceListToPortableText(const QList< QKeySequence > &sequences)
Formats a key sequence list as portable-text diagnostics.
QJsonArray keySequenceToDiagnosticJson(const QKeySequence &sequence)
Converts an assigned key sequence into the diagnostic JSON payload shape.
QKeySequence parseConfiguredKeySequence(const QString &sequenceText)
Parses a configured shortcut string into a Qt key sequence.
Global shortcut registration settings.
Definition config.h:32