1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00
polybar/include/utils/inotify.hpp

50 lines
904 B
C++
Raw Normal View History

2016-06-14 23:32:35 -04:00
#pragma once
#include <poll.h>
2016-11-25 02:42:31 -05:00
#include <sys/inotify.h>
2016-06-14 23:32:35 -04:00
#include <cstdio>
#include "common.hpp"
#include "utils/factory.hpp"
2016-06-14 23:32:35 -04:00
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;
};
class inotify_watch {
public:
explicit inotify_watch(string path);
~inotify_watch();
void attach(int mask = IN_MODIFY);
void remove(bool force = false);
bool poll(int wait_ms = 1000);
unique_ptr<inotify_event> get_event();
bool await_match();
const string path() const;
int get_file_descriptor() const;
protected:
string m_path;
int m_fd = -1;
int m_wd = -1;
int m_mask = 0;
};
2016-06-14 23:32:35 -04:00
namespace inotify_util {
bool match(const inotify_event* evt, int mask);
template <typename... Args>
decltype(auto) make_watch(Args&&... args) {
return factory_util::unique<inotify_watch>(forward<Args>(args)...);
}
2016-06-14 23:32:35 -04:00
}
2016-11-19 00:22:44 -05:00
POLYBAR_NS_END