mirror of
https://github.com/hyprwm/Hyprland.git
synced 2026-02-10 18:55:57 +00:00
keybinds: fix previous_per_monitor logic (#9010)
Co-authored-by: Крылов Александр <aleksandr.krylov@hyperus.team>
This commit is contained in:
@ -1176,27 +1176,24 @@ SDispatchResult CKeybindManager::toggleActivePseudo(std::string args) {
|
||||
return {};
|
||||
}
|
||||
|
||||
static SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE) {
|
||||
static SWorkspaceIDName getWorkspaceToChangeFromArgs(std::string args, PHLWORKSPACE PCURRENTWORKSPACE, PHLMONITORREF PMONITOR) {
|
||||
if (!args.starts_with("previous")) {
|
||||
return getWorkspaceIDNameFromString(args);
|
||||
}
|
||||
|
||||
const bool PER_MON = args.contains("_per_monitor");
|
||||
const SWorkspaceIDName PPREVWS = PCURRENTWORKSPACE->getPrevWorkspaceIDName(PER_MON);
|
||||
const SWorkspaceIDName PPREVWS = PER_MON ? PMONITOR->getPrevWorkspaceIDName(PCURRENTWORKSPACE->m_iID) : PCURRENTWORKSPACE->getPrevWorkspaceIDName();
|
||||
// Do nothing if there's no previous workspace, otherwise switch to it.
|
||||
if (PPREVWS.id == -1) {
|
||||
if (PPREVWS.id == -1 || PPREVWS.id == PCURRENTWORKSPACE->m_iID) {
|
||||
Debug::log(LOG, "No previous workspace to change to");
|
||||
return {WORKSPACE_NOT_CHANGED, ""};
|
||||
return {.id = WORKSPACE_NOT_CHANGED};
|
||||
}
|
||||
|
||||
const auto ID = PCURRENTWORKSPACE->m_iID;
|
||||
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(PPREVWS.id); PWORKSPACETOCHANGETO) {
|
||||
if (PER_MON && PCURRENTWORKSPACE->m_pMonitor != PWORKSPACETOCHANGETO->m_pMonitor)
|
||||
return {WORKSPACE_NOT_CHANGED, ""};
|
||||
return {ID, PWORKSPACETOCHANGETO->m_szName};
|
||||
return {.id = PWORKSPACETOCHANGETO->m_iID, .name = PWORKSPACETOCHANGETO->m_szName};
|
||||
}
|
||||
|
||||
return {ID, PPREVWS.name.empty() ? std::to_string(PPREVWS.id) : PPREVWS.name};
|
||||
return {.id = PPREVWS.id, .name = PPREVWS.name.empty() ? std::to_string(PPREVWS.id) : PPREVWS.name};
|
||||
}
|
||||
|
||||
SDispatchResult CKeybindManager::changeworkspace(std::string args) {
|
||||
@ -1214,7 +1211,7 @@ SDispatchResult CKeybindManager::changeworkspace(std::string args) {
|
||||
const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace;
|
||||
const bool EXPLICITPREVIOUS = args.contains("previous");
|
||||
|
||||
const auto& [workspaceToChangeTo, workspaceName] = getWorkspaceToChangeFromArgs(args, PCURRENTWORKSPACE);
|
||||
const auto& [workspaceToChangeTo, workspaceName] = getWorkspaceToChangeFromArgs(args, PCURRENTWORKSPACE, PMONITOR);
|
||||
if (workspaceToChangeTo == WORKSPACE_INVALID) {
|
||||
Debug::log(ERR, "Error in changeworkspace, invalid value");
|
||||
return {.success = false, .error = "Error in changeworkspace, invalid value"};
|
||||
@ -1223,19 +1220,19 @@ SDispatchResult CKeybindManager::changeworkspace(std::string args) {
|
||||
if (workspaceToChangeTo == WORKSPACE_NOT_CHANGED)
|
||||
return {};
|
||||
|
||||
const auto PREVWS = PCURRENTWORKSPACE->getPrevWorkspaceIDName(args.contains("_per_monitor"));
|
||||
const SWorkspaceIDName PPREVWS = args.contains("_per_monitor") ? PMONITOR->getPrevWorkspaceIDName(PCURRENTWORKSPACE->m_iID) : PCURRENTWORKSPACE->getPrevWorkspaceIDName();
|
||||
|
||||
const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID;
|
||||
if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PREVWS.id == -1))
|
||||
const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID;
|
||||
if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PPREVWS.id == -1))
|
||||
return {.success = false, .error = "Previous workspace doesn't exist"};
|
||||
|
||||
g_pInputManager->unconstrainMouse();
|
||||
g_pInputManager->m_bEmptyFocusCursorSet = false;
|
||||
|
||||
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(BISWORKSPACECURRENT ? PREVWS.id : workspaceToChangeTo);
|
||||
auto pWorkspaceToChangeTo = g_pCompositor->getWorkspaceByID(BISWORKSPACECURRENT ? PPREVWS.id : workspaceToChangeTo);
|
||||
if (!pWorkspaceToChangeTo)
|
||||
pWorkspaceToChangeTo =
|
||||
g_pCompositor->createNewWorkspace(BISWORKSPACECURRENT ? PREVWS.id : workspaceToChangeTo, PMONITOR->ID, BISWORKSPACECURRENT ? PREVWS.name : workspaceName);
|
||||
g_pCompositor->createNewWorkspace(BISWORKSPACECURRENT ? PPREVWS.id : workspaceToChangeTo, PMONITOR->ID, BISWORKSPACECURRENT ? PPREVWS.name : workspaceName);
|
||||
|
||||
if (!BISWORKSPACECURRENT && pWorkspaceToChangeTo->m_bIsSpecialWorkspace) {
|
||||
PMONITOR->setSpecialWorkspace(pWorkspaceToChangeTo);
|
||||
@ -1407,9 +1404,7 @@ SDispatchResult CKeybindManager::moveActiveToWorkspace(std::string args) {
|
||||
}
|
||||
|
||||
SDispatchResult CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
|
||||
PHLWINDOW PWINDOW = nullptr;
|
||||
|
||||
const auto ORIGINALARGS = args;
|
||||
PHLWINDOW PWINDOW = nullptr;
|
||||
|
||||
if (args.contains(',')) {
|
||||
PWINDOW = g_pCompositor->getWindowByRegex(args.substr(args.find_last_of(',') + 1));
|
||||
@ -2033,7 +2028,7 @@ SDispatchResult CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args
|
||||
}
|
||||
|
||||
static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth");
|
||||
const auto PREVWS = pWorkspace->getPrevWorkspaceIDName(false);
|
||||
const auto PREVWS = pWorkspace->getPrevWorkspaceIDName();
|
||||
|
||||
if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspaceID() == workspaceID && PREVWS.id != -1) {
|
||||
// Workspace to focus is previous workspace
|
||||
|
||||
Reference in New Issue
Block a user