Skip to content

Commit

Permalink
Fix #502: Add a "cyclic" option to CHANGE_DESKTOP
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseExposito committed Jun 13, 2021
1 parent fdd01d1 commit fc1cba6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/actions/change-desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/actions/change-desktop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/window-system/window-system.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions src/window-system/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/window-system/x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit fc1cba6

Please sign in to comment.