mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 10:05:59 +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
|
continue;
|
||||||
searchID++;
|
|
||||||
|
|
||||||
if (g_pCompositor->workspaceIDOutOfBounds(searchID)){
|
validWSes.push_back(ws->m_iID);
|
||||||
// means we need to wrap around
|
}
|
||||||
int lowestID = 99999;
|
|
||||||
int highestID = -99999;
|
|
||||||
|
|
||||||
for (auto& w : g_pCompositor->m_vWorkspaces) {
|
// get the offset
|
||||||
if (g_pCompositor->isWorkspaceSpecial(w->m_iID))
|
remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size();
|
||||||
continue;
|
|
||||||
|
|
||||||
if (w->m_iID < lowestID)
|
// get the current item
|
||||||
lowestID = w->m_iID;
|
int currentItem = -1;
|
||||||
|
for (size_t i = 0; i < validWSes.size(); i++) {
|
||||||
if (w->m_iID > highestID)
|
if (validWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) {
|
||||||
highestID = w->m_iID;
|
currentItem = i;
|
||||||
}
|
break;
|
||||||
|
|
||||||
if (remains < 0)
|
|
||||||
searchID = highestID;
|
|
||||||
else
|
|
||||||
searchID = lowestID;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(searchID); PWORKSPACE && !PWORKSPACE->m_bIsSpecialWorkspace) {
|
|
||||||
if (onAllMonitors || PWORKSPACE->m_iMonitorID == g_pCompositor->m_pLastMonitor->ID) {
|
|
||||||
currentID = PWORKSPACE->m_iID;
|
|
||||||
|
|
||||||
if (remains < 0)
|
|
||||||
remains++;
|
|
||||||
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