From 4510764f348d1a7c4cca613925ee22acfa38b388 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Thu, 30 Jun 2022 20:02:04 +0200 Subject: [PATCH] finally fix scaled snapshots --- src/events/Windows.cpp | 4 +++- src/helpers/MiscFunctions.cpp | 4 ++-- src/render/OpenGL.cpp | 7 ++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index e5bf3696..3c1d83f5 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -337,8 +337,10 @@ void Events::listener_unmapWindow(void* owner, void* data) { g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)); + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + // do the animation thing - PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.vec(); + PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.vec() - PMONITOR->vecPosition; PWINDOW->m_vOriginalClosedSize = PWINDOW->m_vRealSize.vec(); if (!PWINDOW->m_bX11DoesntWantBorders) // don't animate out if they weren't animated in. diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 067a351f..cb1d88d6 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -114,8 +114,8 @@ std::string getFormat(const char *fmt, ...) { } void scaleBox(wlr_box* box, float scale) { - box->width = std::round((box->x + box->width) * scale) - std::round(box->x * scale); - box->height = std::round((box->y + box->height) * scale) - std::round(box->y * scale); + box->width = std::round(box->width * scale); + box->height = std::round(box->height * scale); box->x = std::round(box->x * scale); box->y = std::round(box->y * scale); } diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 6a7c7515..793901aa 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -813,12 +813,13 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { wlr_box windowBox; // some mafs to figure out the correct box - Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.vec().x / PWINDOW->m_vOriginalClosedSize.x), (PMONITOR->scale * PWINDOW->m_vRealSize.vec().y / PWINDOW->m_vOriginalClosedSize.y)); + // the originalClosedPos is relative to the monitor's pos + Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.vec().x / (PWINDOW->m_vOriginalClosedSize.x * PMONITOR->scale)), (PMONITOR->scale * PWINDOW->m_vRealSize.vec().y / (PWINDOW->m_vOriginalClosedSize.y * PMONITOR->scale))); windowBox.width = PMONITOR->vecPixelSize.x * scaleXY.x; windowBox.height = PMONITOR->vecPixelSize.y * scaleXY.y; - windowBox.x = (PWINDOW->m_vRealPosition.vec().x * PMONITOR->scale - PMONITOR->vecPosition.x) - ((PWINDOW->m_vOriginalClosedPos.x - PMONITOR->vecPosition.x) * scaleXY.x); - windowBox.y = (PWINDOW->m_vRealPosition.vec().y * PMONITOR->scale - PMONITOR->vecPosition.y) - ((PWINDOW->m_vOriginalClosedPos.y - PMONITOR->vecPosition.y) * scaleXY.y); + windowBox.x = ((PWINDOW->m_vRealPosition.vec().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.x * PMONITOR->scale) * scaleXY.x); + windowBox.y = ((PWINDOW->m_vRealPosition.vec().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.y * PMONITOR->scale) * scaleXY.y); pixman_region32_t fakeDamage; pixman_region32_init_rect(&fakeDamage, 0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y);