1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-03 04:33:30 -05:00
polybar/include/utils/inotify.hpp
Chase Geigle 47a2cce03d fix: Ensure reloading when IN_IGNORED fired on config (#371)
This fixes a "bug" where polybar wouldn't reload on a configuration
file change on some configurations of vim, which don't actually issue
any IN_MODIFY events because they choose to move the file, replace it
with a new one, and then delete the file instead.

To work around this, we now also listen for IN_IGNORED which fires when
the file we are watching is destroyed. When this happens, we re-attach
the configuration file watcher to the new file and reload.
2017-01-24 07:10:55 +01:00

47 lines
889 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 factory_util::unique<inotify_watch>(forward<Args>(args)...);
}
}
POLYBAR_NS_END