From 9712f20140a12b82b00b8becab8aab83674e9a4c Mon Sep 17 00:00:00 2001 From: Almamu Date: Tue, 21 May 2024 14:14:03 +0200 Subject: [PATCH] fix: improve how default background is determinated, hopefully improves #219 --- .../Application/CApplicationContext.cpp | 5 +++++ .../Application/CWallpaperApplication.cpp | 21 ++++--------------- .../Application/CWallpaperApplication.h | 6 ------ src/WallpaperEngine/Render/CTextureCache.cpp | 13 ------------ 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/WallpaperEngine/Application/CApplicationContext.cpp b/src/WallpaperEngine/Application/CApplicationContext.cpp index bb116eb..0d03566 100644 --- a/src/WallpaperEngine/Application/CApplicationContext.cpp +++ b/src/WallpaperEngine/Application/CApplicationContext.cpp @@ -107,6 +107,11 @@ CApplicationContext::CApplicationContext (int argc, char* argv []) { // to have any value this->settings.general.screenBackgrounds [lastScreen] = translateBackground (optarg); this->settings.general.screenScalings [lastScreen] = this->settings.render.window.scalingMode; + + // update default background if not set + if (this->settings.general.defaultBackground.empty()) { + this->settings.general.defaultBackground = translateBackground (optarg); + } break; case 'o': { diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index a70d2fb..bae5ba8 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -27,7 +27,6 @@ namespace WallpaperEngine::Application { CWallpaperApplication::CWallpaperApplication (CApplicationContext& context, WallpaperEngine::WebBrowser::CWebBrowserContext& browserContext) : m_context (context), - m_defaultBackground (nullptr), m_browserContext (browserContext) { this->loadBackgrounds (); this->setupProperties (); @@ -168,17 +167,12 @@ void CWallpaperApplication::setupContainer (CCombinedContainer& container, const } void CWallpaperApplication::loadBackgrounds () { - // load default background if specified - if (!this->m_context.settings.general.defaultBackground.empty ()) { - this->m_defaultBackground = this->loadBackground (this->m_context.settings.general.defaultBackground); - } - - for (const auto& [background, path] : this->m_context.settings.general.screenBackgrounds) { - // screens with no background should use the default + for (const auto& [screen, path] : this->m_context.settings.general.screenBackgrounds) { + // screens with no screen should use the default if (path.empty ()) { - this->m_backgrounds [background] = this->m_defaultBackground; + this->m_backgrounds [screen] = this->loadBackground (this->m_context.settings.general.defaultBackground); } else { - this->m_backgrounds [background] = this->loadBackground (path); + this->m_backgrounds [screen] = this->loadBackground (path); } } } @@ -211,9 +205,6 @@ void CWallpaperApplication::setupPropertiesForProject (const Core::CProject* pro void CWallpaperApplication::setupProperties () { for (const auto& [backgrounc, info] : this->m_backgrounds) this->setupPropertiesForProject (info); - - if (this->m_defaultBackground != nullptr) - this->setupPropertiesForProject (this->m_defaultBackground); } void CWallpaperApplication::takeScreenshot (const std::filesystem::path& filename, FREE_IMAGE_FORMAT format) { @@ -419,10 +410,6 @@ const std::map& CWallpaperApplication::getBackgrou return this->m_backgrounds; } -Core::CProject* CWallpaperApplication::getDefaultBackground () const { - return this->m_defaultBackground; -} - CApplicationContext& CWallpaperApplication::getContext () const { return this->m_context; } diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.h b/src/WallpaperEngine/Application/CWallpaperApplication.h index d0bca68..c488ad3 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.h +++ b/src/WallpaperEngine/Application/CWallpaperApplication.h @@ -59,10 +59,6 @@ class CWallpaperApplication { * @return Maps screens to loaded backgrounds */ [[nodiscard]] const std::map& getBackgrounds () const; - /** - * @return The default background to use if no specific project is loaded - */ - [[nodiscard]] Core::CProject* getDefaultBackground () const; /** * @return The current application context */ @@ -114,8 +110,6 @@ class CWallpaperApplication { */ void takeScreenshot (const std::filesystem::path& filename, FREE_IMAGE_FORMAT format); - /** The default background to display if no specific background was loaded */ - Core::CProject* m_defaultBackground; /** The application context that contains the current app settings */ CApplicationContext& m_context; /** Maps screens to backgrounds */ diff --git a/src/WallpaperEngine/Render/CTextureCache.cpp b/src/WallpaperEngine/Render/CTextureCache.cpp index ced3347..1ab8244 100644 --- a/src/WallpaperEngine/Render/CTextureCache.cpp +++ b/src/WallpaperEngine/Render/CTextureCache.cpp @@ -27,19 +27,6 @@ const ITexture* CTextureCache::resolve (const std::string& filename) { } } - if (this->getContext ().getApp ().getDefaultBackground () != nullptr) { - try { - const ITexture* texture = - this->getContext ().getApp ().getDefaultBackground ()->getContainer ()->readTexture (filename); - - this->store (filename, texture); - - return texture; - } catch (CAssetLoadException&) { - // ignored, this happens if we're looking at the wrong background - } - } - throw CAssetLoadException (filename, "Cannot find file"); }