summaryrefslogtreecommitdiff
path: root/src/desktop/WLSurface.cpp
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2024-04-27 12:43:12 +0100
committerGitHub <noreply@github.com>2024-04-27 12:43:12 +0100
commitbca7804bb6e1bf5ce5a99b9ae4806be25e36993c (patch)
treeebd3a578de1dfe11b54f9440cfc3a408ffa6a620 /src/desktop/WLSurface.cpp
parent25aec3ac8ce65ed224f025f8f6dfef73780577a4 (diff)
internal: Window storage rework - part 1 (#5762)
* Window storage rework - part 1 * format * remove useless include * fix pch * format * fix crash in dwindle * fix vram leak * prefer .expired() for bool checks
Diffstat (limited to 'src/desktop/WLSurface.cpp')
-rw-r--r--src/desktop/WLSurface.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp
index 4c2f6c84..55601a99 100644
--- a/src/desktop/WLSurface.cpp
+++ b/src/desktop/WLSurface.cpp
@@ -7,7 +7,7 @@ void CWLSurface::assign(wlr_surface* pSurface) {
m_bInert = false;
}
-void CWLSurface::assign(wlr_surface* pSurface, CWindow* pOwner) {
+void CWLSurface::assign(wlr_surface* pSurface, PHLWINDOW pOwner) {
m_pWindowOwner = pOwner;
m_pWLRSurface = pSurface;
init();
@@ -52,20 +52,22 @@ wlr_surface* CWLSurface::wlr() const {
}
bool CWLSurface::small() const {
- if (!m_pWindowOwner || !exists())
+ if (!validMapped(m_pWindowOwner) || !exists())
return false;
- return m_pWindowOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pWindowOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
+ const auto O = m_pWindowOwner.lock();
+
+ return O->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || O->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1;
}
Vector2D CWLSurface::correctSmallVec() const {
- if (!m_pWindowOwner || !exists() || !small() || m_bFillIgnoreSmall)
+ if (!validMapped(m_pWindowOwner) || !exists() || !small() || m_bFillIgnoreSmall)
return {};
const auto SIZE = getViewporterCorrectedSize();
+ const auto O = m_pWindowOwner.lock();
- return Vector2D{(m_pWindowOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pWindowOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) *
- (m_pWindowOwner->m_vRealSize.value() / m_pWindowOwner->m_vReportedSize);
+ return Vector2D{(O->m_vReportedSize.x - SIZE.x) / 2, (O->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * (O->m_vRealSize.value() / O->m_vReportedSize);
}
Vector2D CWLSurface::getViewporterCorrectedSize() const {
@@ -110,11 +112,11 @@ void CWLSurface::destroy() {
hyprListener_destroy.removeCallback();
hyprListener_commit.removeCallback();
m_pWLRSurface->data = nullptr;
- m_pWindowOwner = nullptr;
- m_pLayerOwner = nullptr;
- m_pPopupOwner = nullptr;
- m_pSubsurfaceOwner = nullptr;
- m_bInert = true;
+ m_pWindowOwner.reset();
+ m_pLayerOwner = nullptr;
+ m_pPopupOwner = nullptr;
+ m_pSubsurfaceOwner = nullptr;
+ m_bInert = true;
if (g_pCompositor && g_pCompositor->m_pLastFocus == m_pWLRSurface)
g_pCompositor->m_pLastFocus = nullptr;
@@ -148,8 +150,8 @@ void CWLSurface::init() {
Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this);
}
-CWindow* CWLSurface::getWindow() {
- return m_pWindowOwner;
+PHLWINDOW CWLSurface::getWindow() {
+ return m_pWindowOwner.lock();
}
SLayerSurface* CWLSurface::getLayer() {
@@ -165,15 +167,15 @@ CSubsurface* CWLSurface::getSubsurface() {
}
bool CWLSurface::desktopComponent() {
- return m_pLayerOwner || m_pWindowOwner || m_pSubsurfaceOwner || m_pPopupOwner;
+ return m_pLayerOwner || !m_pWindowOwner.expired() || m_pSubsurfaceOwner || m_pPopupOwner;
}
std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() {
if (!desktopComponent())
return {};
- if (m_pWindowOwner)
- return m_pWindowOwner->getWindowMainSurfaceBox();
+ if (!m_pWindowOwner.expired())
+ return m_pWindowOwner.lock()->getWindowMainSurfaceBox();
if (m_pLayerOwner)
return m_pLayerOwner->geometry;
if (m_pPopupOwner)