Skip to content

Commit

Permalink
dispatchers: remember named workspaces in prev
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski authored and scorpion-26 committed Apr 5, 2023
1 parent 515e0d7 commit 9d150ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/helpers/MiscFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) {
if (!PWORKSPACE)
return INT_MAX;

const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_iPrevWorkspaceID);
const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID);

if (!PLASTWORKSPACE)
return INT_MAX;
Expand Down Expand Up @@ -470,8 +470,8 @@ int64_t getPPIDof(int64_t pid) {

return 0;
#else
std::string dir = "/proc/" + std::to_string(pid) + "/status";
FILE* infile;
std::string dir = "/proc/" + std::to_string(pid) + "/status";
FILE* infile;

infile = fopen(dir.c_str(), "r");
if (!infile)
Expand Down
6 changes: 5 additions & 1 deletion src/helpers/Workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ class CWorkspace {
uint64_t m_iMonitorID = -1;
// Previous workspace ID is stored during a workspace change, allowing travel
// to the previous workspace.
int m_iPrevWorkspaceID = -1;
struct SPrevWorkspaceData {
int iID = -1;
std::string name = "";
} m_sPrevWorkspace;

bool m_bHasFullscreenWindow = false;
eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL;

Expand Down
31 changes: 18 additions & 13 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,22 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);

// 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");
return;
} else {
workspaceToChangeTo = PCURRENTWORKSPACE->m_iPrevWorkspaceID;
workspaceToChangeTo = PCURRENTWORKSPACE->m_sPrevWorkspace.iID;

if (const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo); PWORKSPACETOCHANGETO)
workspaceName = PWORKSPACETOCHANGETO->m_szName;
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
// to the previous workspace again and again.
static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue;
if (!*PALLOWWORKSPACECYCLES)
PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1;
PCURRENTWORKSPACE->m_sPrevWorkspace = {-1, ""};
else
isSwitchingToPrevious = true;
}
Expand All @@ -741,22 +741,22 @@ void CKeybindManager::changeworkspace(std::string args) {
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
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)
workspaceName = PPREVWORKSPACE->m_szName;
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
// to the previous workspace again and again.
static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue;
if (!*PALLOWWORKSPACECYCLES)
PCURRENTWORKSPACE->m_iPrevWorkspaceID = -1;
PCURRENTWORKSPACE->m_sPrevWorkspace = {-1, ""};
else
isSwitchingToPrevious = true;

Expand All @@ -778,9 +778,11 @@ void CKeybindManager::changeworkspace(std::string args) {

const auto PWORKSPACETOCHANGETO = g_pCompositor->getWorkspaceByID(workspaceToChangeTo);

if (!isSwitchingToPrevious && !internal)
if (!isSwitchingToPrevious && !internal) {
// 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))
PWORKSPACETOCHANGETO->m_iMonitorID = PMONITOR->ID;
Expand Down Expand Up @@ -874,9 +876,12 @@ void CKeybindManager::changeworkspace(std::string args) {

const bool ANOTHERMONITOR = PMONITOR != g_pCompositor->m_pLastMonitor;

if (!isSwitchingToPrevious)
if (!isSwitchingToPrevious) {
// 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
PWORKSPACE->startAnim(true, ANIMTOLEFT);
Expand Down

0 comments on commit 9d150ac

Please sign in to comment.