File: input.hpp

package info (click to toggle)
ares 134%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 34,680 kB
  • sloc: cpp: 338,717; ansic: 89,036; sh: 52; makefile: 27
file content (60 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
struct Input;

struct InputDriver {
  InputDriver(Input& super) : super(super) {}
  virtual ~InputDriver() = default;

  virtual auto create() -> bool { return true; }
  virtual auto driver() -> string { return "None"; }
  virtual auto ready() -> bool { return true; }

  virtual auto hasContext() -> bool { return false; }

  virtual auto setContext(uintptr context) -> bool { return true; }

  virtual auto acquired() -> bool { return false; }
  virtual auto acquire() -> bool { return false; }
  virtual auto release() -> bool { return false; }
  virtual auto poll() -> vector<shared_pointer<nall::HID::Device>> { return {}; }
  virtual auto rumble(u64 id, u16 strong, u16 weak) -> bool { return false; }

protected:
  Input& super;
  friend struct Input;

  uintptr context = 0;
};

struct Input {
  static auto hasDrivers() -> vector<string>;
  static auto hasDriver(string driver) -> bool { return (bool)hasDrivers().find(driver); }
  static auto optimalDriver() -> string;
  static auto safestDriver() -> string;

  Input() : self(*this) { reset(); }
  explicit operator bool() { return instance->driver() != "None"; }
  auto reset() -> void { instance = new InputDriver(*this); }
  auto create(string driver = "") -> bool;
  auto driver() -> string { return instance->driver(); }
  auto ready() -> bool { return instance->ready(); }

  auto hasContext() -> bool { return instance->hasContext(); }

  auto context() -> uintptr { return instance->context; }

  auto setContext(uintptr context) -> bool;

  auto acquired() -> bool;
  auto acquire() -> bool;
  auto release() -> bool;
  auto poll() -> vector<shared_pointer<nall::HID::Device>>;
  auto rumble(u64 id, u16 strong, u16 weak) -> bool;

  auto onChange(const function<void (shared_pointer<nall::HID::Device>, u32, u32, s16, s16)>&) -> void;
  auto doChange(shared_pointer<nall::HID::Device> device, u32 group, u32 input, s16 oldValue, s16 newValue) -> void;

protected:
  Input& self;
  unique_pointer<InputDriver> instance;
  function<void (shared_pointer<nall::HID::Device> device, u32 group, u32 input, s16 oldValue, s16 newValue)> change;
};