File: inotify.hpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (44 lines) | stat: -rw-r--r-- 805 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include <poll.h>
#include <sys/inotify.h>

#include <cstdio>

#include "common.hpp"
#include "utils/mixins.hpp"

POLYBAR_NS

struct inotify_event {
  bool is_valid = false;
  string filename;
  bool is_dir;
  int wd = 0;
  int cookie = 0;
  int mask = 0;
};

class inotify_watch : public non_copyable_mixin {
 public:
  explicit inotify_watch(string path);
  ~inotify_watch();

  inotify_watch(inotify_watch&& other) noexcept;
  inotify_watch& operator=(inotify_watch&& other) noexcept;

  void attach(int mask = IN_MODIFY);
  void remove(bool force = false);
  bool poll(int wait_ms = 1000) const;
  inotify_event get_event() 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};
};

POLYBAR_NS_END