diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp index 1a1bd2933..ff6a69dea 100644 --- a/src/desktop/WLSurface.cpp +++ b/src/desktop/WLSurface.cpp @@ -117,11 +117,13 @@ CRegion CWLSurface::computeDamage() const { // go from buffer coords in the damage to hl logical - const auto BOX = getSurfaceBoxGlobal(); - const Vector2D SCALE = BOX.has_value() ? BOX->size() / m_resource->m_current.bufferSize : - Vector2D{1.0 / m_resource->m_current.scale, 1.0 / m_resource->m_current.scale /* Wrong... but we can't really do better */}; + const auto BOX = getSurfaceBoxGlobal(); + const auto SURFSIZE = m_resource->m_current.size; + const Vector2D SCALE = SURFSIZE / m_resource->m_current.bufferSize; damage.scale(SCALE); + if (BOX.has_value()) + damage.intersect(CBox{{}, BOX->size()}); if (m_windowOwner) damage.scale(m_windowOwner->m_X11SurfaceScaledBy); // fix xwayland:force_zero_scaling stuff that will be fucked by the above a bit diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 019f75120..e4b4bf5e8 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1087,6 +1087,25 @@ void CHyprRenderer::renderSessionLockMissing(PHLMONITOR pMonitor) { } } +static std::optional getSurfaceExpectedSize(PHLWINDOW pWindow, SP pSurface, PHLMONITOR pMonitor, bool main) { + const auto CAN_USE_WINDOW = pWindow && main; + const auto WINDOW_SIZE_MISALIGN = CAN_USE_WINDOW && pWindow->getReportedSize() != pWindow->m_wlSurface->resource()->m_current.size; + + if (pSurface->m_current.viewport.hasDestination) + return (pSurface->m_current.viewport.destination * pMonitor->m_scale).round(); + + if (pSurface->m_current.viewport.hasSource) + return (pSurface->m_current.viewport.source.size() * pMonitor->m_scale).round(); + + if (WINDOW_SIZE_MISALIGN) + return (pSurface->m_current.size * pMonitor->m_scale).round(); + + if (CAN_USE_WINDOW) + return (pWindow->getReportedSize() * pMonitor->m_scale).round(); + + return std::nullopt; +} + void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SP pSurface, PHLMONITOR pMonitor, bool main, const Vector2D& projSize, const Vector2D& projSizeUnscaled, bool fixMisalignedFSV1) { if (!pWindow || !pWindow->m_isX11) { @@ -1123,14 +1142,10 @@ void CHyprRenderer::calculateUVForSurface(PHLWINDOW pWindow, SPm_scale); - const bool SCALE_UNAWARE = MONITOR_WL_SCALE == pSurface->m_current.scale || !pSurface->m_current.viewport.hasDestination; - const auto EXPECTED_SIZE = ((pSurface->m_current.viewport.hasDestination ? - pSurface->m_current.viewport.destination : - (pSurface->m_current.viewport.hasSource ? pSurface->m_current.viewport.source.size() / pSurface->m_current.scale : projSize)) * - pMonitor->m_scale) - .round(); + const bool SCALE_UNAWARE = MONITOR_WL_SCALE > 1 && (MONITOR_WL_SCALE == pSurface->m_current.scale || !pSurface->m_current.viewport.hasDestination); + const auto EXPECTED_SIZE = getSurfaceExpectedSize(pWindow, pSurface, pMonitor, main).value_or((projSize * pMonitor->m_scale).round()); const auto RATIO = projSize / EXPECTED_SIZE; if (!SCALE_UNAWARE || MONITOR_WL_SCALE == 1) {