From 7f35f33b4ca16509e127976772db6abd9abf100b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 20 Oct 2023 20:15:41 +0100 Subject: surface/wayland: conform to small surface requirements do not stretch small surfaces, instead center them if they fit. --- src/helpers/WLSurface.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/helpers/WLSurface.cpp') diff --git a/src/helpers/WLSurface.cpp b/src/helpers/WLSurface.cpp index 8524c9a5..a34c77a1 100644 --- a/src/helpers/WLSurface.cpp +++ b/src/helpers/WLSurface.cpp @@ -27,12 +27,29 @@ wlr_surface* CWLSurface::wlr() const { return m_pWLRSurface; } +bool CWLSurface::small() const { + if (!m_pOwner || !exists()) + return false; + + return m_pOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width || m_pOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height; +} + +Vector2D CWLSurface::correctSmallVec() const { + if (!m_pOwner || !exists() || !small() || m_bFillIgnoreSmall) + return {}; + + return Vector2D{(m_pOwner->m_vReportedSize.x - m_pWLRSurface->current.buffer_width) / 2, (m_pOwner->m_vReportedSize.y - m_pWLRSurface->current.buffer_height) / 2}.clamp( + {}, {INFINITY, INFINITY}) * + (m_pOwner->m_vRealSize.vec() / m_pOwner->m_vReportedSize); +} + void CWLSurface::destroy() { if (!m_pWLRSurface) return; hyprListener_destroy.removeCallback(); m_pWLRSurface->data = nullptr; + m_pOwner = nullptr; if (g_pCompositor->m_pLastFocus == m_pWLRSurface) g_pCompositor->m_pLastFocus = nullptr; -- cgit v1.2.3