From 036bf93bf4d94e0ba6f6f95645a48d47db6ce953 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 3 Aug 2022 18:06:33 +0200 Subject: [PATCH] added contain: --- src/Hyprpaper.cpp | 35 ++++++++++++++++++++++++++++------- src/Hyprpaper.hpp | 5 +++++ src/config/ConfigManager.cpp | 8 ++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index ec212ad..95c07f4 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -250,8 +250,6 @@ void CHyprpaper::clearWallpaperFromMonitor(const std::string& monname) { PMONITOR->wantsReload = false; PMONITOR->initialized = false; PMONITOR->readyForLS = true; - - } } @@ -386,6 +384,7 @@ SPoolBuffer* CHyprpaper::getPoolBuffer(SMonitor* pMonitor, CWallpaperTarget* pWa void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) { const auto PWALLPAPERTARGET = m_mMonitorActiveWallpaperTargets[pMonitor]; + const auto CONTAIN = m_mMonitorWallpaperRenderData[pMonitor->name].contain; if (!PWALLPAPERTARGET) { Debug::log(CRIT, "wallpaper target null in render??"); @@ -412,19 +411,41 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) { cairo_paint(PCAIRO); cairo_restore(PCAIRO); + if (CONTAIN) { + cairo_set_source_rgb(PCAIRO, 0, 0, 0); + cairo_rectangle(PCAIRO, 0, 0, pMonitor->size.x * pMonitor->scale, pMonitor->size.y * pMonitor->scale); + + cairo_fill(PCAIRO); + + cairo_surface_flush(PBUFFER->surface); + } + // get scale // we always do cover float scale; Vector2D origin; - if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) { - scale = pMonitor->size.x * pMonitor->scale / PWALLPAPERTARGET->m_vSize.x; - origin.y = - (PWALLPAPERTARGET->m_vSize.y * scale - pMonitor->size.y * pMonitor->scale) / 2.f / scale; + if (!CONTAIN) { + if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) { + scale = pMonitor->size.x * pMonitor->scale / PWALLPAPERTARGET->m_vSize.x; + origin.y = -(PWALLPAPERTARGET->m_vSize.y * scale - pMonitor->size.y * pMonitor->scale) / 2.f / scale; + + } else { + scale = pMonitor->size.y * pMonitor->scale / PWALLPAPERTARGET->m_vSize.y; + + origin.x = -(PWALLPAPERTARGET->m_vSize.x * scale - pMonitor->size.x * pMonitor->scale) / 2.f / scale; + } } else { - scale = pMonitor->size.y * pMonitor->scale / PWALLPAPERTARGET->m_vSize.y; + if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) { + scale = (pMonitor->size.y * pMonitor->scale) / PWALLPAPERTARGET->m_vSize.y; - origin.x = - (PWALLPAPERTARGET->m_vSize.x * scale - pMonitor->size.x * pMonitor->scale) / 2.f / scale; + origin.x = (pMonitor->size.x * pMonitor->scale - PWALLPAPERTARGET->m_vSize.x * scale); + } else { + scale = (pMonitor->size.x * pMonitor->scale) / PWALLPAPERTARGET->m_vSize.x; + + origin.y = (pMonitor->size.y * pMonitor->scale - PWALLPAPERTARGET->m_vSize.y * scale); + } } Debug::log(LOG, "Image data for %s: %s at [%.2f, %.2f], scale: %.2f (original image size: [%i, %i])", pMonitor->name.c_str(), PWALLPAPERTARGET->m_szPath.c_str(), origin.x, origin.y, scale, (int)PWALLPAPERTARGET->m_vSize.x, (int)PWALLPAPERTARGET->m_vSize.y); diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index df511e8..0dad476 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -9,6 +9,10 @@ #include "ipc/Socket.hpp" #include +struct SWallpaperRenderData { + bool contain = false; +}; + class CHyprpaper { public: // important @@ -24,6 +28,7 @@ public: std::unordered_map m_mWallpaperTargets; std::unordered_map m_mMonitorActiveWallpapers; + std::unordered_map m_mMonitorWallpaperRenderData; std::unordered_map m_mMonitorActiveWallpaperTargets; std::vector> m_vBuffers; std::vector> m_vMonitors; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4617b89..357b625 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -110,11 +110,18 @@ void CConfigManager::handleWallpaper(const std::string& COMMAND, const std::stri auto MONITOR = VALUE.substr(0, VALUE.find_first_of(',')); auto WALLPAPER = VALUE.substr(VALUE.find_first_of(',') + 1); + bool contain = false; + if (WALLPAPER[0] == '~') { static const char* const ENVHOME = getenv("HOME"); WALLPAPER = std::string(ENVHOME) + WALLPAPER.substr(1); } + if (WALLPAPER.find("contain:") == 0) { + WALLPAPER = WALLPAPER.substr(8); + contain = true; + } + if (!std::filesystem::exists(WALLPAPER)) { parseError = "wallpaper failed (no such file)"; return; @@ -127,6 +134,7 @@ void CConfigManager::handleWallpaper(const std::string& COMMAND, const std::stri g_pHyprpaper->clearWallpaperFromMonitor(MONITOR); g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR] = WALLPAPER; + g_pHyprpaper->m_mMonitorWallpaperRenderData[MONITOR].contain = contain; } void CConfigManager::handlePreload(const std::string& COMMAND, const std::string& VALUE) {