mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 12:25:58 +01:00
config: add absolute monitor workspace selectors (#5848)
* add absolute monitor workspace selectors * implement absolute for `r` * format code
This commit is contained in:
parent
1c73beaf9b
commit
1d2acbe193
1 changed files with 135 additions and 100 deletions
|
@ -305,13 +305,14 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
outName = PLASTWORKSPACE->m_szName;
|
outName = PLASTWORKSPACE->m_szName;
|
||||||
return PLASTWORKSPACE->m_iID;
|
return PLASTWORKSPACE->m_iID;
|
||||||
} else {
|
} else {
|
||||||
if (in[0] == 'r' && (in[1] == '-' || in[1] == '+') && isNumber(in.substr(2))) {
|
if (in[0] == 'r' && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) {
|
||||||
|
bool absolute = in[1] == '~';
|
||||||
if (!g_pCompositor->m_pLastMonitor) {
|
if (!g_pCompositor->m_pLastMonitor) {
|
||||||
Debug::log(ERR, "Relative monitor workspace on monitor null!");
|
Debug::log(ERR, "Relative monitor workspace on monitor null!");
|
||||||
return WORKSPACE_INVALID;
|
return WORKSPACE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(1), 0);
|
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0);
|
||||||
|
|
||||||
if (!PLUSMINUSRESULT.has_value())
|
if (!PLUSMINUSRESULT.has_value())
|
||||||
return WORKSPACE_INVALID;
|
return WORKSPACE_INVALID;
|
||||||
|
@ -349,6 +350,25 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
}
|
}
|
||||||
std::sort(namedWSes.begin(), namedWSes.end());
|
std::sort(namedWSes.begin(), namedWSes.end());
|
||||||
|
|
||||||
|
if (absolute) {
|
||||||
|
// 1-index
|
||||||
|
remains -= 1;
|
||||||
|
|
||||||
|
// traverse valid workspaces until we reach the remains
|
||||||
|
if ((size_t)remains < namedWSes.size()) {
|
||||||
|
result = namedWSes[remains];
|
||||||
|
} else {
|
||||||
|
remains -= namedWSes.size();
|
||||||
|
result = 0;
|
||||||
|
while (remains >= 0) {
|
||||||
|
result++;
|
||||||
|
if (!invalidWSes.contains(result)) {
|
||||||
|
remains--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
// Just take a blind guess at where we'll probably end up
|
// Just take a blind guess at where we'll probably end up
|
||||||
int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1;
|
int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1;
|
||||||
int predictedWSID = activeWSID + remains;
|
int predictedWSID = activeWSID + remains;
|
||||||
|
@ -436,16 +456,18 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
finalWSID = curID;
|
finalWSID = curID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = finalWSID;
|
result = finalWSID;
|
||||||
|
}
|
||||||
|
|
||||||
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(result);
|
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(result);
|
||||||
if (PWORKSPACE)
|
if (PWORKSPACE)
|
||||||
outName = g_pCompositor->getWorkspaceByID(result)->m_szName;
|
outName = g_pCompositor->getWorkspaceByID(result)->m_szName;
|
||||||
else
|
else
|
||||||
outName = std::to_string(finalWSID);
|
outName = std::to_string(result);
|
||||||
|
|
||||||
} else if ((in[0] == 'm' || in[0] == 'e') && (in[1] == '-' || in[1] == '+') && isNumber(in.substr(2))) {
|
} else if ((in[0] == 'm' || in[0] == 'e') && (in[1] == '-' || in[1] == '+' || in[1] == '~') && isNumber(in.substr(2))) {
|
||||||
bool onAllMonitors = in[0] == 'e';
|
bool onAllMonitors = in[0] == 'e';
|
||||||
|
bool absolute = in[1] == '~';
|
||||||
|
|
||||||
if (!g_pCompositor->m_pLastMonitor) {
|
if (!g_pCompositor->m_pLastMonitor) {
|
||||||
Debug::log(ERR, "Relative monitor workspace on monitor null!");
|
Debug::log(ERR, "Relative monitor workspace on monitor null!");
|
||||||
|
@ -453,7 +475,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// monitor relative
|
// monitor relative
|
||||||
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(1), 0);
|
const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in.substr(absolute ? 2 : 1), 0);
|
||||||
|
|
||||||
if (!PLUSMINUSRESULT.has_value())
|
if (!PLUSMINUSRESULT.has_value())
|
||||||
return WORKSPACE_INVALID;
|
return WORKSPACE_INVALID;
|
||||||
|
@ -473,12 +495,24 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
|
|
||||||
std::sort(validWSes.begin(), validWSes.end());
|
std::sort(validWSes.begin(), validWSes.end());
|
||||||
|
|
||||||
|
int currentItem = -1;
|
||||||
|
|
||||||
|
if (absolute) {
|
||||||
|
// 1-index
|
||||||
|
currentItem = remains - 1;
|
||||||
|
|
||||||
|
// clamp
|
||||||
|
if (currentItem < 0) {
|
||||||
|
currentItem = 0;
|
||||||
|
} else if (currentItem >= (int)validWSes.size()) {
|
||||||
|
currentItem = validWSes.size() - 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
// get the offset
|
// get the offset
|
||||||
remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size();
|
remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size();
|
||||||
|
|
||||||
// get the current item
|
// get the current item
|
||||||
int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1;
|
int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1;
|
||||||
int currentItem = -1;
|
|
||||||
for (size_t i = 0; i < validWSes.size(); i++) {
|
for (size_t i = 0; i < validWSes.size(); i++) {
|
||||||
if (validWSes[i] == activeWSID) {
|
if (validWSes[i] == activeWSID) {
|
||||||
currentItem = i;
|
currentItem = i;
|
||||||
|
@ -495,6 +529,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
} else if (currentItem < 0) {
|
} else if (currentItem < 0) {
|
||||||
currentItem = validWSes.size() + currentItem;
|
currentItem = validWSes.size() + currentItem;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = validWSes[currentItem];
|
result = validWSes[currentItem];
|
||||||
outName = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_szName;
|
outName = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_szName;
|
||||||
|
|
Loading…
Reference in a new issue