polybar-dwm/include/utils/inotify.hpp
patrick96 0d1db206c6 Remove factory_util unique and shared
Equivalent to std::make_unique and std::make_shared
2021-09-21 21:43:27 +02:00

49 lines
913 B
C++

#pragma once
#include <poll.h>
#include <sys/inotify.h>
#include <cstdio>
#include "common.hpp"
#include "utils/factory.hpp"
POLYBAR_NS
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) const;
unique_ptr<inotify_event> get_event() const;
unique_ptr<inotify_event> await_match() const;
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};
};
namespace inotify_util {
template <typename... Args>
decltype(auto) make_watch(Args&&... args) {
return std::make_unique<inotify_watch>(forward<Args>(args)...);
}
} // namespace inotify_util
POLYBAR_NS_END