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.
This commit is contained in:
Aleix Pol 2023-05-08 00:32:03 +02:00 committed by Aleix Pol Gonzalez
parent 7c5c77d53b
commit ad68d6860e
2 changed files with 7 additions and 13 deletions

View file

@ -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<RealtimeFeedbackSwipeShortcut>(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<void(qreal)> 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<void(qreal)> 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<void(qreal)> 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<void(qreal)> progressCallback)

View file

@ -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<GlobalShortcut> m_shortcuts;