diff options
author | Vaxry <[email protected]> | 2024-05-05 17:16:00 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-05-05 17:16:00 +0100 |
commit | 1ed1ce9506e65f76fe5236194516f23d662bba0b (patch) | |
tree | 124556baadfe27587d025913bfbdd579060ed317 /src/Compositor.cpp | |
parent | 589f758d947cb4e8b888d2da00076a9fb0a6d521 (diff) | |
download | Hyprland-1ed1ce9506e65f76fe5236194516f23d662bba0b.tar.gz Hyprland-1ed1ce9506e65f76fe5236194516f23d662bba0b.zip |
internal: new shared_ptr and weak_ptr implementation (#5883)
moves std::shared_ptrs to a new implementation
Advantages:
- you can dereference a weak_ptr directly. This will obviously segfault on a nullptr deref if it's expired.
- this is useful to avoid the .lock() hell where we are 100% sure the pointer _should_ be valid. (and if it isn't, it should throw.)
- weak_ptrs are still valid while the SP is being destroyed.
- reasoning: while an object (e.g. CWindow) is being destroyed, its `weak_ptr self` should be accessible (the sp is still alive, and so is CWindow), but it's not because by stl it's already expired (to prevent resurrection)
- this impl solves it differently. w_p is expired, but can still be dereferenced and used. Creating `s_p`s is not possible anymore, though.
- this is useful in destructors and callbacks.
Diffstat (limited to 'src/Compositor.cpp')
-rw-r--r-- | src/Compositor.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 1f5a355c..96831751 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1183,7 +1183,7 @@ void CCompositor::sanityCheckWorkspaces() { const auto& WORKSPACE = *it; // If ref == 1, only the compositor holds a ref, which means it's inactive and has no mapped windows. - if (!WORKSPACE->m_bPersistent && WORKSPACE.use_count() == 1) { + if (!WORKSPACE->m_bPersistent && WORKSPACE.strongRef() == 1) { it = m_vWorkspaces.erase(it); continue; } @@ -1823,7 +1823,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) { setBorderColor(*RENDERDATA.borderGradient); else { const bool GROUPLOCKED = pWindow->m_sGroupData.pNextWindow.lock() ? pWindow->getGroupHead()->m_sGroupData.locked : false; - if (pWindow == m_pLastWindow.lock()) { + if (pWindow == m_pLastWindow) { const auto* const ACTIVECOLOR = !pWindow->m_sGroupData.pNextWindow.lock() ? (!pWindow->m_sGroupData.deny ? ACTIVECOL : NOGROUPACTIVECOL) : (GROUPLOCKED ? GROUPACTIVELOCKEDCOL : GROUPACTIVECOL); setBorderColor(pWindow->m_sSpecialRenderData.activeBorderColor.toUnderlying().m_vColors.empty() ? *ACTIVECOLOR : @@ -1848,7 +1848,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) { pWindow->m_sSpecialRenderData.alphaFullscreen.toUnderlying() * *PFULLSCREENALPHA) : *PFULLSCREENALPHA; } else { - if (pWindow == m_pLastWindow.lock()) + if (pWindow == m_pLastWindow) pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaOverride.toUnderlying() ? pWindow->m_sSpecialRenderData.alpha.toUnderlying() : pWindow->m_sSpecialRenderData.alpha.toUnderlying() * *PACTIVEALPHA; else @@ -1867,7 +1867,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) { // shadow if (pWindow->m_iX11Type != 2 && !pWindow->m_bX11DoesntWantBorders) { - if (pWindow == m_pLastWindow.lock()) { + if (pWindow == m_pLastWindow) { pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL); } else { pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL); @@ -2346,7 +2346,7 @@ PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp) { const bool FLOAT = regexp.starts_with("floating"); for (auto& w : m_vWindows) { - if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow.lock()->m_pWorkspace || w->isHidden()) + if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow->m_pWorkspace || w->isHidden()) continue; return w; |