2016-06-15 03:32:35 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-11-12 14:36:22 +00:00
|
|
|
#include <poll.h>
|
2016-11-25 07:42:31 +00:00
|
|
|
#include <sys/inotify.h>
|
2021-09-21 19:15:49 +00:00
|
|
|
|
2016-06-15 03:32:35 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-06-15 03:32:35 +00:00
|
|
|
|
|
|
|
struct inotify_event {
|
2022-03-06 16:44:48 +00:00
|
|
|
bool is_valid = false;
|
2016-06-15 03:32:35 +00:00
|
|
|
string filename;
|
|
|
|
bool is_dir;
|
|
|
|
int wd = 0;
|
|
|
|
int cookie = 0;
|
|
|
|
int mask = 0;
|
|
|
|
};
|
|
|
|
|
2016-12-20 04:05:43 +00: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 09:37:14 +00:00
|
|
|
bool poll(int wait_ms = 1000) const;
|
2022-03-06 16:44:48 +00:00
|
|
|
inotify_event get_event() const;
|
2016-12-20 04:05:43 +00:00
|
|
|
const string path() const;
|
|
|
|
int get_file_descriptor() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
string m_path;
|
2016-12-26 09:37:14 +00:00
|
|
|
int m_fd{-1};
|
|
|
|
int m_wd{-1};
|
|
|
|
int m_mask{0};
|
2016-12-20 04:05:43 +00:00
|
|
|
};
|
2016-06-15 03:32:35 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|