From ad68d6860ea6edbde4f85be05e06dc3f51dcf249 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Mon, 8 May 2023 00:32:03 +0200 Subject: [PATCH] globalshortcuts: Do not ignore duplicated shortcuts If a shortcut has been registered several times, we can activate them several times as well. Otherwise we just registered the first one that was introduced. This also makes it impossible to use certain shortcuts depending on the state. --- src/globalshortcuts.cpp | 18 ++++++------------ src/globalshortcuts.h | 2 +- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/globalshortcuts.cpp b/src/globalshortcuts.cpp index 8b18664608..b75095bfde 100644 --- a/src/globalshortcuts.cpp +++ b/src/globalshortcuts.cpp @@ -120,14 +120,8 @@ void GlobalShortcutsManager::objectDeleted(QObject *object) } } -bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc, DeviceType device) +bool GlobalShortcutsManager::add(GlobalShortcut sc, DeviceType device) { - for (const auto &cs : std::as_const(m_shortcuts)) { - if (sc.shortcut() == cs.shortcut()) { - return false; - } - } - const auto &recognizer = device == DeviceType::Touchpad ? m_touchpadGestureRecognizer : m_touchscreenGestureRecognizer; if (std::holds_alternative(sc.shortcut())) { recognizer->registerSwipeGesture(sc.swipeGesture()); @@ -141,27 +135,27 @@ bool GlobalShortcutsManager::addIfNotExists(GlobalShortcut sc, DeviceType device void GlobalShortcutsManager::registerPointerShortcut(QAction *action, Qt::KeyboardModifiers modifiers, Qt::MouseButtons pointerButtons) { - addIfNotExists(GlobalShortcut(PointerButtonShortcut{modifiers, pointerButtons}, action)); + add(GlobalShortcut(PointerButtonShortcut{modifiers, pointerButtons}, action)); } void GlobalShortcutsManager::registerAxisShortcut(QAction *action, Qt::KeyboardModifiers modifiers, PointerAxisDirection axis) { - addIfNotExists(GlobalShortcut(PointerAxisShortcut{modifiers, axis}, action)); + add(GlobalShortcut(PointerAxisShortcut{modifiers, axis}, action)); } void GlobalShortcutsManager::registerTouchpadSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function progressCallback) { - addIfNotExists(GlobalShortcut(RealtimeFeedbackSwipeShortcut{DeviceType::Touchpad, direction, progressCallback, fingerCount}, action), DeviceType::Touchpad); + add(GlobalShortcut(RealtimeFeedbackSwipeShortcut{DeviceType::Touchpad, direction, progressCallback, fingerCount}, action), DeviceType::Touchpad); } void GlobalShortcutsManager::registerTouchpadPinch(PinchDirection direction, uint32_t fingerCount, QAction *action, std::function progressCallback) { - addIfNotExists(GlobalShortcut(RealtimeFeedbackPinchShortcut{direction, progressCallback, fingerCount}, action), DeviceType::Touchpad); + add(GlobalShortcut(RealtimeFeedbackPinchShortcut{direction, progressCallback, fingerCount}, action), DeviceType::Touchpad); } void GlobalShortcutsManager::registerTouchscreenSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function progressCallback) { - addIfNotExists(GlobalShortcut(RealtimeFeedbackSwipeShortcut{DeviceType::Touchscreen, direction, progressCallback, fingerCount}, action), DeviceType::Touchscreen); + add(GlobalShortcut(RealtimeFeedbackSwipeShortcut{DeviceType::Touchscreen, direction, progressCallback, fingerCount}, action), DeviceType::Touchscreen); } void GlobalShortcutsManager::forceRegisterTouchscreenSwipe(SwipeDirection direction, uint32_t fingerCount, QAction *action, std::function progressCallback) diff --git a/src/globalshortcuts.h b/src/globalshortcuts.h index 7ed3b7e378..5002baab6c 100644 --- a/src/globalshortcuts.h +++ b/src/globalshortcuts.h @@ -113,7 +113,7 @@ public: private: void objectDeleted(QObject *object); - bool addIfNotExists(GlobalShortcut sc, DeviceType device = DeviceType::Touchpad); + bool add(GlobalShortcut sc, DeviceType device = DeviceType::Touchpad); QVector m_shortcuts;