From 8bdbe4dc159075859e268f6eaa170db686436155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 1 Jul 2014 08:09:27 +0200 Subject: [PATCH] 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 --- kcmkwin/kwindesktop/main.cpp | 19 ++++++++++++++++--- virtualdesktops.cpp | 4 ++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/kcmkwin/kwindesktop/main.cpp b/kcmkwin/kwindesktop/main.cpp index 936dad1b06..68cbca3df2 100644 --- a/kcmkwin/kwindesktop/main.cpp +++ b/kcmkwin/kwindesktop/main.cpp @@ -116,11 +116,24 @@ void KWinDesktopConfig::init() 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)); a->setProperty("isConfigurationAction", true); a->setText(i18n("Switch to Desktop %1", i)); - KGlobalAccel::self()->setShortcut(a, QList()); + 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 @@ -201,7 +214,7 @@ void KWinDesktopConfig::addAction(const QString &name, const QString &label) QAction* a = m_switchDesktopCollection->addAction(name); a->setProperty("isConfigurationAction", true); a->setText(label); - KGlobalAccel::self()->setShortcut(a, QList()); + KGlobalAccel::setGlobalShortcut(a, QKeySequence()); } void KWinDesktopConfig::defaults() diff --git a/virtualdesktops.cpp b/virtualdesktops.cpp index 30a5e2e553..7055c0fb4e 100644 --- a/virtualdesktops.cpp +++ b/virtualdesktops.cpp @@ -459,7 +459,7 @@ void VirtualDesktopManager::addAction(const QString &name, const KLocalizedStrin a->setText(label.subs(value).toString()); a->setData(value); connect(a, &QAction::triggered, this, slot); - KGlobalAccel::self()->setShortcut(a, QList() << key); + KGlobalAccel::setGlobalShortcut(a, key); input()->registerShortcut(key, a); } @@ -469,7 +469,7 @@ void VirtualDesktopManager::addAction(const QString &name, const QString &label, a->setObjectName(name); a->setText(label); connect(a, &QAction::triggered, this, slot); - KGlobalAccel::self()->setShortcut(a, QList()); + KGlobalAccel::setGlobalShortcut(a, QKeySequence()); input()->registerShortcut(QKeySequence(), a); }