dispatchers: remember named workspaces in prev

This commit is contained in:
vaxerski 2023-03-13 15:19:25 +00:00
parent 17deeb07ad
commit e749af7b60
3 changed files with 26 additions and 17 deletions

View file

@ -297,7 +297,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
if (!PWORKSPACE) if (!PWORKSPACE)
return INT_MAX; return INT_MAX;
const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_iPrevWorkspaceID); const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID);
if (!PLASTWORKSPACE) if (!PLASTWORKSPACE)
return INT_MAX; return INT_MAX;
@ -470,8 +470,8 @@ int64_t getPPIDof(int64_t pid) {
return 0; return 0;
#else #else
std::string dir = "/proc/" + std::to_string(pid) + "/status"; std::string dir = "/proc/" + std::to_string(pid) + "/status";
FILE* infile; FILE* infile;
infile = fopen(dir.c_str(), "r"); infile = fopen(dir.c_str(), "r");
if (!infile) if (!infile)

View file

@ -23,7 +23,11 @@ class CWorkspace {
uint64_t m_iMonitorID = -1; uint64_t m_iMonitorID = -1;
// Previous workspace ID is stored during a workspace change, allowing travel // Previous workspace ID is stored during a workspace change, allowing travel
// to the previous workspace. // to the previous workspace.
int m_iPrevWorkspaceID = -1; struct SPrevWorkspaceData {
int iID = -1;
std::string name = "";
} m_sPrevWorkspace;
bool m_bHasFullscreenWindow = false; bool m_bHasFullscreenWindow = false;
eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL; eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL;

View file

@ -708,22 +708,22 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
// 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_iPrevWorkspaceID == -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_iPrevWorkspaceID; workspaceToChangeTo = PCURRENTWORKSPACE->m_sPrevWorkspace.iID;
if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); PWORKSPACETOCHANGETO) if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); PWORKSPACETOCHANGETO)
workspaceName = PWORKSPACETOCHANGETO->m_szName; workspaceName = PWORKSPACETOCHANGETO->m_szName;
else else
workspaceName = std::to_string(workspaceToChangeTo); workspaceName = PCURRENTWORKSPACE->m_sPrevWorkspace.name.empty() ? std::to_string(workspaceToChangeTo) : PCURRENTWORKSPACE->m_sPrevWorkspace.name;
// If the previous workspace ID isn't reset, cycles can form when continually going // If the previous workspace ID isn't reset, cycles can form when continually going
// to the previous workspace again and again. // to the previous workspace again and again.
static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue;
if (!*PALLOWWORKSPACECYCLES) if (!*PALLOWWORKSPACECYCLES)
PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1; PCURRENTWORKSPACE->m_sPrevWorkspace = {-1, ""};
else else
isSwitchingToPrevious = true; isSwitchingToPrevious = true;
} }
@ -741,22 +741,22 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
static auto* const PBACKANDFORTH = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue; static auto* const PBACKANDFORTH = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue;
if (*PBACKANDFORTH && PCURRENTWORKSPACE && PCURRENTWORKSPACE->m_iID == workspaceToChangeTo && PCURRENTWORKSPACE->m_iPrevWorkspaceID != -1 && !internal) { if (*PBACKANDFORTH && PCURRENTWORKSPACE && PCURRENTWORKSPACE->m_iID == workspaceToChangeTo && PCURRENTWORKSPACE->m_sPrevWorkspace.iID != -1 && !internal) {
const auto PPREVWORKSPACE = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_iPrevWorkspaceID); const auto PPREVWORKSPACE = g_pCompositor->getWorkspaceByID(PCURRENTWORKSPACE->m_sPrevWorkspace.iID);
workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID; workspaceToChangeTo = PCURRENTWORKSPACE->m_sPrevWorkspace.iID;
if (PPREVWORKSPACE) if (PPREVWORKSPACE)
workspaceName = PPREVWORKSPACE->m_szName; workspaceName = PPREVWORKSPACE->m_szName;
else else
workspaceName = std::to_string(workspaceToChangeTo); workspaceName = PCURRENTWORKSPACE->m_sPrevWorkspace.name.empty() ? std::to_string(workspaceToChangeTo) : PCURRENTWORKSPACE->m_sPrevWorkspace.name;
// If the previous workspace ID isn't reset, cycles can form when continually going // If the previous workspace ID isn't reset, cycles can form when continually going
// to the previous workspace again and again. // to the previous workspace again and again.
static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue;
if (!*PALLOWWORKSPACECYCLES) if (!*PALLOWWORKSPACECYCLES)
PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1; PCURRENTWORKSPACE->m_sPrevWorkspace = {-1, ""};
else else
isSwitchingToPrevious = true; isSwitchingToPrevious = true;
@ -778,9 +778,11 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);
if (!isSwitchingToPrevious && !internal) if (!isSwitchingToPrevious && !internal) {
// Remember previous workspace. // Remember previous workspace.
PWORKSPACETOCHANGETO->m_iPrevWorkspaceID = g_pCompositor->m_pLastMonitor->activeWorkspace; PWORKSPACETOCHANGETO->m_sPrevWorkspace.iID = g_pCompositor->m_pLastMonitor->activeWorkspace;
PWORKSPACETOCHANGETO->m_sPrevWorkspace.name = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace)->m_szName;
}
if (g_pCompositor->isWorkspaceSpecial(workspaceToChangeTo)) if (g_pCompositor->isWorkspaceSpecial(workspaceToChangeTo))
PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID; PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID;
@ -874,9 +876,12 @@ void CKeybindManager::changeworkspace(std::string args) {
const bool ANOTHERMONITOR = PMONITOR != g_pCompositor->m_pLastMonitor; const bool ANOTHERMONITOR = PMONITOR != g_pCompositor->m_pLastMonitor;
if (!isSwitchingToPrevious) if (!isSwitchingToPrevious) {
// Remember previous workspace. // Remember previous workspace.
PWORKSPACE->m_iPrevWorkspaceID = OLDWORKSPACE; PWORKSPACE->m_sPrevWorkspace.iID = OLDWORKSPACE;
if (const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); POLDWORKSPACE)
PWORKSPACE->m_sPrevWorkspace.name = POLDWORKSPACE->m_szName;
}
// start anim on new workspace // start anim on new workspace
PWORKSPACE->startAnim(true, ANIMTOLEFT); PWORKSPACE->startAnim(true, ANIMTOLEFT);