summaryrefslogtreecommitdiff
path: root/src/config/ConfigWatcher.hpp
blob: 979456891b7caa6bfaf080d602fb5704f94a3237 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#pragma once
#include "../helpers/memory/Memory.hpp"
#include <vector>
#include <string>
#include <functional>
#include <hyprutils/os/FileDescriptor.hpp>

class CConfigWatcher {
  public:
    CConfigWatcher();
    ~CConfigWatcher() = default;

    struct SConfigWatchEvent {
        std::string file;
    };

    Hyprutils::OS::CFileDescriptor& getInotifyFD();
    void                            setWatchList(const std::vector<std::string>& paths);
    void                            setOnChange(const std::function<void(const SConfigWatchEvent&)>& fn);
    void                            onInotifyEvent();

  private:
    struct SInotifyWatch {
        int         wd = -1;
        std::string file;
    };

    std::function<void(const SConfigWatchEvent&)> m_watchCallback;
    std::vector<SInotifyWatch>                    m_watches;
    Hyprutils::OS::CFileDescriptor                m_inotifyFd;
};

inline UP<CConfigWatcher> g_pConfigWatcher = makeUnique<CConfigWatcher>();