From 4e8837ddabf669600c9571189e8a6a7937ba336a Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:02:33 +0000 Subject: [PATCH] core: minor transform fixes (#94) --- src/helpers/LayerSurface.cpp | 3 +++ src/helpers/LayerSurface.hpp | 8 +++++--- src/helpers/Monitor.cpp | 4 +++- src/hyprpicker.cpp | 14 ++++++++++---- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/helpers/LayerSurface.cpp b/src/helpers/LayerSurface.cpp index f67d186..7054e0f 100644 --- a/src/helpers/LayerSurface.cpp +++ b/src/helpers/LayerSurface.cpp @@ -21,6 +21,9 @@ CLayerSurface::CLayerSurface(SMonitor* pMonitor) { pFractionalScale = makeShared(g_pHyprpicker->m_pFractionalMgr->sendGetFractionalScale(pSurface->resource())); pFractionalScale->setPreferredScale([this](CCWpFractionalScaleV1* r, uint32_t scale120) { // Debug::log(TRACE, "Received a preferredScale for %s: %.2f", m_pMonitor->name.c_str(), scale120 / 120.F); + fractionalScale = scale120 / 120.F; + wantsReload = true; + g_pHyprpicker->recheckACK(); }); } diff --git a/src/helpers/LayerSurface.hpp b/src/helpers/LayerSurface.hpp index 29aa10b..46bc87c 100644 --- a/src/helpers/LayerSurface.hpp +++ b/src/helpers/LayerSurface.hpp @@ -20,9 +20,11 @@ class CLayerSurface { SP pViewport = nullptr; SP pFractionalScale = nullptr; - bool wantsACK = false; - uint32_t ACKSerial = 0; - bool working = false; + float fractionalScale = 1.F; + bool wantsACK = false; + bool wantsReload = false; + uint32_t ACKSerial = 0; + bool working = false; int lastBuffer = 0; SP buffers[2]; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 07a982b..67a8fde 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -39,6 +39,8 @@ void SMonitor::initSCFrame() { if (pLS->m_pMonitor->transform % 2 == 1) std::swap(transformedSize.x, transformedSize.y); + Debug::log(TRACE, "Frame ready: pixel %.0fx%.0f, xfmd: %.0fx%.0f", pLS->screenBuffer->pixelSize.x, pLS->screenBuffer->pixelSize.y, transformedSize.x, transformedSize.y); + SP newBuf = makeShared(transformedSize, pLS->screenBufferFormat, transformedSize.x * 4); int bytesPerPixel = pLS->screenBuffer->stride / (int)pLS->screenBuffer->pixelSize.x; @@ -112,7 +114,7 @@ void SMonitor::initSCFrame() { pSCFrame.reset(); }); - pSCFrame->setFailed([this](CCZwlrScreencopyFrameV1* r) { + pSCFrame->setFailed([](CCZwlrScreencopyFrameV1* r) { Debug::log(CRIT, "Failed to get a Screencopy!"); g_pHyprpicker->finish(1); }); diff --git a/src/hyprpicker.cpp b/src/hyprpicker.cpp index aaee7e1..3118116 100644 --- a/src/hyprpicker.cpp +++ b/src/hyprpicker.cpp @@ -147,13 +147,17 @@ void CHyprpicker::finish(int code) { void CHyprpicker::recheckACK() { for (auto& ls : m_vLayerSurfaces) { - if (ls->wantsACK) { - ls->wantsACK = false; - ls->pLayerSurface->sendAckConfigure(ls->ACKSerial); + if ((ls->wantsACK || ls->wantsReload) && ls->screenBuffer) { + if (ls->wantsACK) + ls->pLayerSurface->sendAckConfigure(ls->ACKSerial); + ls->wantsACK = false; + ls->wantsReload = false; - const auto MONITORSIZE = ls->screenBuffer && !g_pHyprpicker->m_bNoFractional ? ls->screenBuffer->pixelSize : ls->m_pMonitor->size * ls->m_pMonitor->scale; + const auto MONITORSIZE = + (ls->screenBuffer && !g_pHyprpicker->m_bNoFractional ? ls->m_pMonitor->size * ls->fractionalScale : ls->m_pMonitor->size * ls->m_pMonitor->scale).round(); if (!ls->buffers[0] || ls->buffers[0]->pixelSize != MONITORSIZE) { + Debug::log(TRACE, "making new buffers: size changed to %.0fx%.0f", MONITORSIZE.x, MONITORSIZE.y); ls->buffers[0] = makeShared(MONITORSIZE, WL_SHM_FORMAT_ARGB8888, MONITORSIZE.x * 4); ls->buffers[1] = makeShared(MONITORSIZE, WL_SHM_FORMAT_ARGB8888, MONITORSIZE.x * 4); } @@ -360,6 +364,8 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) { const auto MOUSECOORDSABS = m_vLastCoords.floor() / pSurface->m_pMonitor->size; const auto CLICKPOS = MOUSECOORDSABS * PBUFFER->pixelSize; + Debug::log(TRACE, "renderSurface: scalebufs %.2fx%.2f", SCALEBUFS.x, SCALEBUFS.y); + const auto PATTERNPRE = cairo_pattern_create_for_surface(pSurface->screenBuffer->surface); cairo_pattern_set_filter(PATTERNPRE, CAIRO_FILTER_BILINEAR); cairo_matrix_t matrixPre;