#pragma once #include #include #include #include #include "giomm/file.h" #include "giomm/filemonitor.h" #include "glibmm/refptr.h" struct pollfd; namespace waybar { class CssReloadHelper { public: CssReloadHelper(std::string cssFile, std::function callback); virtual ~CssReloadHelper() = default; virtual void monitorChanges(); protected: std::vector parseImports(const std::string& cssFile); void parseImports(const std::string& cssFile, std::unordered_map& imports); void watchFiles(const std::vector& files); bool handleInotifyEvents(int fd); bool watch(int inotifyFd, pollfd* pollFd); virtual std::string getFileContents(const std::string& filename); virtual std::string findPath(const std::string& filename); void handleFileChange(Glib::RefPtr const& file, Glib::RefPtr const& other_type, Gio::FileMonitorEvent event_type); private: std::string m_cssFile; std::function m_callback; std::vector>> m_fileMonitors; }; } // namespace waybar