From 1c009491b5a39af59f4d35b827135e2bb6d33026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Lewandowski?= <49685661+FakeMichau@users.noreply.github.com> Date: Fri, 13 Oct 2023 22:23:24 +0200 Subject: [PATCH] render: Always draw a black background first (#100) --- src/Hyprpaper.cpp | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 935f345..9e45991 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -481,41 +481,24 @@ 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, DIMENSIONS.x, DIMENSIONS.y); - - cairo_fill(PCAIRO); - - cairo_surface_flush(PBUFFER->surface); - } + // always draw a black background behind the wallpaper + cairo_set_source_rgb(PCAIRO, 0, 0, 0); + cairo_rectangle(PCAIRO, 0, 0, DIMENSIONS.x, DIMENSIONS.y); + cairo_fill(PCAIRO); + cairo_surface_flush(PBUFFER->surface); // get scale // we always do cover - float scale; + double scale; Vector2D origin; - if (!CONTAIN) { - if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) { - scale = DIMENSIONS.x / PWALLPAPERTARGET->m_vSize.x; - - origin.y = -(PWALLPAPERTARGET->m_vSize.y * scale - DIMENSIONS.y) / 2.f / scale; - - } else { - scale = DIMENSIONS.y / PWALLPAPERTARGET->m_vSize.y; - - origin.x = -(PWALLPAPERTARGET->m_vSize.x * scale - DIMENSIONS.x) / 2.f / scale; - } + const bool LOWASPECTRATIO = pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y; + if ((CONTAIN && !LOWASPECTRATIO) || (!CONTAIN && LOWASPECTRATIO)) { + scale = DIMENSIONS.x / PWALLPAPERTARGET->m_vSize.x; + origin.y = -(PWALLPAPERTARGET->m_vSize.y * scale - DIMENSIONS.y) / 2.0 / scale; } else { - if (pMonitor->size.x / pMonitor->size.y > PWALLPAPERTARGET->m_vSize.x / PWALLPAPERTARGET->m_vSize.y) { - scale = (DIMENSIONS.y) / PWALLPAPERTARGET->m_vSize.y; - - origin.x = (DIMENSIONS.x - PWALLPAPERTARGET->m_vSize.x * scale) / 2.0 / scale; - } else { - scale = (DIMENSIONS.x) / PWALLPAPERTARGET->m_vSize.x; - - origin.y = (DIMENSIONS.y - PWALLPAPERTARGET->m_vSize.y * scale) / 2.0 / scale; - } + scale = DIMENSIONS.y / PWALLPAPERTARGET->m_vSize.y; + origin.x = -(PWALLPAPERTARGET->m_vSize.x * scale - DIMENSIONS.x) / 2.0 / 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);