kglobalaccel: Attempt to register media shortcuts too
This commit is contained in:
parent
8b1d198efd
commit
bbd81e7d9c
|
@ -58,6 +58,16 @@ bool GlobalShortcutsBackendKDE::IsAvailable() const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GlobalShortcutsBackendKDE::IsMediaShortcut(const GlobalShortcutsManager::Shortcut &shortcut) const {
|
||||||
|
|
||||||
|
return (shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay) ||
|
||||||
|
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaStop) ||
|
||||||
|
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaNext) ||
|
||||||
|
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPrevious));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool GlobalShortcutsBackendKDE::DoRegister() {
|
bool GlobalShortcutsBackendKDE::DoRegister() {
|
||||||
|
|
||||||
qLog(Debug) << "Registering";
|
qLog(Debug) << "Registering";
|
||||||
|
@ -136,14 +146,6 @@ bool GlobalShortcutsBackendKDE::RegisterShortcut(const GlobalShortcutsManager::S
|
||||||
|
|
||||||
if (!interface_ || !interface_->isValid() || shortcut.id.isEmpty() || !shortcut.action || shortcut.action->shortcut().isEmpty()) return false;
|
if (!interface_ || !interface_->isValid() || shortcut.id.isEmpty() || !shortcut.action || shortcut.action->shortcut().isEmpty()) return false;
|
||||||
|
|
||||||
if (shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPlay) ||
|
|
||||||
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaStop) ||
|
|
||||||
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaNext) ||
|
|
||||||
shortcut.action->shortcut() == QKeySequence(Qt::Key_MediaPrevious)) {
|
|
||||||
qLog(Info) << "Media shortcut" << shortcut.id << shortcut.action->shortcut();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList action_id = GetActionId(shortcut.id, shortcut.action);
|
QStringList action_id = GetActionId(shortcut.id, shortcut.action);
|
||||||
actions_.insert(shortcut.id, shortcut.action);
|
actions_.insert(shortcut.id, shortcut.action);
|
||||||
interface_->doRegister(action_id);
|
interface_->doRegister(action_id);
|
||||||
|
@ -152,17 +154,16 @@ bool GlobalShortcutsBackendKDE::RegisterShortcut(const GlobalShortcutsManager::S
|
||||||
|
|
||||||
const QList<int> result = interface_->setShortcut(action_id, ToIntList(active_shortcut), 0x2);
|
const QList<int> result = interface_->setShortcut(action_id, ToIntList(active_shortcut), 0x2);
|
||||||
const QList<QKeySequence> result_sequence = ToKeySequenceList(result);
|
const QList<QKeySequence> result_sequence = ToKeySequenceList(result);
|
||||||
if (result_sequence != active_shortcut) {
|
if (result_sequence == active_shortcut) {
|
||||||
if (result_sequence.isEmpty()) {
|
qLog(Info) << "Registered shortcut" << shortcut.id << shortcut.action->shortcut();
|
||||||
shortcut.action->setShortcut(QKeySequence());
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
qLog(Error) << "KGlobalAccel returned" << result_sequence << "when setting shortcut" << active_shortcut;
|
||||||
|
if (!result_sequence.isEmpty() && !IsMediaShortcut(shortcut)) {
|
||||||
shortcut.action->setShortcut(result_sequence[0]);
|
shortcut.action->setShortcut(result_sequence[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qLog(Info) << "Registered shortcut" << shortcut.id << shortcut.action->shortcut();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ class GlobalShortcutsBackendKDE : public GlobalShortcutsBackend {
|
||||||
void DoUnregister() override;
|
void DoUnregister() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool IsMediaShortcut(const GlobalShortcutsManager::Shortcut &shortcut) const;
|
||||||
bool RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut);
|
bool RegisterShortcut(const GlobalShortcutsManager::Shortcut &shortcut);
|
||||||
static QStringList GetActionId(const QString &id, const QAction *action);
|
static QStringList GetActionId(const QString &id, const QAction *action);
|
||||||
static QList<int> ToIntList(const QList<QKeySequence> &sequence_list);
|
static QList<int> ToIntList(const QList<QKeySequence> &sequence_list);
|
||||||
|
|
Loading…
Reference in New Issue