Pārlūkot izejas kodu

chore: take a screenshot on each background change so playlists always produce an up to date image

Almamu 7 mēneši atpakaļ
vecāks
revīzija
674c551f91

+ 22 - 6
src/WallpaperEngine/Application/WallpaperApplication.cpp

@@ -195,6 +195,19 @@ ProjectUniquePtr WallpaperApplication::loadBackground (const std::string& bg) {
     auto container = this->setupAssetLocator (bg);
     auto json = WallpaperEngine::Data::JSON::JSON::parse (container->readString ("project.json"));
 
+    // when a background is loaded, reset the screenshot variables
+    // this allows taking screenshots after a background changes
+    // useful for playlists
+    if (this->m_context.settings.screenshot.take) {
+        this->m_nextFrameScreenshot = this->m_context.settings.screenshot.delay;
+
+        if (this->m_videoDriver != nullptr) {
+            this->m_nextFrameScreenshot += this->m_videoDriver->getFrameCounter ();
+        }
+
+        this->m_screenShotTaken = false;
+    }
+
     return WallpaperEngine::Data::Parsers::ProjectParser::parse (json, std::move (container));
 }
 
@@ -813,13 +826,16 @@ void WallpaperApplication::show () {
 
 	this->updatePlaylists ();
 
-	if (!this->m_context.settings.screenshot.take
-	    || m_videoDriver->getFrameCounter () < this->m_context.settings.screenshot.delay) {
-	    continue;
-	}
+        if (!this->m_context.settings.screenshot.take || this->m_screenShotTaken == true) {
+            continue;
+        }
+
+        if (this->m_videoDriver->getFrameCounter () < this->m_nextFrameScreenshot) {
+            continue;
+        }
 
-	this->takeScreenshot (this->m_context.settings.screenshot.path);
-	this->m_context.settings.screenshot.take = false;
+        this->takeScreenshot (this->m_context.settings.screenshot.path);
+        this->m_screenShotTaken = true;
     }
 
     sLog.out ("Stopping");

+ 2 - 0
src/WallpaperEngine/Application/WallpaperApplication.h

@@ -149,6 +149,8 @@ private:
     std::unique_ptr<WallpaperEngine::WebBrowser::WebBrowserContext> m_browserContext = nullptr;
     std::mt19937 m_playlistRng { std::random_device {}() };
     bool m_isPaused = false;
+    bool m_screenShotTaken = false;
+    uint32_t m_nextFrameScreenshot = 0;
     std::chrono::steady_clock::time_point m_pauseStart {};
 };
 } // namespace WallpaperEngine::Application