Workspace/core: Refactor workspace storage (#5380)

* refactor workspaces to use ptrs

* clang-format
This commit is contained in:
Vaxry 2024-04-02 20:32:39 +01:00 committed by GitHub
parent fc0a7af7ba
commit ef23ef60c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 544 additions and 509 deletions

View file

@ -79,11 +79,11 @@ void CAnimationManager::tick() {
const float SPENT = av->getPercent();
// window stuff
const auto PWINDOW = (CWindow*)av->m_pWindow;
const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace;
const auto PLAYER = (SLayerSurface*)av->m_pLayer;
CMonitor* PMONITOR = nullptr;
bool animationsDisabled = animGlobalDisabled;
const auto PWINDOW = (CWindow*)av->m_pWindow;
PHLWORKSPACE PWORKSPACE = av->m_pWorkspace.lock();
const auto PLAYER = (SLayerSurface*)av->m_pLayer;
CMonitor* PMONITOR = nullptr;
bool animationsDisabled = animGlobalDisabled;
if (PWINDOW) {
if (av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) {
@ -111,7 +111,7 @@ void CAnimationManager::tick() {
// TODO: just make this into a damn callback already vax...
for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != PWORKSPACE->m_iID)
if (!w->m_bIsMapped || w->isHidden() || w->m_pWorkspace != PWORKSPACE)
continue;
if (w->m_bIsFloating && !w->m_bPinned) {
@ -129,7 +129,7 @@ void CAnimationManager::tick() {
// damage any workspace window that is on any monitor
for (auto& w : g_pCompositor->m_vWindows) {
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->m_bPinned)
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE || w->m_bPinned)
continue;
g_pHyprRenderer->damageWindow(w.get());
@ -146,7 +146,7 @@ void CAnimationManager::tick() {
animationsDisabled = animationsDisabled || PLAYER->noAnimations;
}
const bool VISIBLE = PWINDOW ? g_pCompositor->isWorkspaceVisible(PWINDOW->m_iWorkspaceID) : true;
const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? g_pCompositor->isWorkspaceVisible(PWINDOW->workspaceID()) : true;
// beziers are with a switch unforto
// TODO: maybe do something cleaner
@ -212,7 +212,7 @@ void CAnimationManager::tick() {
g_pHyprRenderer->damageWindow(PWINDOW);
} else if (PWORKSPACE) {
for (auto& w : g_pCompositor->m_vWindows) {
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID)
if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE)
continue;
w->updateWindowDecos();

View file

@ -225,13 +225,13 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) {
return false;
}
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
const auto PNEWMAINWORKSPACE = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace);
const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
const auto PNEWMAINWORKSPACE = monitor->activeWorkspace;
g_pInputManager->unconstrainMouse();
PNEWMAINWORKSPACE->rememberPrevWorkspace(PWORKSPACE);
const auto PNEWWORKSPACE = monitor->specialWorkspaceID != 0 ? g_pCompositor->getWorkspaceByID(monitor->specialWorkspaceID) : PNEWMAINWORKSPACE;
const auto PNEWWORKSPACE = monitor->activeSpecialWorkspace ? monitor->activeSpecialWorkspace : PNEWMAINWORKSPACE;
const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow();
if (PNEWWINDOW) {
@ -259,8 +259,8 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) {
// remove constraints
g_pInputManager->unconstrainMouse();
if (PLASTWINDOW && PLASTWINDOW->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && PLASTWINDOW->m_bIsFullscreen) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PLASTWINDOW->m_iWorkspaceID);
if (PLASTWINDOW && PLASTWINDOW->m_pWorkspace == PWINDOWTOCHANGETO->m_pWorkspace && PLASTWINDOW->m_bIsFullscreen) {
const auto PWORKSPACE = PLASTWINDOW->m_pWorkspace;
const auto FSMODE = PWORKSPACE->m_efFullscreenMode;
if (!PWINDOWTOCHANGETO->m_bPinned)
@ -874,11 +874,11 @@ void toggleActiveFloatingCore(std::string args, std::optional<bool> floatState)
curr = curr->m_sGroupData.pNextWindow;
}
g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID);
g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID());
} else {
PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating;
g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID);
g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID());
g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW);
}
@ -927,7 +927,7 @@ void CKeybindManager::changeworkspace(std::string args) {
if (!PMONITOR)
return;
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace;
const bool EXPLICITPREVIOUS = args.starts_with("previous");
if (args.starts_with("previous")) {
@ -1044,14 +1044,14 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) {
return;
}
if (WORKSPACEID == PWINDOW->m_iWorkspaceID) {
if (WORKSPACEID == PWINDOW->workspaceID()) {
Debug::log(LOG, "Not moving to workspace because it didn't change.");
return;
}
auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID);
CMonitor* pMonitor = nullptr;
const auto POLDWS = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
const auto POLDWS = PWINDOW->m_pWorkspace;
static auto PALLOWWORKSPACECYCLES = CConfigValue<Hyprlang::INT>("binds:allow_workspace_cycles");
g_pHyprRenderer->damageWindow(PWINDOW);
@ -1106,7 +1106,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {
return;
}
if (WORKSPACEID == PWINDOW->m_iWorkspaceID)
if (WORKSPACEID == PWINDOW->workspaceID())
return;
g_pHyprRenderer->damageWindow(PWINDOW);
@ -1220,7 +1220,7 @@ void CKeybindManager::moveActiveTo(std::string args) {
if (!PNEWMONITOR)
return;
moveActiveToWorkspace(std::to_string(PNEWMONITOR->activeWorkspace));
moveActiveToWorkspace(PNEWMONITOR->activeWorkspace->getConfigName());
return;
}
@ -1265,7 +1265,7 @@ void CKeybindManager::moveActiveTo(std::string args) {
if (!PMONITORTOCHANGETO)
return;
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITORTOCHANGETO->activeWorkspace);
const auto PWORKSPACE = PMONITORTOCHANGETO->activeWorkspace;
moveActiveToWorkspace(PWORKSPACE->getConfigName());
}
@ -1324,7 +1324,7 @@ void CKeybindManager::toggleSplit(std::string args) {
if (!header.pWindow)
return;
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID);
const auto PWORKSPACE = header.pWindow->m_pWorkspace;
if (PWORKSPACE->m_bHasFullscreenWindow)
return;
@ -1339,7 +1339,7 @@ void CKeybindManager::swapSplit(std::string args) {
if (!header.pWindow)
return;
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID);
const auto PWORKSPACE = header.pWindow->m_pWorkspace;
if (PWORKSPACE->m_bHasFullscreenWindow)
return;
@ -1447,7 +1447,7 @@ void CKeybindManager::moveCursor(std::string args) {
void CKeybindManager::workspaceOpt(std::string args) {
// current workspace
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
if (!PWORKSPACE)
return; // ????
@ -1457,7 +1457,7 @@ void CKeybindManager::workspaceOpt(std::string args) {
// apply
for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID)
if (!w->m_bIsMapped || w->m_pWorkspace != PWORKSPACE)
continue;
w->m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo;
@ -1472,7 +1472,7 @@ void CKeybindManager::workspaceOpt(std::string args) {
ptrs.push_back(w.get());
for (auto& w : ptrs) {
if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->isHidden())
if (!w->m_bIsMapped || w->m_pWorkspace != PWORKSPACE || w->isHidden())
continue;
if (!w->m_bRequestsFloat && w->m_bIsFloating != PWORKSPACE->m_bDefaultFloating) {
@ -1526,7 +1526,7 @@ void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) {
}
// get the current workspace
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
const auto PCURRENTWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
if (!PCURRENTWORKSPACE) {
Debug::log(ERR, "moveCurrentWorkspaceToMonitor invalid workspace!");
@ -1595,7 +1595,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
static auto PBACKANDFORTH = CConfigValue<Hyprlang::INT>("binds:workspace_back_and_forth");
if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspace == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) {
if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspaceID() == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) {
const int PREVWORKSPACEID = pWorkspace->m_sPrevWorkspace.iID;
const auto PREVWORKSPACENAME = pWorkspace->m_sPrevWorkspace.name;
// Workspace to focus is previous workspace
@ -1612,7 +1612,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) {
Debug::log(ERR, "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!");
return;
}
if (POLDMONITOR->activeWorkspace == workspaceID) {
if (POLDMONITOR->activeWorkspaceID() == workspaceID) {
g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR);
return;
} else {
@ -1634,10 +1634,10 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) {
bool requestedWorkspaceIsAlreadyOpen = false;
const auto PMONITOR = g_pCompositor->m_pLastMonitor;
int specialOpenOnMonitor = PMONITOR->specialWorkspaceID;
int specialOpenOnMonitor = PMONITOR->activeSpecialWorkspaceID();
for (auto& m : g_pCompositor->m_vMonitors) {
if (m->specialWorkspaceID == workspaceID) {
if (m->activeSpecialWorkspaceID() == workspaceID) {
requestedWorkspaceIsAlreadyOpen = true;
break;
}
@ -1750,8 +1750,8 @@ void CKeybindManager::circleNext(std::string arg) {
if (!g_pCompositor->m_pLastWindow) {
// if we have a clear focus, find the first window and get the next focusable.
if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace) > 0) {
const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace);
if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()) > 0) {
const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID());
switchToWindow(PWINDOW);
}
@ -1781,13 +1781,13 @@ void CKeybindManager::focusWindow(std::string regexp) {
Debug::log(LOG, "Focusing to window name: {}", PWINDOW->m_szTitle);
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
if (!PWORKSPACE) {
Debug::log(ERR, "BUG THIS: null workspace in focusWindow");
return;
}
if (g_pCompositor->m_pLastMonitor->activeWorkspace != PWINDOW->m_iWorkspaceID) {
if (g_pCompositor->m_pLastMonitor->activeWorkspace != PWINDOW->m_pWorkspace) {
Debug::log(LOG, "Fake executing workspace to move focus");
changeworkspace(PWORKSPACE->getConfigName());
}
@ -1975,7 +1975,7 @@ void CKeybindManager::swapnext(std::string arg) {
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
const auto PLASTCYCLED = g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow->m_pLastCycledWindow) &&
g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_iWorkspaceID == PLASTWINDOW->m_iWorkspaceID ?
g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_pWorkspace == PLASTWINDOW->m_pWorkspace ?
g_pCompositor->m_pLastWindow->m_pLastCycledWindow :
nullptr;
@ -2029,13 +2029,13 @@ void CKeybindManager::pinActive(std::string args) {
if (!PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen)
return;
PWINDOW->m_bPinned = !PWINDOW->m_bPinned;
PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeWorkspace;
PWINDOW->m_bPinned = !PWINDOW->m_bPinned;
PWINDOW->m_pWorkspace = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeWorkspace;
PWINDOW->updateDynamicRules();
g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW);
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID);
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS);

View file

@ -74,7 +74,7 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) {
}
if (!pWindow->m_bPinned)
g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_pLastFocusedWindow = pWindow;
pWindow->m_pWorkspace->m_pLastFocusedWindow = pWindow;
}
void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) {

View file

@ -65,7 +65,7 @@ void CInputManager::recheckIdleInhibitorStatus() {
return;
}
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->m_iWorkspaceID)) {
if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->workspaceID())) {
g_pCompositor->setIdleActivityInhibit(false);
return;
}

View file

@ -230,7 +230,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface);
// then, we check if the workspace doesnt have a fullscreen window
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
const auto PWORKSPACE = PMONITOR->activeWorkspace;
if (PWORKSPACE->m_bHasFullscreenWindow && !foundSurface && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) {
pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID);
@ -244,7 +244,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (PWINDOWIDEAL &&
((PWINDOWIDEAL->m_bIsFloating && PWINDOWIDEAL->m_bCreatedOverFullscreen) /* floating over fullscreen */
|| (PMONITOR->specialWorkspaceID == PWINDOWIDEAL->m_iWorkspaceID) /* on an open special workspace */))
|| (PMONITOR->activeSpecialWorkspace == PWINDOWIDEAL->m_pWorkspace) /* on an open special workspace */))
pFoundWindow = PWINDOWIDEAL;
if (!pFoundWindow->m_bIsX11) {
@ -260,10 +260,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
if (!foundSurface) {
if (PWORKSPACE->m_bHasFullscreenWindow && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) {
if (PMONITOR->specialWorkspaceID) {
if (PMONITOR->activeSpecialWorkspace) {
pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
if (pFoundWindow && !g_pCompositor->isWorkspaceSpecial(pFoundWindow->m_iWorkspaceID)) {
if (pFoundWindow && !pFoundWindow->onSpecialWorkspace()) {
pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID);
}
} else {

View file

@ -24,7 +24,7 @@ void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) {
}
void CInputManager::beginWorkspaceSwipe() {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace);
const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace;
Debug::log(LOG, "Starting a swipe from {}", PWORKSPACE->m_szName);
@ -80,14 +80,14 @@ void CInputManager::endWorkspaceSwipe() {
workspaceIDRight = maxWorkspace + 1;
}
auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER
auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER
auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER
auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER
const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value();
const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP;
const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP;
const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value();
const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP;
const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP;
CWorkspace* pSwitchedTo = nullptr;
PHLWORKSPACE pSwitchedTo = nullptr;
if ((abs(m_sActiveSwipe.delta) < *PSWIPEDIST * *PSWIPEPERC && (*PSWIPEFORC == 0 || (*PSWIPEFORC != 0 && m_sActiveSwipe.avgSpeed < *PSWIPEFORC))) ||
abs(m_sActiveSwipe.delta) < 2) {

View file

@ -37,7 +37,7 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) {
return;
// TODO: Don't swipe if you touched a floating window.
} else if (*PSWIPETOUCH && (!m_pFoundLSToFocus || m_pFoundLSToFocus->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
const auto PWORKSPACE = PMONITOR->activeWorkspace;
const bool VERTANIMS = PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" ||
PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert");
// TODO: support no_gaps_when_only?