mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-25 14:25:59 +01:00
More code deduplication in changeworkspace
This commit is contained in:
parent
47bc01bfca
commit
1b0b11e209
1 changed files with 11 additions and 50 deletions
|
@ -725,13 +725,14 @@ void CKeybindManager::changeworkspace(std::string args) {
|
||||||
|
|
||||||
const bool EXPLICITPREVIOUS = args.find("previous") == 0;
|
const bool EXPLICITPREVIOUS = args.find("previous") == 0;
|
||||||
|
|
||||||
if (args.find("previous") == 0) {
|
workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName);
|
||||||
|
if (EXPLICITPREVIOUS || (workspaceToChangeTo == PCURRENTWORKSPACE->m_iID && *PBACKANDFORTH)) {
|
||||||
// Do nothing if there's no previous workspace, otherwise switch to it.
|
// Do nothing if there's no previous workspace, otherwise switch to it.
|
||||||
if (PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1) {
|
if (PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1) {
|
||||||
Debug::log(LOG, "No previous workspace to change to");
|
Debug::log(LOG, "No previous workspace to change to");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
workspaceToChangeTo = PCURRENTWORKSPACE->m_iID;
|
workspaceToChangeTo = PCURRENTWORKSPACE->m_sPrevWorkspace.iID;
|
||||||
|
|
||||||
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_sPrevWorkspace.iID); PWORKSPACETOCHANGETO)
|
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_sPrevWorkspace.iID); PWORKSPACETOCHANGETO)
|
||||||
workspaceName = PWORKSPACETOCHANGETO->m_szName;
|
workspaceName = PWORKSPACETOCHANGETO->m_szName;
|
||||||
|
@ -739,8 +740,6 @@ void CKeybindManager::changeworkspace(std::string args) {
|
||||||
workspaceName =
|
workspaceName =
|
||||||
PCURRENTWORKSPACE->m_sPrevWorkspace.name.empty() ? std::to_string(PCURRENTWORKSPACE->m_sPrevWorkspace.iID) : PCURRENTWORKSPACE->m_sPrevWorkspace.name;
|
PCURRENTWORKSPACE->m_sPrevWorkspace.name.empty() ? std::to_string(PCURRENTWORKSPACE->m_sPrevWorkspace.iID) : PCURRENTWORKSPACE->m_sPrevWorkspace.name;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
workspaceToChangeTo = getWorkspaceIDFromString(args, workspaceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (workspaceToChangeTo == INT_MAX) {
|
if (workspaceToChangeTo == INT_MAX) {
|
||||||
|
@ -751,51 +750,6 @@ void CKeybindManager::changeworkspace(std::string args) {
|
||||||
g_pInputManager->unconstrainMouse();
|
g_pInputManager->unconstrainMouse();
|
||||||
g_pInputManager->m_bEmptyFocusCursorSet = false;
|
g_pInputManager->m_bEmptyFocusCursorSet = false;
|
||||||
|
|
||||||
if (workspaceToChangeTo == PCURRENTWORKSPACE->m_iID) {
|
|
||||||
if ((!*PBACKANDFORTH && !EXPLICITPREVIOUS) || PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_sPrevWorkspace.iID);
|
|
||||||
|
|
||||||
g_pInputManager->releaseAllMouseButtons();
|
|
||||||
|
|
||||||
if (pWorkspaceToChangeTo) {
|
|
||||||
const auto PMONITORWORKSPACEOWNER = PMONITOR->ID == pWorkspaceToChangeTo->m_iMonitorID ? PMONITOR : g_pCompositor->getMonitorFromID(pWorkspaceToChangeTo->m_iMonitorID);
|
|
||||||
|
|
||||||
if (!PMONITORWORKSPACEOWNER)
|
|
||||||
return;
|
|
||||||
|
|
||||||
g_pCompositor->setActiveMonitor(PMONITORWORKSPACEOWNER);
|
|
||||||
|
|
||||||
const auto PREVWSDATA = pWorkspaceToChangeTo->m_sPrevWorkspace;
|
|
||||||
|
|
||||||
PMONITORWORKSPACEOWNER->changeWorkspace(pWorkspaceToChangeTo);
|
|
||||||
|
|
||||||
if (PMONITOR != PMONITORWORKSPACEOWNER) {
|
|
||||||
auto PNEWWINDOW = pWorkspaceToChangeTo->getLastFocusedWindow();
|
|
||||||
if (!PNEWWINDOW)
|
|
||||||
PNEWWINDOW = g_pCompositor->getFirstWindowOnWorkspace(pWorkspaceToChangeTo->m_iID);
|
|
||||||
|
|
||||||
g_pCompositor->setActiveMonitor(PMONITORWORKSPACEOWNER);
|
|
||||||
g_pCompositor->focusWindow(PNEWWINDOW);
|
|
||||||
if (PNEWWINDOW)
|
|
||||||
g_pCompositor->warpCursorTo(PNEWWINDOW->m_vRealPosition.goalv() + PNEWWINDOW->m_vRealSize.goalv() / 2.f);
|
|
||||||
else
|
|
||||||
g_pCompositor->warpCursorTo(PMONITORWORKSPACEOWNER->vecPosition + PMONITORWORKSPACEOWNER->vecSize / 2.f);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pWorkspaceToChangeTo = g_pCompositor->createNewWorkspace(PCURRENTWORKSPACE->m_sPrevWorkspace.iID, PMONITOR->ID, PCURRENTWORKSPACE->m_sPrevWorkspace.name);
|
|
||||||
PMONITOR->changeWorkspace(pWorkspaceToChangeTo);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*PALLOWWORKSPACECYCLES)
|
|
||||||
pWorkspaceToChangeTo->m_sPrevWorkspace = {PCURRENTWORKSPACE->m_iID, PCURRENTWORKSPACE->m_szName};
|
|
||||||
else if (!EXPLICITPREVIOUS)
|
|
||||||
pWorkspaceToChangeTo->m_sPrevWorkspace = {-1, ""};
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);
|
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);
|
||||||
if (!pWorkspaceToChangeTo)
|
if (!pWorkspaceToChangeTo)
|
||||||
pWorkspaceToChangeTo = g_pCompositor->createNewWorkspace(workspaceToChangeTo, PMONITOR->ID, workspaceName);
|
pWorkspaceToChangeTo = g_pCompositor->createNewWorkspace(workspaceToChangeTo, PMONITOR->ID, workspaceName);
|
||||||
|
@ -827,7 +781,14 @@ void CKeybindManager::changeworkspace(std::string args) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pWorkspaceToChangeTo->m_sPrevWorkspace = {PCURRENTWORKSPACE->m_iID, PCURRENTWORKSPACE->m_szName};
|
if (EXPLICITPREVIOUS || (workspaceToChangeTo == PCURRENTWORKSPACE->m_iID && *PBACKANDFORTH)) {
|
||||||
|
if (*PALLOWWORKSPACECYCLES)
|
||||||
|
pWorkspaceToChangeTo->m_sPrevWorkspace = {PCURRENTWORKSPACE->m_iID, PCURRENTWORKSPACE->m_szName};
|
||||||
|
else if (!EXPLICITPREVIOUS)
|
||||||
|
pWorkspaceToChangeTo->m_sPrevWorkspace = {-1, ""};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
pWorkspaceToChangeTo->m_sPrevWorkspace = {PCURRENTWORKSPACE->m_iID, PCURRENTWORKSPACE->m_szName};
|
||||||
|
|
||||||
g_pInputManager->simulateMouseMovement();
|
g_pInputManager->simulateMouseMovement();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue