2016-06-14 23:32:35 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <sys/inotify.h>
|
2016-11-12 09:36:22 -05:00
|
|
|
#include <poll.h>
|
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-11-02 15:22:45 -04:00
|
|
|
namespace inotify_util {
|
|
|
|
using event_t = inotify_event;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
class inotify_watch {
|
|
|
|
public:
|
|
|
|
explicit inotify_watch(string path) : m_path(path) {}
|
|
|
|
~inotify_watch() noexcept;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void attach(int mask = IN_MODIFY);
|
|
|
|
void remove();
|
|
|
|
bool poll(int wait_ms = 1000);
|
|
|
|
unique_ptr<event_t> get_event();
|
|
|
|
const string path() const;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
protected:
|
|
|
|
string m_path;
|
|
|
|
int m_fd = -1;
|
|
|
|
int m_wd = -1;
|
|
|
|
};
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
using watch_t = unique_ptr<inotify_watch>;
|
2016-06-14 23:32:35 -04:00
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
watch_t make_watch(string path);
|
2016-06-14 23:32:35 -04:00
|
|
|
}
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|