From fc1cba63ad59606d9bdd6f07f84a9428de857634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Sun, 13 Jun 2021 17:08:52 +0200 Subject: [PATCH] Fix #502: Add a "cyclic" option to CHANGE_DESKTOP --- src/actions/change-desktop.cpp | 6 +++++- src/actions/change-desktop.h | 1 + src/window-system/window-system.h | 2 +- src/window-system/x11.cpp | 10 +++++++--- src/window-system/x11.h | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/actions/change-desktop.cpp b/src/actions/change-desktop.cpp index be9fc110..e84aa8a6 100644 --- a/src/actions/change-desktop.cpp +++ b/src/actions/change-desktop.cpp @@ -27,6 +27,10 @@ void ChangeDesktop::onGestureBegin(const Gesture& gesture) { this->direction = actionDirectionFromStr(this->settings.at("direction")); } + if (this->settings.count("cyclic") == 1) { + this->cyclic = (this->settings.at("cyclic") == "true"); + } + if (this->animate) { ActionDirection animationPosition = ActionDirection::UNKNOWN; @@ -67,7 +71,7 @@ void ChangeDesktop::executeAction(const Gesture& gesture) { ActionDirection actionDirection = (this->direction == ActionDirection::AUTO) ? this->getActionAutoDirection(gesture) : this->direction; - this->windowSystem.changeDesktop(actionDirection); + this->windowSystem.changeDesktop(actionDirection, this->cyclic); } ActionDirection ChangeDesktop::getAnimationAutoDirection( diff --git a/src/actions/change-desktop.h b/src/actions/change-desktop.h index af0e2339..52e729e7 100644 --- a/src/actions/change-desktop.h +++ b/src/actions/change-desktop.h @@ -33,6 +33,7 @@ class ChangeDesktop : public AnimatedAction { private: ActionDirection direction = ActionDirection::AUTO; + bool cyclic = false; ActionDirection getAnimationAutoDirection(const Gesture &gesture) const; ActionDirection getActionAutoDirection(const Gesture &gesture) const; diff --git a/src/window-system/window-system.h b/src/window-system/window-system.h index 2fa03da5..557a16f1 100644 --- a/src/window-system/window-system.h +++ b/src/window-system/window-system.h @@ -145,7 +145,7 @@ class WindowSystem { /** * Changes to the next/previous desktop. */ - virtual void changeDesktop(ActionDirection direction) const = 0; + virtual void changeDesktop(ActionDirection direction, bool cyclic) const = 0; /** * Show the desktop. diff --git a/src/window-system/x11.cpp b/src/window-system/x11.cpp index 0527e0c0..f638d92a 100644 --- a/src/window-system/x11.cpp +++ b/src/window-system/x11.cpp @@ -584,7 +584,7 @@ Rectangle X11::getDesktopWorkarea() const { return workarea; } -void X11::changeDesktop(ActionDirection direction) const { +void X11::changeDesktop(ActionDirection direction, bool cyclic) const { Window rootWindow = XDefaultRootWindow(this->display); // NOLINTNEXTLINE @@ -611,11 +611,15 @@ void X11::changeDesktop(ActionDirection direction) const { this->destinationDesktop(currentDesktop, totalDesktops, direction); break; case ActionDirection::NEXT: - toDesktop = std::min(totalDesktops - 1, currentDesktop + 1); + toDesktop = cyclic ? (currentDesktop + 1) % totalDesktops + : std::min(totalDesktops - 1, currentDesktop + 1); break; case ActionDirection::PREVIOUS: default: - toDesktop = std::max(0, currentDesktop - 1); + int prev = currentDesktop - 1; + toDesktop = cyclic + ? (prev % totalDesktops + totalDesktops) % totalDesktops + : std::max(0, prev); break; } diff --git a/src/window-system/x11.h b/src/window-system/x11.h index 43919cfa..5e987ef8 100644 --- a/src/window-system/x11.h +++ b/src/window-system/x11.h @@ -67,7 +67,7 @@ class X11 : public WindowSystem { void sendMouseClick(int button) const override; Rectangle getDesktopWorkarea() const override; - void changeDesktop(ActionDirection direction) const override; + void changeDesktop(ActionDirection direction, bool cyclic) const override; void showDesktop(bool show) const override; bool isShowingDesktop() const override;