mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-22 22:25:58 +01:00
optimize m+- and e+- workspace opts
This commit is contained in:
parent
6259202c01
commit
0803febac5
1 changed files with 28 additions and 40 deletions
|
@ -277,51 +277,39 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
|
||||||
|
|
||||||
// result now has +/- what we should move on mon
|
// result now has +/- what we should move on mon
|
||||||
int remains = (int)result;
|
int remains = (int)result;
|
||||||
int currentID = g_pCompositor->m_pLastMonitor->activeWorkspace;
|
|
||||||
int searchID = currentID;
|
|
||||||
|
|
||||||
while (remains != 0) {
|
std::vector<int> validWSes;
|
||||||
if (remains < 0)
|
for (auto& ws : g_pCompositor->m_vWorkspaces) {
|
||||||
searchID--;
|
if (ws->m_bIsSpecialWorkspace || (ws->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID && !onAllMonitors))
|
||||||
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_vWorkspaces) {
|
|
||||||
if (g_pCompositor->isWorkspaceSpecial(w->m_iID))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (w->m_iID < lowestID)
|
validWSes.push_back(ws->m_iID);
|
||||||
lowestID = w->m_iID;
|
|
||||||
|
|
||||||
if (w->m_iID > highestID)
|
|
||||||
highestID = w->m_iID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (remains < 0)
|
// get the offset
|
||||||
searchID = highestID;
|
remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size();
|
||||||
else
|
|
||||||
searchID = lowestID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE && !PWORKSPACE->m_bIsSpecialWorkspace) {
|
// get the current item
|
||||||
if (onAllMonitors || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) {
|
int currentItem = -1;
|
||||||
currentID = PWORKSPACE->m_iID;
|
for (size_t i = 0; i < validWSes.size(); i++) {
|
||||||
|
if (validWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) {
|
||||||
if (remains < 0)
|
currentItem = i;
|
||||||
remains++;
|
break;
|
||||||
else
|
|
||||||
remains--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result = currentID;
|
// apply
|
||||||
outName = g_pCompositor->getWorkspaceByID(currentID)->m_szName;
|
currentItem += remains;
|
||||||
|
|
||||||
|
// sanitize
|
||||||
|
if (currentItem >= (int)validWSes.size()) {
|
||||||
|
currentItem = currentItem % validWSes.size();
|
||||||
|
} else if (currentItem < 0) {
|
||||||
|
currentItem = validWSes.size() + currentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = validWSes[currentItem];
|
||||||
|
outName = g_pCompositor->getWorkspaceByID(validWSes[currentItem])->m_szName;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (in[0] == '+' || in[0] == '-') {
|
if (in[0] == '+' || in[0] == '-') {
|
||||||
|
|
Loading…
Reference in a new issue