Skip to content

Commit

Permalink
Add option for animating workspaces as an infinite band
Browse files Browse the repository at this point in the history
  • Loading branch information
pdamianik committed Feb 18, 2024
1 parent 5fc0b77 commit 9108b44
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("binds:workspace_back_and_forth", {0L});
m_pConfig->addConfigValue("binds:allow_workspace_cycles", {0L});
m_pConfig->addConfigValue("binds:workspace_center_on", {1L});
m_pConfig->addConfigValue("binds:animate_workspace_band", {0L});
m_pConfig->addConfigValue("binds:focus_preferred_method", {0L});
m_pConfig->addConfigValue("binds:ignore_group_lock", {0L});
m_pConfig->addConfigValue("binds:movefocus_cycles_fullscreen", {1L});
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/MiscFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
return result;
}

std::optional<bool> isWorkspaceChangeDirectionLeft(const std::string& args) {
if ((args[0] == '-' || args[0] == '+') && isNumber(args.substr(1)))
return args[0] == '+';
else if ((args[0] == 'r' || args[0] == 'm' || args[0] == 'e') && (args[1] == '-' || args[1] == '+') && isNumber(args.substr(2)))
return args[1] == '+';
else
return {};
}

std::optional<std::string> cleanCmdForWorkspace(const std::string& inWorkspaceName, std::string dirtyCmd) {

std::string cmd = removeBeginEndSpacesTabs(dirtyCmd);
Expand Down
1 change: 1 addition & 0 deletions src/helpers/MiscFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool isNumber(const std::string&, bool allowfloat =
bool isDirection(const std::string&);
bool isDirection(const char&);
int getWorkspaceIDFromString(const std::string&, std::string&);
std::optional<bool> isWorkspaceChangeDirectionLeft(const std::string&);
std::optional<std::string> cleanCmdForWorkspace(const std::string&, std::string);
float vecToRectDistanceSquared(const Vector2D& vec, const Vector2D& p1, const Vector2D& p2);
void logSystemInfo();
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ float CMonitor::getDefaultScale() {
return 1;
}

void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool noMouseMove, bool noFocus) {
void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool noMouseMove, bool noFocus, std::optional<bool> animateLeftOverride) {
if (!pWorkspace)
return;

Expand All @@ -529,7 +529,7 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool
activeWorkspace = pWorkspace->m_iID;

if (!internal) {
const auto ANIMTOLEFT = pWorkspace->m_iID > POLDWORKSPACE->m_iID;
const auto ANIMTOLEFT = animateLeftOverride.value_or(pWorkspace->m_iID > POLDWORKSPACE->m_iID);
POLDWORKSPACE->startAnim(false, ANIMTOLEFT);
pWorkspace->startAnim(true, ANIMTOLEFT);

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class CMonitor {
void setMirror(const std::string&);
bool isMirror();
float getDefaultScale();
void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false);
void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false, std::optional<bool> animateLeftOverride = {});
void changeWorkspace(const int& id, bool internal = false, bool noMouseMove = false, bool noFocus = false);
void setSpecialWorkspace(CWorkspace* const pWorkspace);
void setSpecialWorkspace(const int& id);
Expand Down
8 changes: 7 additions & 1 deletion src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ void CKeybindManager::changeworkspace(std::string args) {
static auto* const PBACKANDFORTH = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth");
static auto* const PALLOWWORKSPACECYCLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles");
static auto* const PWORKSPACECENTERON = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:workspace_center_on");
static auto* const PANIMATEWORKSPACEBAND = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:animate_workspace_band");

const auto PMONITOR = g_pCompositor->m_pLastMonitor;

Expand Down Expand Up @@ -934,7 +935,12 @@ void CKeybindManager::changeworkspace(std::string args) {

g_pCompositor->setActiveMonitor(PMONITORWORKSPACEOWNER);

PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo, false, true);
if (**PANIMATEWORKSPACEBAND) {
const auto ANIMATELEFT = isWorkspaceChangeDirectionLeft(args);
PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo, false, true, false, ANIMATELEFT);
} else {
PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo, false, true);
}

if (PMONITOR != PMONITORWORKSPACEOWNER) {
Vector2D middle = PMONITORWORKSPACEOWNER->middle();
Expand Down

0 comments on commit 9108b44

Please sign in to comment.