diff --git a/containmentactions/switchdesktop/CMakeLists.txt b/containmentactions/switchdesktop/CMakeLists.txt
--- a/containmentactions/switchdesktop/CMakeLists.txt
+++ b/containmentactions/switchdesktop/CMakeLists.txt
@@ -1,6 +1,9 @@
+add_definitions(-DTRANSLATION_DOMAIN=\"plasma_containmentactions_switchdesktop\")
+
set(switchdesktop_SRCS
desktop.cpp
)
+ki18n_wrap_ui(switchdesktop_SRCS config.ui)
add_library(plasma_containmentactions_switchdesktop MODULE ${switchdesktop_SRCS})
diff --git a/containmentactions/switchdesktop/config.ui b/containmentactions/switchdesktop/config.ui
new file mode 100644
--- /dev/null
+++ b/containmentactions/switchdesktop/config.ui
@@ -0,0 +1,25 @@
+
+
+ Config
+
+
+
+ 0
+ 0
+ 397
+ 123
+
+
+
+ -
+
+
+ Enable virtual desktop navigation wrapping
+
+
+
+
+
+
+
+
diff --git a/containmentactions/switchdesktop/desktop.h b/containmentactions/switchdesktop/desktop.h
--- a/containmentactions/switchdesktop/desktop.h
+++ b/containmentactions/switchdesktop/desktop.h
@@ -22,6 +22,8 @@
#include
+#include "ui_config.h"
+
class QAction;
class SwitchDesktop : public Plasma::ContainmentActions
@@ -36,11 +38,20 @@
void performNextAction() override;
void performPreviousAction() override;
+ void init(const KConfigGroup &config);
+ QWidget *createConfigurationInterface(QWidget* parent) override;
+ void configurationAccepted() override;
+ void restore(const KConfigGroup &config) override;
+ void save(KConfigGroup &config) override;
+
private Q_SLOTS:
void switchTo();
private:
QHash m_actions;
+
+ Ui::Config m_ui;
+ bool m_wrapDesktop = false;
};
diff --git a/containmentactions/switchdesktop/desktop.cpp b/containmentactions/switchdesktop/desktop.cpp
--- a/containmentactions/switchdesktop/desktop.cpp
+++ b/containmentactions/switchdesktop/desktop.cpp
@@ -18,6 +18,7 @@
*/
#include "desktop.h"
+#include "algorithm"
#include
#include
@@ -85,14 +86,44 @@
{
const int numDesktops = KWindowSystem::numberOfDesktops();
const int currentDesktop = KWindowSystem::currentDesktop();
- KWindowSystem::setCurrentDesktop(currentDesktop % numDesktops + 1);
+ int nextDesktop = m_wrapDesktop ?
+ currentDesktop % numDesktops + 1 : std::min(currentDesktop + 1, numDesktops);
+ KWindowSystem::setCurrentDesktop(nextDesktop);
}
void SwitchDesktop::performPreviousAction()
{
const int numDesktops = KWindowSystem::numberOfDesktops();
const int currentDesktop = KWindowSystem::currentDesktop();
- KWindowSystem::setCurrentDesktop((numDesktops + currentDesktop - 2) % numDesktops + 1);
+ int previousDesktop = m_wrapDesktop ?
+ (numDesktops + currentDesktop - 2) % numDesktops + 1 : std::max(currentDesktop - 1, 1);
+ KWindowSystem::setCurrentDesktop(previousDesktop);
+}
+
+void SwitchDesktop::init(const KConfigGroup &config) {
+
+}
+
+QWidget *SwitchDesktop::createConfigurationInterface(QWidget *parent) {
+ QWidget *widget = new QWidget(parent);
+ m_ui.setupUi(widget);
+ widget->setWindowTitle(i18nc("plasma_containmentactions_switchdesktop", "Configure Switch Desktop Plugin"));
+
+ m_ui.wrapDesktop->setChecked(m_wrapDesktop);
+
+ return widget;
+}
+
+void SwitchDesktop::configurationAccepted() {
+ m_wrapDesktop = m_ui.wrapDesktop->isChecked();
+}
+
+void SwitchDesktop::restore(const KConfigGroup &config) {
+ m_wrapDesktop = config.readEntry(QStringLiteral("wrapDesktop"), false);
+}
+
+void SwitchDesktop::save(KConfigGroup &config) {
+ config.writeEntry(QStringLiteral("wrapDesktop"), m_wrapDesktop);
}
K_EXPORT_PLASMA_CONTAINMENTACTIONS_WITH_JSON(switchdesktop, SwitchDesktop, "plasma-containmentactions-switchdesktop.json")
diff --git a/containmentactions/switchdesktop/plasma-containmentactions-switchdesktop.desktop b/containmentactions/switchdesktop/plasma-containmentactions-switchdesktop.desktop
--- a/containmentactions/switchdesktop/plasma-containmentactions-switchdesktop.desktop
+++ b/containmentactions/switchdesktop/plasma-containmentactions-switchdesktop.desktop
@@ -146,3 +146,4 @@
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
+X-Plasma-HasConfigurationInterface=true