Skip to content

Commit

Permalink
fix: improve how default background is determinated, hopefully improves
Browse files Browse the repository at this point in the history
  • Loading branch information
Almamu committed May 21, 2024
1 parent cdfa4ff commit 9712f20
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
5 changes: 5 additions & 0 deletions src/WallpaperEngine/Application/CApplicationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
21 changes: 4 additions & 17 deletions src/WallpaperEngine/Application/CWallpaperApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -419,10 +410,6 @@ const std::map<std::string, Core::CProject*>& CWallpaperApplication::getBackgrou
return this->m_backgrounds;
}

Core::CProject* CWallpaperApplication::getDefaultBackground () const {
return this->m_defaultBackground;
}

CApplicationContext& CWallpaperApplication::getContext () const {
return this->m_context;
}
Expand Down
6 changes: 0 additions & 6 deletions src/WallpaperEngine/Application/CWallpaperApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class CWallpaperApplication {
* @return Maps screens to loaded backgrounds
*/
[[nodiscard]] const std::map<std::string, Core::CProject*>& getBackgrounds () const;
/**
* @return The default background to use if no specific project is loaded
*/
[[nodiscard]] Core::CProject* getDefaultBackground () const;
/**
* @return The current application context
*/
Expand Down Expand Up @@ -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 */
Expand Down
13 changes: 0 additions & 13 deletions src/WallpaperEngine/Render/CTextureCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down

0 comments on commit 9712f20

Please sign in to comment.