node editor: dragging!
[zinnia.git] / src / notify.h
blobb01a1917bc786f68cff0f3ce0ee6675725be0fdf
1 #include <map>
2 #include <cerrno>
3 #include <Inotify.h>
4 #include <FileSystemEvent.h>
5 #include <experimental/filesystem>
6 #include "project.h"
8 namespace fs = std::experimental::filesystem;
10 #define MAX_WDS 16
12 class NotifyService {
13 public:
14 NotifyService() : inotify{IN_MODIFY | IN_MOVED_TO} {}
16 void watch(std::shared_ptr<Project> project) {
17 inotify.watchDirectoryRecursively(project->basepath);
18 projects[project->basepath]= project;
21 void _poll() {
22 auto event = inotify.nb_getNextEvent();
23 if (event) {
24 if (event->recursive_root_path) {
25 auto path = *event->recursive_root_path;
26 if (projects.find(path) != projects.end()) {
27 std::cout << "=== reloading shaders ===\n";
28 projects[path]->reload_shaders();
33 private:
34 Inotify inotify;
36 std::map<fs::path, std::shared_ptr<Project>> projects;