2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-12 09:36:22 -05:00
|
|
|
#include <poll.h>
|
2016-11-25 02:42:31 -05:00
|
|
|
#include <sys/inotify.h>
|
2021-09-21 15:15:49 -04:00
|
|
|
|
2016-06-14 23:32:35 -04:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-06-14 23:32:35 -04:00
|
|
|
|
|
|
|
struct inotify_event {
|
|
|
|
string filename;
|
|
|
|
bool is_dir;
|
|
|
|
int wd = 0;
|
|
|
|
int cookie = 0;
|
|
|
|
int mask = 0;
|
|
|
|
};
|
|
|
|
|
2016-12-19 23:05:43 -05:00
|
|
|
class inotify_watch {
|
|
|
|
public:
|
|
|
|
explicit inotify_watch(string path);
|
|
|
|
~inotify_watch();
|
|
|
|
|
|
|
|
void attach(int mask = IN_MODIFY);
|
|
|
|
void remove(bool force = false);
|
2016-12-26 04:37:14 -05:00
|
|
|
bool poll(int wait_ms = 1000) const;
|
|
|
|
unique_ptr<inotify_event> get_event() const;
|
2017-01-24 01:10:55 -05:00
|
|
|
unique_ptr<inotify_event> await_match() const;
|
2016-12-19 23:05:43 -05:00
|
|
|
const string path() const;
|
|
|
|
int get_file_descriptor() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
string m_path;
|
2016-12-26 04:37:14 -05:00
|
|
|
int m_fd{-1};
|
|
|
|
int m_wd{-1};
|
|
|
|
int m_mask{0};
|
2016-12-19 23:05:43 -05:00
|
|
|
};
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-12-19 23:05:43 -05:00
|
|
|
namespace inotify_util {
|
|
|
|
template <typename... Args>
|
|
|
|
decltype(auto) make_watch(Args&&... args) {
|
2021-09-21 15:15:49 -04:00
|
|
|
return std::make_unique<inotify_watch>(forward<Args>(args)...);
|
2016-12-19 23:05:43 -05:00
|
|
|
}
|
2021-09-21 15:15:49 -04:00
|
|
|
} // namespace inotify_util
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|