2024-01-22 02:23:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <string>
|
2024-01-28 22:44:25 +00:00
|
|
|
#include <unordered_map>
|
2024-01-22 02:23:46 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2024-01-22 04:49:13 +00:00
|
|
|
#include "giomm/file.h"
|
|
|
|
#include "giomm/filemonitor.h"
|
2024-01-28 22:44:25 +00:00
|
|
|
#include "glibmm/refptr.h"
|
2024-01-22 04:49:13 +00:00
|
|
|
|
2024-01-22 02:23:46 +00:00
|
|
|
struct pollfd;
|
|
|
|
|
|
|
|
namespace waybar {
|
|
|
|
class CssReloadHelper {
|
|
|
|
public:
|
|
|
|
CssReloadHelper(std::string cssFile, std::function<void()> callback);
|
|
|
|
|
|
|
|
virtual void monitorChanges();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::vector<std::string> parseImports(const std::string& cssFile);
|
|
|
|
|
2024-01-28 22:44:25 +00:00
|
|
|
void parseImports(const std::string& cssFile, std::unordered_map<std::string, bool>& imports);
|
2024-01-22 02:23:46 +00:00
|
|
|
|
|
|
|
void watchFiles(const std::vector<std::string>& files);
|
|
|
|
|
|
|
|
bool handleInotifyEvents(int fd);
|
|
|
|
|
2024-01-28 22:44:25 +00:00
|
|
|
bool watch(int inotifyFd, pollfd* pollFd);
|
2024-01-22 02:23:46 +00:00
|
|
|
|
|
|
|
virtual std::string getFileContents(const std::string& filename);
|
|
|
|
|
|
|
|
virtual std::string findPath(const std::string& filename);
|
|
|
|
|
2024-01-28 22:44:25 +00:00
|
|
|
void handleFileChange(Glib::RefPtr<Gio::File> const& file,
|
|
|
|
Glib::RefPtr<Gio::File> const& other_type,
|
|
|
|
Gio::FileMonitorEvent event_type);
|
2024-01-22 04:49:13 +00:00
|
|
|
|
2024-01-22 02:23:46 +00:00
|
|
|
private:
|
|
|
|
std::string m_cssFile;
|
2024-01-22 04:49:13 +00:00
|
|
|
|
2024-01-22 02:23:46 +00:00
|
|
|
std::function<void()> m_callback;
|
2024-01-22 04:49:13 +00:00
|
|
|
|
|
|
|
std::vector<std::tuple<Glib::RefPtr<Gio::FileMonitor>>> m_fileMonitors;
|
2024-01-22 02:23:46 +00:00
|
|
|
};
|
|
|
|
} // namespace waybar
|