From e398289287d3e25ec48111c4f2a2b9d2a1195c00 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Tue, 17 Oct 2023 14:49:49 -0400 Subject: [PATCH] Add QKeySequence to VirtualDesktopManager::addAction overload There are four usages of this overload, two of them are for the intentionally disabled "Switch to Next/Previous Desktop" actions and the rest are for "Switch One Desktop to X" actions. Due to the order they were added, an empty keybind was set as the default and the actual keybind is never enabled. Now there's a QKeySequence argument to this overload, so an unexpected empty keybind is never added. The two usages of addAction that depend on this empty keybind behavior now pass in an empty QKeySequence. BUG: 475748 --- src/virtualdesktops.cpp | 20 ++++++++------------ src/virtualdesktops.h | 6 +++--- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/virtualdesktops.cpp b/src/virtualdesktops.cpp index bc666c01b8..7f64e3d9b7 100644 --- a/src/virtualdesktops.cpp +++ b/src/virtualdesktops.cpp @@ -795,18 +795,14 @@ void VirtualDesktopManager::initShortcuts() { initSwitchToShortcuts(); - addAction(QStringLiteral("Switch to Next Desktop"), i18n("Switch to Next Desktop"), &VirtualDesktopManager::slotNext); - addAction(QStringLiteral("Switch to Previous Desktop"), i18n("Switch to Previous Desktop"), &VirtualDesktopManager::slotPrevious); + addAction(QStringLiteral("Switch to Next Desktop"), i18n("Switch to Next Desktop"), QKeySequence(), &VirtualDesktopManager::slotNext); + addAction(QStringLiteral("Switch to Previous Desktop"), i18n("Switch to Previous Desktop"), QKeySequence(), &VirtualDesktopManager::slotPrevious); // shortcuts - QAction *slotRightAction = addAction(QStringLiteral("Switch One Desktop to the Right"), i18n("Switch One Desktop to the Right"), &VirtualDesktopManager::slotRight); - KGlobalAccel::setGlobalShortcut(slotRightAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Right)); - QAction *slotLeftAction = addAction(QStringLiteral("Switch One Desktop to the Left"), i18n("Switch One Desktop to the Left"), &VirtualDesktopManager::slotLeft); - KGlobalAccel::setGlobalShortcut(slotLeftAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Left)); - QAction *slotUpAction = addAction(QStringLiteral("Switch One Desktop Up"), i18n("Switch One Desktop Up"), &VirtualDesktopManager::slotUp); - KGlobalAccel::setGlobalShortcut(slotUpAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Up)); - QAction *slotDownAction = addAction(QStringLiteral("Switch One Desktop Down"), i18n("Switch One Desktop Down"), &VirtualDesktopManager::slotDown); - KGlobalAccel::setGlobalShortcut(slotDownAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Down)); + addAction(QStringLiteral("Switch One Desktop to the Right"), i18n("Switch One Desktop to the Right"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Right), &VirtualDesktopManager::slotRight); + addAction(QStringLiteral("Switch One Desktop to the Left"), i18n("Switch One Desktop to the Left"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Left), &VirtualDesktopManager::slotLeft); + addAction(QStringLiteral("Switch One Desktop Up"), i18n("Switch One Desktop Up"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Up), &VirtualDesktopManager::slotUp); + addAction(QStringLiteral("Switch One Desktop Down"), i18n("Switch One Desktop Down"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Down), &VirtualDesktopManager::slotDown); // Gestures // These connections decide which desktop to end on after gesture ends @@ -917,13 +913,13 @@ QAction *VirtualDesktopManager::addAction(const QString &name, const KLocalizedS return a; } -QAction *VirtualDesktopManager::addAction(const QString &name, const QString &label, void (VirtualDesktopManager::*slot)()) +QAction *VirtualDesktopManager::addAction(const QString &name, const QString &label, const QKeySequence &key, void (VirtualDesktopManager::*slot)()) { QAction *a = new QAction(this); a->setProperty("componentName", QStringLiteral("kwin")); a->setObjectName(name); a->setText(label); - KGlobalAccel::setGlobalShortcut(a, QKeySequence()); + KGlobalAccel::setGlobalShortcut(a, key); connect(a, &QAction::triggered, this, slot); return a; } diff --git a/src/virtualdesktops.h b/src/virtualdesktops.h index 645c6c6f6d..dc3df6832b 100644 --- a/src/virtualdesktops.h +++ b/src/virtualdesktops.h @@ -471,13 +471,13 @@ private: QAction *addAction(const QString &name, const KLocalizedString &label, uint value, const QKeySequence &key, void (VirtualDesktopManager::*slot)()); /** * Creates an action and connects it to the @p slot in this Manager. - * Overloaded method for the case that no additional value needs to be passed to the action and - * no global shortcut is defined by default. + * Overloaded method for the case that no additional value needs to be passed to the action. * @param name The name of the action to be created * @param label The localized name for the action to be created + * @param key The global shortcut for the action. If an empty QKeySequence is passed, no global shortcut is defined by default. * @param slot The slot to invoke when the action is triggered */ - QAction *addAction(const QString &name, const QString &label, void (VirtualDesktopManager::*slot)()); + QAction *addAction(const QString &name, const QString &label, const QKeySequence &key, void (VirtualDesktopManager::*slot)()); QVector m_desktops; QPointer m_current;