@desklink/host 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/NOTICE +44 -0
- package/README.md +266 -0
- package/bin/desklink-host.mjs +113 -0
- package/dist/bridge.d.ts +57 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +208 -0
- package/dist/bridge.js.map +1 -0
- package/dist/engineProcess.d.ts +82 -0
- package/dist/engineProcess.d.ts.map +1 -0
- package/dist/engineProcess.js +243 -0
- package/dist/engineProcess.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +169 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +18 -0
- package/dist/protocol.js.map +1 -0
- package/dist/resolveEngine.d.ts +34 -0
- package/dist/resolveEngine.d.ts.map +1 -0
- package/dist/resolveEngine.js +103 -0
- package/dist/resolveEngine.js.map +1 -0
- package/docs/BOUNDARY.md +145 -0
- package/docs/PROTOCOL.md +363 -0
- package/engine/Cargo.lock +3077 -0
- package/engine/Cargo.toml +37 -0
- package/engine/build.rs +107 -0
- package/engine/native/inputtino_shim.cpp +11 -0
- package/engine/native/vpx_shim.c +184 -0
- package/engine/native/wrapper.h +7 -0
- package/engine/src/capture.rs +510 -0
- package/engine/src/clipboard.rs +132 -0
- package/engine/src/convert.rs +299 -0
- package/engine/src/encoder.rs +204 -0
- package/engine/src/input.rs +355 -0
- package/engine/src/keymap.rs +338 -0
- package/engine/src/main.rs +614 -0
- package/engine/src/peer.rs +775 -0
- package/engine/src/portal.rs +115 -0
- package/engine/src/protocol.rs +331 -0
- package/engine/src/session.rs +2159 -0
- package/engine/src/x11.rs +244 -0
- package/engine/vendor/inputtino/.clang-format +166 -0
- package/engine/vendor/inputtino/.clang-tidy +30 -0
- package/engine/vendor/inputtino/.dockerignore +11 -0
- package/engine/vendor/inputtino/.github/workflows/mirror-repo.yml +14 -0
- package/engine/vendor/inputtino/.github/workflows/python-lint-format-test-typecheck.yml +124 -0
- package/engine/vendor/inputtino/.github/workflows/python-test-install.yaml +49 -0
- package/engine/vendor/inputtino/.github/workflows/rust.yml +40 -0
- package/engine/vendor/inputtino/CMakeLists.txt +187 -0
- package/engine/vendor/inputtino/LICENSE +21 -0
- package/engine/vendor/inputtino/README.md +110 -0
- package/engine/vendor/inputtino/bindings/python/.devcontainer/Dockerfile +23 -0
- package/engine/vendor/inputtino/bindings/python/.devcontainer/devcontainer.json +28 -0
- package/engine/vendor/inputtino/bindings/python/.python-version +1 -0
- package/engine/vendor/inputtino/bindings/python/CMakeLists.txt +23 -0
- package/engine/vendor/inputtino/bindings/python/CPPLINT.cfg +2 -0
- package/engine/vendor/inputtino/bindings/python/Makefile +49 -0
- package/engine/vendor/inputtino/bindings/python/README.md +215 -0
- package/engine/vendor/inputtino/bindings/python/pyproject.toml +178 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/__init__.py +43 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/_core.pyi +533 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/base.py +63 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/joypad.py +248 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/keyboard.py +256 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/mouse.py +106 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/pentablet.py +73 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/py.typed +0 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/touchscreen.py +61 -0
- package/engine/vendor/inputtino/bindings/python/src/inputtino/trackpad.py +74 -0
- package/engine/vendor/inputtino/bindings/python/src/main.cpp +217 -0
- package/engine/vendor/inputtino/bindings/python/tests/__init__.py +0 -0
- package/engine/vendor/inputtino/bindings/python/tests/helpers.py +3 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_base.py +60 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_inputtino.py +5 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_joypad.py +332 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_keyboard.py +164 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_mouse.py +185 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_pentablet.py +198 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_touchscreen.py +144 -0
- package/engine/vendor/inputtino/bindings/python/tests/test_trackpad.py +146 -0
- package/engine/vendor/inputtino/bindings/python/uv.lock +390 -0
- package/engine/vendor/inputtino/bindings/rust/Cargo.toml +6 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/.dockerignore +1 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/Cargo.toml +18 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/examples/keyboard.rs +33 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/examples/mouse.rs +17 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/common.rs +116 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/error.rs +17 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad.rs +74 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_nintendo.rs +135 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_ps5.rs +280 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/joypad_xbox.rs +134 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/keyboard.rs +76 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/lib.rs +32 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/src/mouse.rs +178 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/tests/common.rs +38 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/tests/joypads.rs +150 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/tests/keyboard.rs +73 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino/tests/mouse.rs +139 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino-sys/.dockerignore +1 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino-sys/Cargo.toml +12 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino-sys/build.rs +48 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino-sys/src/lib.rs +5 -0
- package/engine/vendor/inputtino/bindings/rust/inputtino-sys/wrapper.h +1 -0
- package/engine/vendor/inputtino/cmake/utils.cmake +9 -0
- package/engine/vendor/inputtino/docker/Dockerfile +70 -0
- package/engine/vendor/inputtino/include/inputtino/input.h +324 -0
- package/engine/vendor/inputtino/include/inputtino/input.hpp +466 -0
- package/engine/vendor/inputtino/include/inputtino/result.hpp +37 -0
- package/engine/vendor/inputtino/share/pkgconfig/libinputtino.pc.in +17 -0
- package/engine/vendor/inputtino/src/c-bindings/helpers.hpp +19 -0
- package/engine/vendor/inputtino/src/c-bindings/joypad_ps5.cpp +115 -0
- package/engine/vendor/inputtino/src/c-bindings/joypad_switch.cpp +63 -0
- package/engine/vendor/inputtino/src/c-bindings/joypad_xone.cpp +62 -0
- package/engine/vendor/inputtino/src/c-bindings/keyboard.cpp +42 -0
- package/engine/vendor/inputtino/src/c-bindings/mouse.cpp +67 -0
- package/engine/vendor/inputtino/src/c-bindings/pen_tablet.cpp +50 -0
- package/engine/vendor/inputtino/src/c-bindings/touchscreen.cpp +43 -0
- package/engine/vendor/inputtino/src/c-bindings/trackpad.cpp +49 -0
- package/engine/vendor/inputtino/src/uhid/README.adoc +63 -0
- package/engine/vendor/inputtino/src/uhid/include/crc32.hpp +38 -0
- package/engine/vendor/inputtino/src/uhid/include/uhid/protected_types.hpp +36 -0
- package/engine/vendor/inputtino/src/uhid/include/uhid/ps5.hpp +550 -0
- package/engine/vendor/inputtino/src/uhid/include/uhid/uhid.hpp +168 -0
- package/engine/vendor/inputtino/src/uhid/joypad_ps5.cpp +580 -0
- package/engine/vendor/inputtino/src/uinput/include/inputtino/keyboard.hpp +84 -0
- package/engine/vendor/inputtino/src/uinput/include/inputtino/protected_ps5_types.hpp +7 -0
- package/engine/vendor/inputtino/src/uinput/include/inputtino/protected_types.hpp +110 -0
- package/engine/vendor/inputtino/src/uinput/joypad_nintendo.cpp +190 -0
- package/engine/vendor/inputtino/src/uinput/joypad_ps.cpp +203 -0
- package/engine/vendor/inputtino/src/uinput/joypad_utils.hpp +246 -0
- package/engine/vendor/inputtino/src/uinput/joypad_xbox.cpp +190 -0
- package/engine/vendor/inputtino/src/uinput/keyboard.cpp +120 -0
- package/engine/vendor/inputtino/src/uinput/mouse.cpp +199 -0
- package/engine/vendor/inputtino/src/uinput/pentablet.cpp +162 -0
- package/engine/vendor/inputtino/src/uinput/touchscreen.cpp +140 -0
- package/engine/vendor/inputtino/src/uinput/trackpad.cpp +192 -0
- package/examples/reference-client.html +428 -0
- package/package.json +38 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <errno.h>
|
|
4
|
+
#include <fcntl.h>
|
|
5
|
+
#include <functional>
|
|
6
|
+
#include <inputtino/result.hpp>
|
|
7
|
+
#include <iostream>
|
|
8
|
+
#include <linux/uhid.h>
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include <poll.h>
|
|
11
|
+
#include <stdbool.h>
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
#include <string>
|
|
16
|
+
#include <termios.h>
|
|
17
|
+
#include <thread>
|
|
18
|
+
#include <unistd.h>
|
|
19
|
+
#include <vector>
|
|
20
|
+
|
|
21
|
+
namespace uhid {
|
|
22
|
+
struct ThreadState {
|
|
23
|
+
int fd;
|
|
24
|
+
std::function<void(const uhid_event &ev, int fd)> on_event;
|
|
25
|
+
bool stop_repeat_thread = false;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
struct DeviceDefinition {
|
|
29
|
+
std::string name;
|
|
30
|
+
std::string phys;
|
|
31
|
+
std::string uniq;
|
|
32
|
+
uint16_t bus;
|
|
33
|
+
uint32_t vendor;
|
|
34
|
+
uint32_t product;
|
|
35
|
+
uint32_t version;
|
|
36
|
+
uint32_t country;
|
|
37
|
+
std::vector<unsigned char> report_description;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
static inputtino::Result<bool> uhid_write(int fd, const struct uhid_event *ev) {
|
|
41
|
+
ssize_t ret = write(fd, ev, sizeof(*ev));
|
|
42
|
+
if (ret < 0) {
|
|
43
|
+
return inputtino::Error(strerror(errno));
|
|
44
|
+
} else if (ret != sizeof(*ev)) {
|
|
45
|
+
return inputtino::Error(strerror(-EFAULT));
|
|
46
|
+
} else {
|
|
47
|
+
return ret;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
class Device {
|
|
52
|
+
private:
|
|
53
|
+
Device(std::shared_ptr<std::thread> ev_thread, std::shared_ptr<ThreadState> state)
|
|
54
|
+
: ev_thread(std::move(ev_thread)), state(std::move(state)) {};
|
|
55
|
+
std::shared_ptr<std::thread> ev_thread;
|
|
56
|
+
std::shared_ptr<ThreadState> state;
|
|
57
|
+
std::shared_ptr<std::function<void(const uhid_event &ev, int fd)>> on_event;
|
|
58
|
+
|
|
59
|
+
public:
|
|
60
|
+
static inputtino::Result<Device> create(const DeviceDefinition &definition,
|
|
61
|
+
const std::function<void(const uhid_event &ev, int fd)> &on_event);
|
|
62
|
+
|
|
63
|
+
Device(Device &&j) noexcept : ev_thread(nullptr), state(nullptr), on_event(nullptr) {
|
|
64
|
+
std::swap(j.ev_thread, ev_thread);
|
|
65
|
+
std::swap(j.state, state);
|
|
66
|
+
std::swap(j.on_event, on_event);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Device(Device const &) = delete;
|
|
70
|
+
Device &operator=(Device const &) = delete;
|
|
71
|
+
|
|
72
|
+
inline inputtino::Result<bool> send(const uhid_event &ev) {
|
|
73
|
+
return uhid_write(state->fd, &ev);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
inline void stop_thread() {
|
|
77
|
+
state->stop_repeat_thread = true;
|
|
78
|
+
if (ev_thread->joinable()) {
|
|
79
|
+
ev_thread->join(); // let's wait for the thread to finish
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
~Device() {
|
|
84
|
+
if (state) {
|
|
85
|
+
struct uhid_event ev{};
|
|
86
|
+
ev.type = UHID_DESTROY;
|
|
87
|
+
uhid_write(state->fd, &ev);
|
|
88
|
+
|
|
89
|
+
close(state->fd); // This should also close the thread by causing a POLLHUP
|
|
90
|
+
|
|
91
|
+
state->stop_repeat_thread = true;
|
|
92
|
+
if (ev_thread->joinable()) {
|
|
93
|
+
ev_thread->join(); // let's wait for the thread to finish
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
static void set_c_str(const std::string &str, unsigned char *c_str) {
|
|
100
|
+
std::copy(str.begin(), str.end(), c_str);
|
|
101
|
+
c_str[str.length()] = 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
constexpr int UHID_POLL_TIMEOUT = 500; // ms
|
|
105
|
+
|
|
106
|
+
inputtino::Result<Device> Device::create(const DeviceDefinition &definition,
|
|
107
|
+
const std::function<void(const uhid_event &ev, int fd)> &on_event) {
|
|
108
|
+
|
|
109
|
+
int fd = open("/dev/uhid", O_RDWR | O_CLOEXEC);
|
|
110
|
+
if (fd < 0) {
|
|
111
|
+
return inputtino::Error(strerror(errno));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
auto ev = uhid_event{};
|
|
115
|
+
ev.type = UHID_CREATE2, ev.u.create2.bus = definition.bus, ev.u.create2.vendor = definition.vendor,
|
|
116
|
+
ev.u.create2.product = definition.product, ev.u.create2.version = definition.version,
|
|
117
|
+
ev.u.create2.country = definition.country,
|
|
118
|
+
ev.u.create2.rd_size = static_cast<std::uint16_t>(definition.report_description.size()),
|
|
119
|
+
std::copy(definition.report_description.begin(), definition.report_description.end(), ev.u.create2.rd_data);
|
|
120
|
+
set_c_str(definition.name, ev.u.create2.name);
|
|
121
|
+
set_c_str(definition.phys, ev.u.create2.phys);
|
|
122
|
+
set_c_str(definition.uniq, ev.u.create2.uniq);
|
|
123
|
+
|
|
124
|
+
auto res = uhid_write(fd, &ev);
|
|
125
|
+
if (res) {
|
|
126
|
+
auto state = std::make_shared<ThreadState>();
|
|
127
|
+
state->fd = fd;
|
|
128
|
+
state->on_event = on_event;
|
|
129
|
+
auto thread = std::make_shared<std::thread>([state]() {
|
|
130
|
+
std::array<pollfd, 1> pfds = {pollfd{.fd = state->fd, .events = POLLIN}};
|
|
131
|
+
int poll_rs = 0;
|
|
132
|
+
|
|
133
|
+
while (!state->stop_repeat_thread) {
|
|
134
|
+
poll_rs = poll(pfds.data(), pfds.size(), UHID_POLL_TIMEOUT);
|
|
135
|
+
if (poll_rs < 0) {
|
|
136
|
+
std::cerr << "Failed polling uhid fd; ret=" << strerror(errno) << std::endl;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
if (pfds[0].revents & POLLHUP) {
|
|
140
|
+
std::cerr << "HUP on uhid-cdev" << std::endl;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
if (pfds[0].revents & POLLIN) {
|
|
144
|
+
struct uhid_event ev{};
|
|
145
|
+
auto ret = read(state->fd, &ev, sizeof(ev));
|
|
146
|
+
if (ret == 0) {
|
|
147
|
+
std::cerr << "Read HUP on uhid-cdev" << std::endl;
|
|
148
|
+
} else if (ret < 0) {
|
|
149
|
+
std::cerr << "Cannot read uhid-cdev: " << strerror(errno) << std::endl;
|
|
150
|
+
} else if (ret != sizeof(ev)) {
|
|
151
|
+
std::cerr << "Invalid size read from uhid-dev" << ret << " != " << sizeof(ev) << std::endl;
|
|
152
|
+
} else {
|
|
153
|
+
if (state->on_event) {
|
|
154
|
+
state->on_event(ev, state->fd);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
thread->detach();
|
|
161
|
+
return inputtino::Result<Device>({std::move(thread), std::move(state)});
|
|
162
|
+
} else {
|
|
163
|
+
close(fd);
|
|
164
|
+
return inputtino::Error(res.getErrorMessage());
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
} // namespace uhid
|