diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 33faae3..33f36fe 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -201,7 +201,7 @@ void CHyprpaper::ensurePoolBuffersPresent() { auto it = std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [wt = &wt, &m](const std::unique_ptr& el) { auto scale = std::round((m->pCurrentLayerSurface && m->pCurrentLayerSurface->pFractionalScaleInfo ? m->pCurrentLayerSurface->fScale : m->scale) * 120.0) / 120.0; - return el->target == wt->m_szPath && el->pixelSize == m->size * scale; + return el->target == wt->m_szPath && vectorDeltaLessThan(el->pixelSize, m->size * scale, 1); }); if (it == m_vBuffers.end()) { @@ -394,7 +394,7 @@ void CHyprpaper::destroyBuffer(SPoolBuffer* pBuffer) { SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWallpaperTarget) { return std::find_if(m_vBuffers.begin(), m_vBuffers.end(), [&](const std::unique_ptr& el) { auto scale = std::round((pMonitor->pCurrentLayerSurface && pMonitor->pCurrentLayerSurface->pFractionalScaleInfo ? pMonitor->pCurrentLayerSurface->fScale : pMonitor->scale) * 120.0) / 120.0; - return el->target == pWallpaperTarget->m_szPath && el->pixelSize == pMonitor->size * scale; + return el->target == pWallpaperTarget->m_szPath && vectorDeltaLessThan(el->pixelSize, pMonitor->size * scale, 1); })->get(); } diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index 764be6e..cdc94bf 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -6,6 +6,7 @@ #include "helpers/Monitor.hpp" #include "events/Events.hpp" #include "helpers/PoolBuffer.hpp" +#include "helpers/MiscFunctions.hpp" #include "ipc/Socket.hpp" #include diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp new file mode 100644 index 0000000..40a9668 --- /dev/null +++ b/src/helpers/MiscFunctions.cpp @@ -0,0 +1,9 @@ +#include "MiscFunctions.hpp" + +bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta) { + return std::abs(a.x - b.x) < delta && std::abs(a.y - b.y) < delta; +} + +bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta) { + return std::abs(a.x - b.x) < delta.x && std::abs(a.y - b.y) < delta.y; +} diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp new file mode 100644 index 0000000..69d8695 --- /dev/null +++ b/src/helpers/MiscFunctions.hpp @@ -0,0 +1,5 @@ +#pragma once +#include "Vector2D.hpp" + +bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta); +bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta); \ No newline at end of file