11#include " UI.hpp"
2+ #include " ../defines.hpp"
23#include " ../helpers/Logger.hpp"
34#include " ../ipc/HyprlandSocket.hpp"
45#include " ../ipc/IPC.hpp"
@@ -12,13 +13,34 @@ CUI::~CUI() {
1213 m_targets.clear ();
1314}
1415
15- CWallpaperTarget::CWallpaperTarget (SP <Hyprtoolkit::IOutput> output, const std::string_view& path, Hyprtoolkit::eImageFitMode fitMode) : m_monitorName(output->port ()) {
16+ struct CWallpaperTarget ::ImagesData {
17+ public:
18+ ImagesData (Hyprtoolkit::eImageFitMode fitMode, const std::vector<std::string>& images, const int timeout = 0 ) :
19+ fitMode (fitMode), images(images), timeout(timeout > 0 ? timeout : 30 ) {}
20+
21+ const Hyprtoolkit::eImageFitMode fitMode;
22+ const std::vector<std::string> images;
23+ const int timeout;
24+
25+ std::string nextImage () {
26+ current = (current + 1 ) % images.size ();
27+ return images[current];
28+ }
29+
30+ private:
31+ std::size_t current = 0 ;
32+ };
33+
34+ CWallpaperTarget::CWallpaperTarget (SP <Hyprtoolkit::IBackend> backend, SP <Hyprtoolkit::IOutput> output, const std::vector<std::string>& path, Hyprtoolkit::eImageFitMode fitMode,
35+ const int timeout) : m_monitorName(output->port ()), m_backend(backend) {
1636 static const auto SPLASH_REPLY = HyprlandSocket::getFromSocket (" /splash" );
1737
1838 static const auto PENABLESPLASH = Hyprlang::CSimpleConfigValue<Hyprlang::INT >(g_config->hyprlang (), " splash" );
1939 static const auto PSPLASHOFFSET = Hyprlang::CSimpleConfigValue<Hyprlang::INT >(g_config->hyprlang (), " splash_offset" );
2040 static const auto PSPLASHALPHA = Hyprlang::CSimpleConfigValue<Hyprlang::FLOAT >(g_config->hyprlang (), " splash_opacity" );
2141
42+ ASSERT (path.size () > 0 );
43+
2244 m_window = Hyprtoolkit::CWindowBuilder::begin ()
2345 ->type (Hyprtoolkit::HT_WINDOW_LAYER )
2446 ->prefferedOutput (output)
@@ -33,9 +55,10 @@ CWallpaperTarget::CWallpaperTarget(SP<Hyprtoolkit::IOutput> output, const std::s
3355 ->size ({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , {1 , 1 }})
3456 ->color ([] { return Hyprtoolkit::CHyprColor{0xFF000000 }; })
3557 ->commence ();
36- m_null = Hyprtoolkit::CNullBuilder::begin ()->size ({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , {1 , 1 }})->commence ();
58+ m_null = Hyprtoolkit::CNullBuilder::begin ()->size ({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , {1 , 1 }})->commence ();
59+
3760 m_image = Hyprtoolkit::CImageBuilder::begin ()
38- ->path (std::string{path})
61+ ->path (std::string{path. front () })
3962 ->size ({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , {1 .F , 1 .F }})
4063 ->sync (true )
4164 ->fitMode (fitMode)
@@ -44,6 +67,12 @@ CWallpaperTarget::CWallpaperTarget(SP<Hyprtoolkit::IOutput> output, const std::s
4467 m_image->setPositionMode (Hyprtoolkit::IElement::HT_POSITION_ABSOLUTE );
4568 m_image->setPositionFlag (Hyprtoolkit::IElement::HT_POSITION_FLAG_CENTER , true );
4669
70+ if (path.size () > 1 ) {
71+ m_imagesData = makeUnique<ImagesData>(fitMode, path, timeout);
72+ m_timer =
73+ m_backend->addTimer (std::chrono::milliseconds (std::chrono::seconds (m_imagesData->timeout )), [this ](ASP <Hyprtoolkit::CTimer> self, void *) { onRepeatTimer (); }, nullptr );
74+ }
75+
4776 m_window->m_rootElement ->addChild (m_bg);
4877 m_window->m_rootElement ->addChild (m_null);
4978 m_null->addChild (m_image);
@@ -68,6 +97,30 @@ CWallpaperTarget::CWallpaperTarget(SP<Hyprtoolkit::IOutput> output, const std::s
6897 m_window->open ();
6998}
7099
100+ CWallpaperTarget::~CWallpaperTarget () {
101+ if (m_timer && !m_timer->passed ())
102+ m_timer->cancel ();
103+ }
104+
105+ void CWallpaperTarget::onRepeatTimer () {
106+
107+ ASSERT (m_imagesData);
108+
109+ m_null->removeChild (m_image);
110+ m_image = Hyprtoolkit::CImageBuilder::begin ()
111+ ->path (m_imagesData->nextImage ())
112+ ->size ({Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , Hyprtoolkit::CDynamicSize::HT_SIZE_PERCENT , {1 .F , 1 .F }})
113+ ->sync (true )
114+ ->fitMode (m_imagesData->fitMode )
115+ ->commence ();
116+ m_image->setPositionMode (Hyprtoolkit::IElement::HT_POSITION_ABSOLUTE );
117+ m_image->setPositionFlag (Hyprtoolkit::IElement::HT_POSITION_FLAG_CENTER , true );
118+ m_null->addChild (m_image);
119+
120+ m_timer =
121+ m_backend->addTimer (std::chrono::milliseconds (std::chrono::seconds (m_imagesData->timeout )), [this ](ASP <Hyprtoolkit::CTimer> self, void *) { onRepeatTimer (); }, nullptr );
122+ }
123+
71124void CUI::registerOutput (const SP <Hyprtoolkit::IOutput>& mon) {
72125 g_matcher->registerOutput (mon->port ());
73126 if (IPC ::g_IPCSocket)
@@ -158,5 +211,5 @@ void CUI::targetChanged(const SP<Hyprtoolkit::IOutput>& mon) {
158211
159212 std::erase_if (m_targets, [&mon](const auto & e) { return e->m_monitorName == mon->port (); });
160213
161- m_targets.emplace_back (makeShared<CWallpaperTarget>(mon, TARGET ->get ().path , toFitMode (TARGET ->get ().fitMode )));
214+ m_targets.emplace_back (makeShared<CWallpaperTarget>(m_backend, mon, TARGET ->get ().paths , toFitMode (TARGET ->get ().fitMode ), TARGET -> get (). timeout ));
162215}
0 commit comments