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
master
Joshua Goins 11 months ago committed by Vlad Zahorodnii
parent be88c8ec49
commit e398289287

@ -795,18 +795,14 @@ void VirtualDesktopManager::initShortcuts()
{ {
initSwitchToShortcuts(); initSwitchToShortcuts();
addAction(QStringLiteral("Switch to Next Desktop"), i18n("Switch to Next Desktop"), &VirtualDesktopManager::slotNext); 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"), &VirtualDesktopManager::slotPrevious); addAction(QStringLiteral("Switch to Previous Desktop"), i18n("Switch to Previous Desktop"), QKeySequence(), &VirtualDesktopManager::slotPrevious);
// shortcuts // shortcuts
QAction *slotRightAction = addAction(QStringLiteral("Switch One Desktop to the Right"), i18n("Switch One Desktop to the Right"), &VirtualDesktopManager::slotRight); 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);
KGlobalAccel::setGlobalShortcut(slotRightAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Right)); 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);
QAction *slotLeftAction = addAction(QStringLiteral("Switch One Desktop to the Left"), i18n("Switch One Desktop to the Left"), &VirtualDesktopManager::slotLeft); addAction(QStringLiteral("Switch One Desktop Up"), i18n("Switch One Desktop Up"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Up), &VirtualDesktopManager::slotUp);
KGlobalAccel::setGlobalShortcut(slotLeftAction, QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Left)); addAction(QStringLiteral("Switch One Desktop Down"), i18n("Switch One Desktop Down"), QKeySequence(Qt::CTRL | Qt::META | Qt::Key_Down), &VirtualDesktopManager::slotDown);
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));
// Gestures // Gestures
// These connections decide which desktop to end on after gesture ends // 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; 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); QAction *a = new QAction(this);
a->setProperty("componentName", QStringLiteral("kwin")); a->setProperty("componentName", QStringLiteral("kwin"));
a->setObjectName(name); a->setObjectName(name);
a->setText(label); a->setText(label);
KGlobalAccel::setGlobalShortcut(a, QKeySequence()); KGlobalAccel::setGlobalShortcut(a, key);
connect(a, &QAction::triggered, this, slot); connect(a, &QAction::triggered, this, slot);
return a; return a;
} }

@ -471,13 +471,13 @@ private:
QAction *addAction(const QString &name, const KLocalizedString &label, uint value, const QKeySequence &key, void (VirtualDesktopManager::*slot)()); 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. * 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 * Overloaded method for the case that no additional value needs to be passed to the action.
* no global shortcut is defined by default.
* @param name The name of the action to be created * @param name The name of the action to be created
* @param label The localized name for 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 * @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<VirtualDesktop *> m_desktops; QVector<VirtualDesktop *> m_desktops;
QPointer<VirtualDesktop> m_current; QPointer<VirtualDesktop> m_current;

Loading…
Cancel
Save