Added relative monitor workspace offset

This commit is contained in:
vaxerski 2022-05-31 12:33:08 +02:00
parent 68f7e565e6
commit df722cbb86
3 changed files with 69 additions and 2 deletions

View file

@ -1021,4 +1021,19 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, SMonitor* pMoni
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
g_pInputManager->refocus(); g_pInputManager->refocus();
}
bool CCompositor::workspaceIDOutOfBounds(const int& id) {
int lowestID = 99999;
int highestID = -99999;
for (auto& w : m_lWorkspaces) {
if (w.m_iID < lowestID)
lowestID = w.m_iID;
if (w.m_iID > highestID)
highestID = w.m_iID;
}
return std::clamp(id, lowestID, highestID) != id;
} }

View file

@ -129,6 +129,7 @@ public:
void moveWindowToWorkspace(CWindow*, const std::string&); void moveWindowToWorkspace(CWindow*, const std::string&);
int getNextAvailableMonitorID(); int getNextAvailableMonitorID();
void moveWorkspaceToMonitor(CWorkspace*, SMonitor*); void moveWorkspaceToMonitor(CWorkspace*, SMonitor*);
bool workspaceIDOutOfBounds(const int&);
private: private:
void initAllSignals(); void initAllSignals();

View file

@ -135,8 +135,59 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
} }
outName = WORKSPACENAME; outName = WORKSPACENAME;
} else { } else {
result = std::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX); if (in[0] == 'm') {
outName = std::to_string(result); // monitor relative
result = (int)getPlusMinusKeywordResult(in.substr(1), 0);
// result now has +/- what we should move on mon
int remains = (int)result;
int currentID = g_pCompositor->m_pLastMonitor->activeWorkspace;
int searchID = currentID;
while (remains != 0) {
if (remains < 0)
searchID--;
else
searchID++;
if (g_pCompositor->workspaceIDOutOfBounds(searchID)){
// means we need to wrap around
int lowestID = 99999;
int highestID = -99999;
for (auto& w : g_pCompositor->m_lWorkspaces) {
if (w.m_iID < lowestID)
lowestID = w.m_iID;
if (w.m_iID > highestID)
highestID = w.m_iID;
}
if (remains < 0)
searchID = highestID;
else
searchID = lowestID;
}
if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE) {
if (PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) {
currentID = PWORKSPACE->m_iID;
if (remains < 0)
remains++;
else
remains--;
}
}
}
result = currentID;
outName = g_pCompositor->getWorkspaceByID(currentID)->m_szName;
} else {
result = std::clamp((int)getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX);
outName = std::to_string(result);
}
} }
return result; return result;