2025-01-19 15:39:19 +01:00
|
|
|
#pragma once
|
2025-01-23 21:55:41 +01:00
|
|
|
#include "../helpers/memory/Memory.hpp"
|
2025-01-19 15:39:19 +01:00
|
|
|
#include <vector>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <functional>
|
2025-01-30 12:30:12 +01:00
|
|
|
#include <hyprutils/os/FileDescriptor.hpp>
|
2025-01-19 15:39:19 +01:00
|
|
|
|
|
|
|
|
class CConfigWatcher {
|
|
|
|
|
public:
|
|
|
|
|
CConfigWatcher();
|
2025-01-30 12:30:12 +01:00
|
|
|
~CConfigWatcher() = default;
|
2025-01-19 15:39:19 +01:00
|
|
|
|
|
|
|
|
struct SConfigWatchEvent {
|
|
|
|
|
std::string file;
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-30 12:30:12 +01:00
|
|
|
Hyprutils::OS::CFileDescriptor& getInotifyFD();
|
|
|
|
|
void setWatchList(const std::vector<std::string>& paths);
|
|
|
|
|
void setOnChange(const std::function<void(const SConfigWatchEvent&)>& fn);
|
|
|
|
|
void onInotifyEvent();
|
2025-01-19 15:39:19 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
struct SInotifyWatch {
|
|
|
|
|
int wd = -1;
|
|
|
|
|
std::string file;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::function<void(const SConfigWatchEvent&)> m_watchCallback;
|
|
|
|
|
std::vector<SInotifyWatch> m_watches;
|
2025-01-30 12:30:12 +01:00
|
|
|
Hyprutils::OS::CFileDescriptor m_inotifyFd;
|
2025-01-19 15:39:19 +01:00
|
|
|
};
|
|
|
|
|
|
2025-01-30 12:30:12 +01:00
|
|
|
inline UP<CConfigWatcher> g_pConfigWatcher = makeUnique<CConfigWatcher>();
|