66#include " ../ipc/IPC.hpp"
77#include " ../config/WallpaperMatcher.hpp"
88
9+ #include < algorithm>
10+ #include < random>
911#include < hyprtoolkit/core/Output.hpp>
1012
1113#include < hyprutils/string/String.hpp>
@@ -24,14 +26,23 @@ static std::string_view pruneDesc(const std::string_view& sv) {
2426
2527class CWallpaperTarget ::CImagesData {
2628 public:
27- CImagesData (Hyprtoolkit::eImageFitMode fitMode, const std::vector<std::string>& images, const int timeout = 0 ) :
28- fitMode (fitMode), images(images), timeout(timeout > 0 ? timeout : 30 ) {}
29+ CImagesData (Hyprtoolkit::eImageFitMode fitMode, std::vector<std::string> images, const int timeout = 0 , std::string order = " default " ) :
30+ fitMode (fitMode), images(std::move( images)), order(std::move(order) ), timeout(timeout > 0 ? timeout : 30 ) {}
2931
3032 const Hyprtoolkit::eImageFitMode fitMode;
31- const std::vector<std::string> images;
33+ std::vector<std::string> images;
34+ const std::string order;
3235 const int timeout;
3336
3437 std::string nextImage () {
38+ if (order == " random-shuffle" && current + 1 >= images.size ()) {
39+ std::random_device rd;
40+ std::mt19937 g (rd ());
41+ std::shuffle (images.begin (), images.end (), g);
42+ current = 0 ;
43+ return images[current];
44+ }
45+
3546 current = (current + 1 ) % images.size ();
3647 return images[current];
3748 }
@@ -41,7 +52,7 @@ class CWallpaperTarget::CImagesData {
4152};
4253
4354CWallpaperTarget::CWallpaperTarget (SP <Hyprtoolkit::IBackend> backend, SP <Hyprtoolkit::IOutput> output, const std::vector<std::string>& path, Hyprtoolkit::eImageFitMode fitMode,
44- const int timeout) : m_monitorName(output->port ()), m_backend(backend) {
55+ const int timeout, const std::string& order ) : m_monitorName(output->port ()), m_backend(backend) {
4556 static const auto SPLASH_REPLY = HyprlandSocket::getFromSocket (" /splash" );
4657
4758 static const auto PENABLESPLASH = Hyprlang::CSimpleConfigValue<Hyprlang::INT >(g_config->hyprlang (), " splash" );
@@ -79,7 +90,7 @@ CWallpaperTarget::CWallpaperTarget(SP<Hyprtoolkit::IBackend> backend, SP<Hyprtoo
7990 m_image->setPositionFlag (Hyprtoolkit::IElement::HT_POSITION_FLAG_CENTER , true );
8091
8192 if (path.size () > 1 ) {
82- m_imagesData = makeUnique<CImagesData>(fitMode, path, timeout);
93+ m_imagesData = makeUnique<CImagesData>(fitMode, std::vector<std::string>( path) , timeout, order );
8394 m_timer =
8495 m_backend->addTimer (std::chrono::milliseconds (std::chrono::seconds (m_imagesData->timeout )), [this ](ASP <Hyprtoolkit::CTimer> self, void *) { onRepeatTimer (); }, nullptr );
8596 }
@@ -228,7 +239,7 @@ void CUI::targetChanged(const SP<Hyprtoolkit::IOutput>& mon) {
228239
229240 std::erase_if (m_targets, [&mon](const auto & e) { return e->m_monitorName == mon->port (); });
230241
231- m_targets.emplace_back (makeShared<CWallpaperTarget>(m_backend, mon, TARGET ->get ().paths , toFitMode (TARGET ->get ().fitMode ), TARGET ->get ().timeout ));
242+ m_targets.emplace_back (makeShared<CWallpaperTarget>(m_backend, mon, TARGET ->get ().paths , toFitMode (TARGET ->get ().fitMode ), TARGET ->get ().timeout , TARGET -> get (). order ));
232243}
233244
234245const std::vector<SP <CWallpaperTarget>>& CUI::targets () {
0 commit comments