Add default shortcuts for virtual desktop switching actions

This makes the virtual desktop KCM properly show Ctrl+F1-F4 as the
default shortcuts for switch to desktop.

REVIEW: 119051
This commit is contained in:
Martin Gräßlin 2014-07-01 08:09:27 +02:00
parent ce48a1b27b
commit 8bdbe4dc15
2 changed files with 18 additions and 5 deletions

View file

@ -116,11 +116,24 @@ void KWinDesktopConfig::init()
n = info.numberOfDesktops(); n = info.numberOfDesktops();
} }
for (int i = 1; i <= n; ++i) { auto addSwitchTo = [this](int i, const QKeySequence &sequence) {
QAction* a = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(i)); QAction* a = m_actionCollection->addAction(QString("Switch to Desktop %1").arg(i));
a->setProperty("isConfigurationAction", true); a->setProperty("isConfigurationAction", true);
a->setText(i18n("Switch to Desktop %1", i)); a->setText(i18n("Switch to Desktop %1", i));
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>()); KGlobalAccel::setGlobalShortcut(a, sequence);
};
if (n >= 2) {
addSwitchTo(1, Qt::CTRL + Qt::Key_F1);
addSwitchTo(2, Qt::CTRL + Qt::Key_F2);
}
if (n >= 3) {
addSwitchTo(3, Qt::CTRL + Qt::Key_F3);
}
if (n >= 4) {
addSwitchTo(4, Qt::CTRL + Qt::Key_F4);
}
for (int i = 5; i <= n; ++i) {
addSwitchTo(i, QKeySequence());
} }
// This should be after the "Switch to Desktop %1" loop. It HAS to be // This should be after the "Switch to Desktop %1" loop. It HAS to be
@ -201,7 +214,7 @@ void KWinDesktopConfig::addAction(const QString &name, const QString &label)
QAction* a = m_switchDesktopCollection->addAction(name); QAction* a = m_switchDesktopCollection->addAction(name);
a->setProperty("isConfigurationAction", true); a->setProperty("isConfigurationAction", true);
a->setText(label); a->setText(label);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>()); KGlobalAccel::setGlobalShortcut(a, QKeySequence());
} }
void KWinDesktopConfig::defaults() void KWinDesktopConfig::defaults()

View file

@ -459,7 +459,7 @@ void VirtualDesktopManager::addAction(const QString &name, const KLocalizedStrin
a->setText(label.subs(value).toString()); a->setText(label.subs(value).toString());
a->setData(value); a->setData(value);
connect(a, &QAction::triggered, this, slot); connect(a, &QAction::triggered, this, slot);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << key); KGlobalAccel::setGlobalShortcut(a, key);
input()->registerShortcut(key, a); input()->registerShortcut(key, a);
} }
@ -469,7 +469,7 @@ void VirtualDesktopManager::addAction(const QString &name, const QString &label,
a->setObjectName(name); a->setObjectName(name);
a->setText(label); a->setText(label);
connect(a, &QAction::triggered, this, slot); connect(a, &QAction::triggered, this, slot);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>()); KGlobalAccel::setGlobalShortcut(a, QKeySequence());
input()->registerShortcut(QKeySequence(), a); input()->registerShortcut(QKeySequence(), a);
} }