diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..e2f942b --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2303155..7e8b618 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,12 @@ jobs: with: toolchain: stable - - name: Install cross-compilers + - name: Install build dependencies run: | sudo apt-get update - sudo apt-get install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu + sudo apt-get install -y \ + gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu \ + libssl-dev pkg-config libpipewire-0.3-dev - name: Cache cargo registry uses: actions/cache@v4 @@ -39,10 +41,12 @@ jobs: - name: Build run: cargo build --release - - name: Check binary exists + - name: Check binaries exist run: | - if [ ! -f target/release/rm-pad ]; then - echo "Binary not found!" - exit 1 - fi - ls -lh target/release/rm-pad + for b in rm-pad rm-screen; do + if [ ! -f "target/release/$b" ]; then + echo "Binary $b not found!" + exit 1 + fi + ls -lh "target/release/$b" + done diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3be055c..e325394 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,10 +19,12 @@ jobs: with: toolchain: stable - - name: Install cross-compilers + - name: Install build dependencies run: | sudo apt-get update - sudo apt-get install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu + sudo apt-get install -y \ + gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu \ + libssl-dev pkg-config libpipewire-0.3-dev - name: Cache cargo registry uses: actions/cache@v4 @@ -43,7 +45,7 @@ jobs: - name: Get version from Cargo.toml id: version run: | - VERSION=$(grep '^version' Cargo.toml | cut -d '"' -f 2) + VERSION=$(grep '^version' rm-pad/Cargo.toml | head -1 | cut -d '"' -f 2) echo "version=$VERSION" >> $GITHUB_OUTPUT echo "Version: $VERSION" @@ -51,6 +53,7 @@ jobs: run: | mkdir -p release cp target/release/rm-pad release/rm-pad + cp target/release/rm-screen release/rm-screen cp README.md release/ cp rm-pad.toml.example release/ cp -r data release/ diff --git a/Cargo.lock b/Cargo.lock index 3ac985c..657a169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "annotate-snippets" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710e8eae58854cdc1790fcb56cca04d712a17be849eeb81da2a724bf4bae2bc4" +dependencies = [ + "anstyle", + "unicode-width", +] + [[package]] name = "anstream" version = "0.6.21" @@ -61,12 +71,222 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "ashpd" +version = "0.13.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bdf0fd848239dcd5e64eeeee35dbc00378ebcc6f3aa4ead0a305eec83d0cfb" +dependencies = [ + "enumflags2", + "futures-util", + "getrandom", + "serde", + "serde_repr", + "tokio", + "zbus", +] + +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" +dependencies = [ + "async-channel", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "rustix", +] + +[[package]] +name = "async-recursion" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b43422f69d8ff38f95f1b2bb76517c91589a924d1559a0e935d7c8ce0274c11" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "async-signal" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "bindgen" +version = "0.72.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" +dependencies = [ + "annotate-snippets", + "bitflags 2.10.0", + "cexpr", + "clang-sys", + "itertools", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "block-buffer" version = "0.10.4" @@ -76,6 +296,31 @@ dependencies = [ "generic-array", ] +[[package]] +name = "blocking" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83f8d02be6967315521be875afa792a316e28d57b5a2d401897e2a7921b7f21" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + [[package]] name = "cc" version = "1.2.55" @@ -86,12 +331,58 @@ dependencies = [ "shlex", ] +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + +[[package]] +name = "cfg-expr" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c6b04e07d8080154ed4ac03546d9a2b303cc2fe1901ba0b35b301516e289368" +dependencies = [ + "smallvec", + "target-lexicon", +] + [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "cgmath" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317" +dependencies = [ + "approx", + "num-traits", +] + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clap" version = "4.5.57" @@ -138,6 +429,30 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "convert_case" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baaaa0ecca5b51987b9423ccdc971514dd8b0bb7b4060b983d3664dad3f1f89f" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cookie-factory" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" + [[package]] name = "cpufeatures" version = "0.2.17" @@ -147,6 +462,12 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + [[package]] name = "crypto-common" version = "0.1.7" @@ -167,6 +488,39 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "either" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" + +[[package]] +name = "endi" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" + +[[package]] +name = "enumflags2" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "env_filter" version = "0.1.4" @@ -196,6 +550,29 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "evdev" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab6055a93a963297befb0f4f6e18f314aec9767a4bbe88b151126df2433610a7" +dependencies = [ + "bitvec", + "cfg-if", + "libc", + "nix 0.23.2", + "thiserror 1.0.69", +] + [[package]] name = "evdevil" version = "0.4.0" @@ -207,6 +584,33 @@ dependencies = [ "uoctl", ] +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" + [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -214,61 +618,83 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" [[package]] -name = "generic-array" -version = "0.14.7" +name = "foldhash" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" dependencies = [ - "typenum", - "version_check", + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", ] [[package]] -name = "hashbrown" -version = "0.16.1" +name = "futures-channel" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] [[package]] -name = "heck" -version = "0.5.0" +name = "futures-core" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" [[package]] -name = "indexmap" -version = "2.13.0" +name = "futures-executor" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" dependencies = [ - "equivalent", - "hashbrown", + "futures-core", + "futures-task", + "futures-util", ] [[package]] -name = "is_terminal_polyfill" -version = "1.70.2" +name = "futures-io" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" [[package]] -name = "jiff" -version = "0.2.19" +name = "futures-lite" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d89a5b5e10d5a9ad6e5d1f4bd58225f655d6fe9767575a5e8ac5a6fe64e04495" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", ] [[package]] -name = "jiff-static" -version = "0.2.19" +name = "futures-macro" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff7a39c8862fc1369215ccf0a8f12dd4598c7f6484704359f0351bd617034dbf" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", @@ -276,17 +702,280 @@ dependencies = [ ] [[package]] -name = "libc" -version = "0.2.180" +name = "futures-sink" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" [[package]] -name = "libssh2-sys" -version = "0.3.1" +name = "futures-task" +version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" -dependencies = [ +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "ioctl-gen" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1745979ddec01f66bfed491fee60958959015239cb9c8878960a18cb73906be7" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "jiff" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d89a5b5e10d5a9ad6e5d1f4bd58225f655d6fe9767575a5e8ac5a6fe64e04495" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", +] + +[[package]] +name = "jiff-static" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff7a39c8862fc1369215ccf0a8f12dd4598c7f6484704359f0351bd617034dbf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "js-sys" +version = "0.3.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e04e2ef80ce82e13552136fabeef8a5ed1f985a96805761cbb9a2c34e7664d9" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lamco-pipewire" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28c9325005b97e5988dc6925366196f9c90fe43144f5b77b1b5ea7f97ed6079" +dependencies = [ + "futures", + "libc", + "libspa", + "libspa-sys", + "nix 0.30.1", + "parking_lot", + "pipewire", + "thiserror 1.0.69", + "tokio", + "tracing", +] + +[[package]] +name = "lamco-portal" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2280804f1e28d002f80cd1bdb45cac454dcddb138f4c1bf5a32994fd19bfc766" +dependencies = [ + "ashpd", + "enumflags2", + "futures-util", + "libc", + "thiserror 1.0.69", + "tokio", + "tracing", + "uuid", + "zbus", +] + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.184" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f5d2a454e16a5ea0f4ced81bd44e4cfc7bd3a507b61887c99fd3538b28e4af" + +[[package]] +name = "libloading" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" +dependencies = [ + "cfg-if", + "windows-link", +] + +[[package]] +name = "libremarkable" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1da7c4a5765735faf196b9c3eb027cd9c2afb58abc772c8ef299dc56dc93edef" +dependencies = [ + "cgmath", + "evdev", + "ioctl-gen", + "libc", + "log", + "memmap2", +] + +[[package]] +name = "libspa" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6b8cfa2a7656627b4c92c6b9ef929433acd673d5ab3708cda1b18478ac00df4" +dependencies = [ + "bitflags 2.10.0", + "cc", + "convert_case", + "cookie-factory", + "libc", + "libspa-sys", + "nix 0.30.1", + "nom 8.0.0", + "system-deps", +] + +[[package]] +name = "libspa-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901049455d2eb6decf9058235d745237952f4804bc584c5fcb41412e6adcc6e0" +dependencies = [ + "bindgen", + "cc", + "system-deps", +] + +[[package]] +name = "libssh2-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "220e4f05ad4a218192533b300327f5150e809b54c4ec83b5a1d91833601811b9" +dependencies = [ "cc", "libc", "libz-sys", @@ -307,6 +996,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + [[package]] name = "lock_api" version = "0.4.14" @@ -322,12 +1017,124 @@ version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +[[package]] +name = "lz4_flex" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373f5eceeeab7925e0c1098212f2fbc4d416adec9d35051a6ab251e824c1854a" +dependencies = [ + "twox-hash", +] + [[package]] name = "memchr" version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "memmap2" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714098028fe011992e1c3962653c96b2d578c4b4bce9036e15ff220319b1e0e3" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "nix" +version = "0.23.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f3790c00a0150112de0f4cd161e3d7fc4b2d8a5542ffc35f099a2562aecb35c" +dependencies = [ + "bitflags 1.3.2", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + +[[package]] +name = "nix" +version = "0.30.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" +dependencies = [ + "bitflags 2.10.0", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nom" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9761775871bdef83bee530e60050f7e54b1105350d6884eb0fb4f46c2f9405" +dependencies = [ + "memchr", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + [[package]] name = "once_cell_polyfill" version = "1.70.2" @@ -346,6 +1153,22 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "ordered-stream" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -369,12 +1192,71 @@ dependencies = [ "windows-link", ] +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pipewire" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9688b89abf11d756499f7c6190711d6dbe5a3acdb30c8fbf001d6596d06a8d44" +dependencies = [ + "anyhow", + "bitflags 2.10.0", + "libc", + "libspa", + "libspa-sys", + "nix 0.30.1", + "once_cell", + "pipewire-sys", + "thiserror 2.0.18", +] + +[[package]] +name = "pipewire-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb028afee0d6ca17020b090e3b8fa2d7de23305aef975c7e5192a5050246ea36" +dependencies = [ + "bindgen", + "libspa-sys", + "system-deps", +] + [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + [[package]] name = "portable-atomic" version = "1.13.1" @@ -390,6 +1272,25 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit 0.25.11+spec-1.1.0", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -408,13 +1309,25 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "redox_syscall" version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" dependencies = [ - "bitflags", + "bitflags 2.10.0", ] [[package]] @@ -447,26 +1360,94 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" [[package]] -name = "rm-pad" +name = "rm-client-screen" version = "0.1.0" dependencies = [ - "clap", "env_logger", - "evdevil", + "libc", + "libremarkable", + "log", + "lz4_flex", + "rm-common", +] + +[[package]] +name = "rm-common" +version = "0.1.0" +dependencies = [ + "clap", "log", "serde", "sha2", - "socket2", "ssh2", - "toml", + "toml 0.8.23", ] +[[package]] +name = "rm-pad" +version = "0.1.0" +dependencies = [ + "clap", + "env_logger", + "evdevil", + "log", + "rm-common", + "socket2 0.5.10", +] + +[[package]] +name = "rm-screen" +version = "0.1.0" +dependencies = [ + "ashpd", + "clap", + "env_logger", + "lamco-pipewire", + "lamco-portal", + "log", + "lz4_flex", + "rm-common", + "socket2 0.5.10", + "tokio", +] + +[[package]] +name = "rustc-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94300abf3f1ae2e2b8ffb7b58043de3d399c73fa6f4b73826402a5c457614dbe" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags 2.10.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" + [[package]] name = "serde" version = "1.0.228" @@ -497,6 +1478,30 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_repr" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "serde_spanned" version = "0.6.9" @@ -506,6 +1511,15 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + [[package]] name = "sha2" version = "0.10.9" @@ -523,6 +1537,22 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.15.1" @@ -540,32 +1570,148 @@ dependencies = [ ] [[package]] -name = "ssh2" -version = "0.9.5" +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "ssh2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f84d13b3b8a0d4e91a2629911e951db1bb8671512f5c09d7d4ba34500ba68c8" +dependencies = [ + "bitflags 2.10.0", + "libc", + "libssh2-sys", + "parking_lot", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "system-deps" +version = "7.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396a35feb67335377e0251fcbc1092fc85c484bd4e3a7a54319399da127796e7" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml 1.1.2+spec-1.1.0", + "version-compare", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "target-lexicon" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c" + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl 2.0.18", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio" +version = "1.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f84d13b3b8a0d4e91a2629911e951db1bb8671512f5c09d7d4ba34500ba68c8" +checksum = "f66bf9585cda4b724d3e78ab34b73fb2bbaba9011b9bfdf69dc836382ea13b8c" dependencies = [ - "bitflags", + "bytes", "libc", - "libssh2-sys", - "parking_lot", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.6.3", + "tokio-macros", + "tracing", + "windows-sys 0.61.2", ] [[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.114" +name = "tokio-macros" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4d107df263a3013ef9b1879b0df87d706ff80f65a86ea879bd9c31f9b307c2a" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "unicode-ident", + "syn", ] [[package]] @@ -575,9 +1721,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" dependencies = [ "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", + "toml_edit 0.22.27", +] + +[[package]] +name = "toml" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned 1.1.1", + "toml_datetime 1.1.1+spec-1.1.0", + "toml_parser", + "toml_writer", + "winnow 1.0.1", ] [[package]] @@ -589,6 +1750,15 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + [[package]] name = "toml_edit" version = "0.22.27" @@ -597,10 +1767,31 @@ checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", "serde", - "serde_spanned", - "toml_datetime", + "serde_spanned 0.6.9", + "toml_datetime 0.6.11", "toml_write", - "winnow", + "winnow 0.7.14", +] + +[[package]] +name = "toml_edit" +version = "0.25.11+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b59c4d22ed448339746c59b905d24568fcbb3ab65a500494f7b8c3e97739f2b" +dependencies = [ + "indexmap", + "toml_datetime 1.1.1+spec-1.1.0", + "toml_parser", + "winnow 1.0.1", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow 1.0.1", ] [[package]] @@ -609,18 +1800,90 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" +[[package]] +name = "toml_writer" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "twox-hash" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea3136b675547379c4bd395ca6b938e5ad3c3d20fad76e7fe85f9e0d011419c" + [[package]] name = "typenum" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" +[[package]] +name = "uds_windows" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" +dependencies = [ + "memoffset 0.9.1", + "tempfile", + "windows-sys 0.61.2", +] + [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "unicode-segmentation" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9629274872b2bfaf8d66f5f15725007f635594914870f65218920345aa11aa8c" + +[[package]] +name = "unicode-width" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "uoctl" version = "1.0.1" @@ -636,18 +1899,139 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "uuid" +version = "1.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ac8b6f42ead25368cf5b098aeb3dc8a1a2c05a3eee8a9a1a68c640edbfc79d9" +dependencies = [ + "getrandom", + "js-sys", + "serde_core", + "wasm-bindgen", +] + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0551fc1bb415591e3372d0bc4780db7e587d84e2a7e79da121051c5c4b89d0b0" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fbdf9a35adf44786aecd5ff89b4563a90325f9da0923236f6104e603c7e86be" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dca9693ef2bab6d4e6707234500350d8dad079eb508dca05530c85dc3a529ff2" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39129a682a6d2d841b6c429d0c51e5cb0ed1a03829d8b3d1e69a011e62cb3d3b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags 2.10.0", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + [[package]] name = "windows-link" version = "0.2.1" @@ -744,3 +2128,217 @@ checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" dependencies = [ "memchr", ] + +[[package]] +name = "winnow" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09dac053f1cd375980747450bfc7250c264eaae0583872e845c0c7cd578872b5" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags 2.10.0", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zbus" +version = "5.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca82f95dbd3943a40a53cfded6c2d0a2ca26192011846a1810c4256ef92c60bc" +dependencies = [ + "async-broadcast", + "async-executor", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-lite", + "hex", + "libc", + "ordered-stream", + "rustix", + "serde", + "serde_repr", + "tokio", + "tracing", + "uds_windows", + "uuid", + "windows-sys 0.61.2", + "winnow 0.7.14", + "zbus_macros", + "zbus_names", + "zvariant", +] + +[[package]] +name = "zbus_macros" +version = "5.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897e79616e84aac4b2c46e9132a4f63b93105d54fe8c0e8f6bffc21fa8d49222" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", + "zbus_names", + "zvariant", + "zvariant_utils", +] + +[[package]] +name = "zbus_names" +version = "4.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffd8af6d5b78619bab301ff3c560a5bd22426150253db278f164d6cf3b72c50f" +dependencies = [ + "serde", + "winnow 0.7.14", + "zvariant", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[package]] +name = "zvariant" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5708299b21903bbe348e94729f22c49c55d04720a004aa350f1f9c122fd2540b" +dependencies = [ + "endi", + "enumflags2", + "serde", + "winnow 0.7.14", + "zvariant_derive", + "zvariant_utils", +] + +[[package]] +name = "zvariant_derive" +version = "5.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b59b012ebe9c46656f9cc08d8da8b4c726510aef12559da3e5f1bf72780752c" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", + "zvariant_utils", +] + +[[package]] +name = "zvariant_utils" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75c23a64ef8f40f13a6989991e643554d9bef1d682a281160cf0c1bc389c5e9" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn", + "winnow 0.7.14", +] diff --git a/Cargo.toml b/Cargo.toml index 7e689f8..44eda31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,3 @@ -[package] -name = "rm-pad" -version = "0.1.0" -edition = "2021" - -[dependencies] -clap = { version = "4", features = ["derive", "env"] } -env_logger = "0.11" -evdevil = "0.4.0" -log = "0.4" -serde = { version = "1.0", features = ["derive"] } -sha2 = "0.10" -socket2 = { version = "0.5", features = ["all"] } -ssh2 = "0.9.5" -toml = "0.8" +[workspace] +resolver = "2" +members = ["rm-common", "rm-pad", "rm-screen", "rm-client-screen"] diff --git a/PKGBUILD b/PKGBUILD index c5ae59c..2b2b605 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -16,13 +16,14 @@ build() { # Set CARGO_TARGET_DIR to avoid picking up parent Cargo.toml export CARGO_TARGET_DIR="$srcdir/target" cd "$srcdir/rm-pad" - cargo build --release --locked + cargo build -p rm-pad --release --locked } package() { cd "$srcdir/rm-pad" install -Dm755 "$srcdir/target/release/rm-pad" "$pkgdir/usr/bin/rm-pad" + install -Dm755 "$srcdir/target/release/rm-screen" "$pkgdir/usr/bin/rm-screen" install -Dm644 data/50-uinput.rules "$pkgdir/usr/lib/udev/rules.d/50-uinput.rules" diff --git a/build.rs b/build.rs deleted file mode 100644 index 3a0f203..0000000 --- a/build.rs +++ /dev/null @@ -1,141 +0,0 @@ -use std::env; -use std::path::PathBuf; -use std::process::Command; - -/// Cross-compile the evgrab helper for ARM targets. -/// -/// The helper is a tiny C program that exclusively grabs an evdev device -/// (EVIOCGRAB) and pipes raw events to stdout. It's uploaded to the -/// reMarkable at runtime and replaces the old kill -STOP approach. -/// -/// Compiler lookup order: -/// 1. Environment variable (ARMV7_CC / AARCH64_CC) -/// 2. Common musl cross-compiler names -/// 3. Common glibc cross-compiler names -fn main() { - println!("cargo:rerun-if-changed=helper/evgrab.c"); - - let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - - build_helper("armv7", &out_dir); - build_helper("aarch64", &out_dir); -} - -fn build_helper(arch: &str, out_dir: &PathBuf) { - let cc = find_compiler(arch); - let output = out_dir.join(format!("evgrab-{}", arch)); - - eprintln!("Compiling evgrab for {} using {}", arch, cc); - - let status = Command::new(&cc) - .args(["-static", "-Os", "-o"]) - .arg(&output) - .arg("helper/evgrab.c") - .status() - .unwrap_or_else(|e| { - panic!( - "Failed to run cross-compiler '{}': {}\n\ - \n\ - To build rm-pad you need C cross-compilers for ARM.\n\ - \n\ - On Ubuntu/Debian:\n\ - \x20 sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu\n\ - \n\ - On Arch Linux (AUR):\n\ - \x20 arm-linux-gnueabihf-gcc, aarch64-linux-gnu-gcc\n\ - \n\ - Or set {}_CC to point to your compiler.", - cc, - e, - arch.to_uppercase() - ) - }); - - if !status.success() { - panic!( - "Cross-compiler '{}' failed with {}.\n\ - Check that the toolchain is correctly installed.", - cc, status - ); - } - - // Try to strip the binary for a smaller embed size. - if let Some(strip) = find_tool("strip", arch) { - let _ = Command::new(strip).arg(&output).status(); - } -} - -fn find_compiler(arch: &str) -> String { - // 1. Check environment variable override. - let env_var = format!("{}_CC", arch.to_uppercase()); - if let Ok(cc) = env::var(&env_var) { - return cc; - } - - // 2. Try common cross-compiler names. - let candidates = compiler_candidates(arch); - - for cc in &candidates { - if command_exists(cc) { - return cc.to_string(); - } - } - - panic!( - "No C cross-compiler found for {arch}.\n\ - \n\ - Tried: {candidates}\n\ - \n\ - Install one of the above, or set {env_var} to your compiler path.\n\ - \n\ - On Ubuntu/Debian:\n\ - \x20 sudo apt install gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu\n\ - \n\ - On Arch Linux (AUR):\n\ - \x20 arm-linux-gnueabihf-gcc, aarch64-linux-gnu-gcc", - arch = arch, - candidates = candidates.join(", "), - env_var = env_var, - ); -} - -fn compiler_candidates(arch: &str) -> Vec<&'static str> { - match arch { - "armv7" => vec![ - "arm-none-linux-gnueabihf-gcc", - "arm-linux-musleabihf-gcc", - "arm-linux-gnueabihf-gcc", - ], - "aarch64" => vec![ - "aarch64-linux-musl-gcc", - "aarch64-linux-gnu-gcc", - ], - _ => panic!("Unknown target architecture: {}", arch), - } -} - -fn find_tool(tool: &str, arch: &str) -> Option { - let prefixes = match arch { - "armv7" => &["arm-none-linux-gnueabihf-", "arm-linux-musleabihf-", "arm-linux-gnueabihf-"][..], - "aarch64" => &["aarch64-linux-musl-", "aarch64-linux-gnu-"][..], - _ => return None, - }; - - for prefix in prefixes { - let name = format!("{}{}", prefix, tool); - if command_exists(&name) { - return Some(name); - } - } - - None -} - -fn command_exists(name: &str) -> bool { - Command::new(name) - .arg("--version") - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) - .status() - .is_ok() -} diff --git a/rm-client-screen/Cargo.toml b/rm-client-screen/Cargo.toml new file mode 100644 index 0000000..6155b3a --- /dev/null +++ b/rm-client-screen/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "rm-client-screen" +version = "0.1.0" +edition = "2021" + +[dependencies] +rm-common = { path = "../rm-common", default-features = false } +env_logger = "0.11" +libremarkable = { version = "0.7.0", default-features = false, features = ["framebuffer"] } +log = "0.4" +lz4_flex = "0.11" +libc = "0.2" diff --git a/rm-client-screen/src/main.rs b/rm-client-screen/src/main.rs new file mode 100644 index 0000000..23da9ae --- /dev/null +++ b/rm-client-screen/src/main.rs @@ -0,0 +1,218 @@ +//! Tablet-side receiver: TCP → LZ4 → framebuffer partial updates. + +use std::io::Read; +use std::net::TcpListener; +use std::os::fd::AsRawFd; +use std::time::Instant; + +use libc::{poll, pollfd, POLLIN}; +use libremarkable::framebuffer::common::{ + color, dither_mode, display_temp, mxcfb_rect, waveform_mode, +}; +use libremarkable::framebuffer::core::Framebuffer; +use libremarkable::framebuffer::{FramebufferIO, FramebufferRefresh, PartialRefreshMode}; +use log::{error, info, warn}; +use rm_common::protocol::{UpdateHeader, HEADER_SIZE}; + +type DynResult = Result>; + +const IDLE_MS: i32 = 3000; + +fn main() -> DynResult<()> { + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); + + let addr = std::env::args() + .nth(1) + .unwrap_or_else(|| "0.0.0.0:9876".to_string()); + let listener = TcpListener::bind(&addr)?; + info!("rm-client-screen listening on {}", addr); + + let (mut stream, peer) = listener.accept()?; + info!("accepted {}", peer); + drop(listener); + + stream.set_nonblocking(true)?; + stream.set_write_timeout(Some(std::time::Duration::from_secs(10)))?; + + let mut fb = Framebuffer::new(); + run_stream(&mut fb, &mut stream)?; + + Ok(()) +} + +fn run_stream(fb: &mut Framebuffer, stream: &mut std::net::TcpStream) -> DynResult<()> { + let fd = stream.as_raw_fd(); + let mut buf: Vec = Vec::new(); + let mut last_data = Instant::now(); + + loop { + ensure_min_bytes(stream, fd, &mut buf, HEADER_SIZE, &mut last_data, fb)?; + if buf.is_empty() { + break; + } + + let hdr_slice: [u8; HEADER_SIZE] = buf[..HEADER_SIZE].try_into().unwrap(); + let Some(header) = UpdateHeader::from_bytes(&hdr_slice) else { + return Err("invalid header".into()); + }; + + let total = HEADER_SIZE + header.payload_size as usize; + ensure_min_bytes(stream, fd, &mut buf, total, &mut last_data, fb)?; + + let payload = buf[HEADER_SIZE..total].to_vec(); + buf.drain(..total); + + let raw = match lz4_flex::block::decompress_size_prepended(&payload) { + Ok(v) => v, + Err(e) => { + warn!("LZ4 error: {e}"); + continue; + } + }; + + let w = header.width as u32; + let h = header.height as u32; + let expected_packed = (w / 2) * h; + if raw.len() != expected_packed as usize { + warn!( + "payload size mismatch: got {} expected {} for {}x{}", + raw.len(), + expected_packed, + w, + h + ); + continue; + } + + let rgb565 = expand_gray4_packed(&raw, w, h); + let rect = mxcfb_rect { + top: header.y as u32, + left: header.x as u32, + width: w, + height: h, + }; + + if let Err(e) = fb.restore_region(rect, &rgb565) { + error!("restore_region: {e}"); + continue; + } + + let wf = waveform_from_wire(header.waveform); + fb.partial_refresh( + &rect, + PartialRefreshMode::Async, + wf, + display_temp::TEMP_USE_REMARKABLE_DRAW, + dither_mode::EPDC_FLAG_USE_DITHERING_PASSTHROUGH, + 0, + false, + ); + } + + Ok(()) +} + +fn ensure_min_bytes( + stream: &mut std::net::TcpStream, + fd: i32, + buf: &mut Vec, + min: usize, + last_data: &mut Instant, + fb: &mut Framebuffer, +) -> DynResult<()> { + while buf.len() < min { + match poll_fd(fd, IDLE_MS)? { + PollOutcome::Timeout => { + if last_data.elapsed().as_millis() as i32 >= IDLE_MS { + ghost_clear(fb); + *last_data = Instant::now(); + } + } + PollOutcome::Ready => { + if !read_available(stream, buf)? { + buf.clear(); + return Ok(()); + } + *last_data = Instant::now(); + } + } + } + Ok(()) +} + +enum PollOutcome { + Ready, + Timeout, +} + +fn poll_fd(fd: i32, timeout_ms: i32) -> DynResult { + let mut pfd = pollfd { + fd, + events: POLLIN as i16, + revents: 0, + }; + let r = unsafe { poll(&mut pfd, 1, timeout_ms) }; + if r < 0 { + return Err(std::io::Error::last_os_error().into()); + } + if r == 0 { + return Ok(PollOutcome::Timeout); + } + Ok(PollOutcome::Ready) +} + +fn read_available(stream: &mut std::net::TcpStream, buf: &mut Vec) -> DynResult { + let mut tmp = [0u8; 16 * 1024]; + loop { + match stream.read(&mut tmp) { + Ok(0) => return Ok(false), + Ok(n) => { + buf.extend_from_slice(&tmp[..n]); + return Ok(true); + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => return Ok(true), + Err(e) if e.kind() == std::io::ErrorKind::Interrupted => continue, + Err(e) => return Err(e.into()), + } + } +} + +fn waveform_from_wire(v: u8) -> waveform_mode { + match v { + 1 => waveform_mode::WAVEFORM_MODE_DU, + 2 => waveform_mode::WAVEFORM_MODE_GC16, + _ => waveform_mode::WAVEFORM_MODE_AUTO, + } +} + +fn ghost_clear(fb: &mut Framebuffer) { + info!("idle ≥3s — full GC16 refresh"); + let _ = fb.full_refresh( + waveform_mode::WAVEFORM_MODE_GC16, + display_temp::TEMP_USE_REMARKABLE_DRAW, + dither_mode::EPDC_FLAG_USE_DITHERING_PASSTHROUGH, + 0, + false, + ); +} + +fn expand_gray4_packed(packed: &[u8], w: u32, h: u32) -> Vec { + let mut out = Vec::with_capacity((w * h * 2) as usize); + let half_w = (w / 2) as usize; + for y in 0..h as usize { + let row = y * half_w; + for x in 0..half_w { + let b = packed[row + x]; + let n0 = (b >> 4) & 0x0f; + let n1 = b & 0x0f; + out.extend_from_slice(&nibble_gray_rgb565(n0)); + out.extend_from_slice(&nibble_gray_rgb565(n1)); + } + } + out +} + +fn nibble_gray_rgb565(n: u8) -> [u8; 2] { + let g = (n & 0x0f) * 17; + color::RGB(g, g, g).as_native() +} diff --git a/rm-common/Cargo.toml b/rm-common/Cargo.toml new file mode 100644 index 0000000..0dc9f6d --- /dev/null +++ b/rm-common/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "rm-common" +version = "0.1.0" +edition = "2021" + +[lib] +path = "src/lib.rs" + +[features] +default = ["ssh"] +ssh = ["dep:ssh2", "dep:sha2"] + +[dependencies] +clap = { version = "4", features = ["derive", "env"] } +log = "0.4" +serde = { version = "1.0", features = ["derive"] } +sha2 = { version = "0.10", optional = true } +ssh2 = { version = "0.9.5", optional = true } +toml = "0.8" + +[build-dependencies] diff --git a/rm-common/build.rs b/rm-common/build.rs new file mode 100644 index 0000000..590b741 --- /dev/null +++ b/rm-common/build.rs @@ -0,0 +1,103 @@ +use std::env; +use std::path::PathBuf; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-changed=helper/evgrab.c"); + + if env::var("CARGO_FEATURE_SSH").is_err() { + return; + } + + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let c_src = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("helper/evgrab.c"); + + build_helper("armv7", &out_dir, &c_src); + build_helper("aarch64", &out_dir, &c_src); +} + +fn build_helper(arch: &str, out_dir: &PathBuf, c_src: &PathBuf) { + let cc = find_compiler(arch); + let output = out_dir.join(format!("evgrab-{}", arch)); + + eprintln!("Compiling evgrab for {} using {}", arch, cc); + + let status = Command::new(&cc) + .args(["-static", "-Os", "-o"]) + .arg(&output) + .arg(c_src) + .status() + .unwrap_or_else(|e| { + panic!( + "Failed to run cross-compiler '{}': {}\n\ + Install gcc-arm-linux-gnueabihf and gcc-aarch64-linux-gnu, or set {}_CC.", + cc, + e, + arch.to_uppercase() + ) + }); + + if !status.success() { + panic!("Cross-compiler '{}' failed with {}.", cc, status); + } + + if let Some(strip) = find_tool("strip", arch) { + let _ = Command::new(strip).arg(&output).status(); + } +} + +fn find_compiler(arch: &str) -> String { + let env_var = format!("{}_CC", arch.to_uppercase()); + if let Ok(cc) = env::var(&env_var) { + return cc; + } + + for cc in compiler_candidates(arch) { + if command_exists(cc) { + return cc.to_string(); + } + } + + panic!( + "No C cross-compiler found for {arch}. Tried: {}. Set {env_var}.", + compiler_candidates(arch).join(", "), + env_var = env_var, + ); +} + +fn compiler_candidates(arch: &str) -> Vec<&'static str> { + match arch { + "armv7" => vec![ + "arm-none-linux-gnueabihf-gcc", + "arm-linux-musleabihf-gcc", + "arm-linux-gnueabihf-gcc", + ], + "aarch64" => vec!["aarch64-linux-musl-gcc", "aarch64-linux-gnu-gcc"], + _ => panic!("Unknown arch {}", arch), + } +} + +fn find_tool(tool: &str, arch: &str) -> Option { + let prefixes = match arch { + "armv7" => &["arm-none-linux-gnueabihf-", "arm-linux-musleabihf-", "arm-linux-gnueabihf-"][..], + "aarch64" => &["aarch64-linux-musl-", "aarch64-linux-gnu-"][..], + _ => return None, + }; + + for prefix in prefixes { + let name = format!("{}{}", prefix, tool); + if command_exists(&name) { + return Some(name); + } + } + None +} + +fn command_exists(name: &str) -> bool { + Command::new(name) + .arg("--version") + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .is_ok() +} diff --git a/helper/evgrab.c b/rm-common/helper/evgrab.c similarity index 100% rename from helper/evgrab.c rename to rm-common/helper/evgrab.c diff --git a/src/config/cli.rs b/rm-common/src/config/cli.rs similarity index 100% rename from src/config/cli.rs rename to rm-common/src/config/cli.rs diff --git a/src/config/file.rs b/rm-common/src/config/file.rs similarity index 100% rename from src/config/file.rs rename to rm-common/src/config/file.rs diff --git a/src/config/mod.rs b/rm-common/src/config/mod.rs similarity index 98% rename from src/config/mod.rs rename to rm-common/src/config/mod.rs index 158b314..b617a84 100644 --- a/src/config/mod.rs +++ b/rm-common/src/config/mod.rs @@ -97,7 +97,7 @@ impl Config { } /// Expand a leading `~` or `~/` to the user's home directory. -fn expand_tilde(path: &str) -> PathBuf { +pub fn expand_tilde(path: &str) -> PathBuf { if path == "~" { if let Ok(home) = std::env::var("HOME") { return PathBuf::from(home); diff --git a/rm-common/src/device/detect_ssh.rs b/rm-common/src/device/detect_ssh.rs new file mode 100644 index 0000000..5c83009 --- /dev/null +++ b/rm-common/src/device/detect_ssh.rs @@ -0,0 +1,42 @@ +use std::io::Read; + +use ssh2::Session; + +use super::{DeviceProfile, RM2, RMPP}; + +impl DeviceProfile { + /// Detect device via SSH connection. + pub fn detect_via_ssh(session: &Session) -> Result<&'static Self, Box> { + let mut channel = session.channel_session()?; + channel.exec("cat /proc/device-tree/model")?; + + let mut output = String::new(); + channel.read_to_string(&mut output)?; + channel.close()?; + channel.wait_close()?; + + let status = channel.exit_status()?; + if status != 0 { + return Err(format!("Failed to read device model (exit status {})", status).into()); + } + + let model = output.trim(); + if model.is_empty() { + return Err("Device model is empty".into()); + } + + log::debug!("Detected remote device model: {}", model); + + if model.contains("reMarkable Ferrari") { + log::info!("Detected reMarkable Paper Pro"); + return Ok(&RMPP); + } + + if model.contains("reMarkable 2.0") { + log::info!("Detected reMarkable 2"); + return Ok(&RM2); + } + + Err(format!("Unsupported device model: '{}'", model).into()) + } +} diff --git a/rm-common/src/device/mod.rs b/rm-common/src/device/mod.rs new file mode 100644 index 0000000..b517a62 --- /dev/null +++ b/rm-common/src/device/mod.rs @@ -0,0 +1,37 @@ +mod rm2; +mod rmpp; + +#[cfg(feature = "ssh")] +mod detect_ssh; + +pub use rm2::RM2; +pub use rmpp::RMPP; + +/// Device-specific parameters for input handling. +#[derive(Debug, Clone, Copy)] +pub struct DeviceProfile { + #[allow(dead_code)] + pub name: &'static str, + + pub input_event_size: usize, + + pub pen_x_max: i32, + pub pen_y_max: i32, + pub pen_pressure_max: i32, + pub pen_distance_max: i32, + pub pen_tilt_range: i32, + + pub touch_x_max: i32, + pub touch_y_max: i32, + pub touch_resolution: i32, + + pub pen_device: &'static str, + pub touch_device: &'static str, +} + +impl DeviceProfile { + /// Defaults to RM2. For actual detection with SSH, use `detect_via_ssh()` (requires `ssh` feature). + pub fn current() -> &'static Self { + &RM2 + } +} diff --git a/src/device/rm2.rs b/rm-common/src/device/rm2.rs similarity index 100% rename from src/device/rm2.rs rename to rm-common/src/device/rm2.rs diff --git a/src/device/rmpp.rs b/rm-common/src/device/rmpp.rs similarity index 100% rename from src/device/rmpp.rs rename to rm-common/src/device/rmpp.rs diff --git a/src/grab.rs b/rm-common/src/grab.rs similarity index 100% rename from src/grab.rs rename to rm-common/src/grab.rs diff --git a/rm-common/src/lib.rs b/rm-common/src/lib.rs new file mode 100644 index 0000000..644991d --- /dev/null +++ b/rm-common/src/lib.rs @@ -0,0 +1,15 @@ +//! Shared configuration, optional SSH/evgrab helpers, and screen-mirror protocol types. + +pub mod config; +pub mod device; +pub mod orientation; +pub mod protocol; + +#[cfg(feature = "ssh")] +pub mod grab; +#[cfg(feature = "ssh")] +pub mod screen_client; +#[cfg(feature = "ssh")] +pub mod ssh; + +pub use protocol::{UpdateHeader, HEADER_SIZE}; diff --git a/src/orientation.rs b/rm-common/src/orientation.rs similarity index 100% rename from src/orientation.rs rename to rm-common/src/orientation.rs diff --git a/rm-common/src/protocol.rs b/rm-common/src/protocol.rs new file mode 100644 index 0000000..b2b6333 --- /dev/null +++ b/rm-common/src/protocol.rs @@ -0,0 +1,62 @@ +//! Wire format for compressed 4-bit grayscale screen updates. + +/// Header sent before each LZ4 payload (little-endian on wire, 13 bytes). +#[repr(C, packed)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct UpdateHeader { + pub x: u16, + pub y: u16, + pub width: u16, + pub height: u16, + pub waveform: u8, + pub payload_size: u32, +} + +pub const HEADER_SIZE: usize = 13; + +impl UpdateHeader { + pub fn to_bytes(self) -> [u8; HEADER_SIZE] { + let mut b = [0u8; HEADER_SIZE]; + b[0..2].copy_from_slice(&self.x.to_le_bytes()); + b[2..4].copy_from_slice(&self.y.to_le_bytes()); + b[4..6].copy_from_slice(&self.width.to_le_bytes()); + b[6..8].copy_from_slice(&self.height.to_le_bytes()); + b[8] = self.waveform; + b[9..13].copy_from_slice(&self.payload_size.to_le_bytes()); + b + } + + pub fn from_bytes(buf: &[u8]) -> Option { + if buf.len() < HEADER_SIZE { + return None; + } + Some(Self { + x: u16::from_le_bytes(buf[0..2].try_into().ok()?), + y: u16::from_le_bytes(buf[2..4].try_into().ok()?), + width: u16::from_le_bytes(buf[4..6].try_into().ok()?), + height: u16::from_le_bytes(buf[6..8].try_into().ok()?), + waveform: buf[8], + payload_size: u32::from_le_bytes(buf[9..13].try_into().ok()?), + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn header_roundtrip() { + let h = UpdateHeader { + x: 10, + y: 20, + width: 100, + height: 50, + waveform: 1, + payload_size: 1234, + }; + let b = h.to_bytes(); + let d = UpdateHeader::from_bytes(&b).unwrap(); + assert_eq!(d, h); + } +} diff --git a/rm-common/src/screen_client.rs b/rm-common/src/screen_client.rs new file mode 100644 index 0000000..576d26d --- /dev/null +++ b/rm-common/src/screen_client.rs @@ -0,0 +1,189 @@ +//! Upload and run the tablet screen client; reverse SSH tunnel for TCP. + +use std::io::{Read, Write}; +use std::path::Path; +use std::process::{Child, Command, Stdio}; + +use sha2::{Digest, Sha256}; +use ssh2::Session; + +use crate::config::{Auth, Config}; +use crate::grab::Arch; + +pub const REMOTE_CLIENT_PATH: &str = "/tmp/rm-client-screen"; + +/// ELF `e_machine` values we care about. +const EM_ARM: u16 = 40; +const EM_AARCH64: u16 = 183; + +/// Ensure `data` is an ELF executable built for the tablet architecture. +/// +/// Catches the common mistake of passing `target/debug/rm-client-screen` built for the host +/// (e.g. x86_64), which cannot run on the reMarkable and causes the reverse tunnel to never connect. +pub fn validate_client_elf_for_arch(data: &[u8], arch: Arch) -> Result<(), String> { + if data.len() < 20 { + return Err("client binary too small to be a valid ELF".into()); + } + if data[0] != 0x7f || data[1] != b'E' || data[2] != b'L' || data[3] != b'F' { + return Err("client binary is not an ELF file (did you pass the right path?)".into()); + } + let ei_class = data[4]; + if ei_class != 1 && ei_class != 2 { + return Err("unsupported ELF class".into()); + } + let machine = u16::from_le_bytes([data[18], data[19]]); + let ok = match arch { + Arch::Armv7 => machine == EM_ARM, + Arch::Aarch64 => machine == EM_AARCH64, + }; + if !ok { + let arch_name = match arch { + Arch::Armv7 => "armv7 (32-bit ARM, e_machine=40)", + Arch::Aarch64 => "aarch64 (e_machine=183)", + }; + return Err(format!( + "client binary ELF architecture does not match tablet ({arch_name}); got e_machine={machine}. \ + Build for the tablet, e.g. `cargo build -p rm-client-screen --release --target armv7-unknown-linux-gnueabihf` \ + (reMarkable 2) or `--target aarch64-unknown-linux-gnu` (Paper Pro), then pass that binary to --client-binary." + )); + } + Ok(()) +} + +fn compute_hash(data: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(data); + format!("{:x}", hasher.finalize()) +} + +fn remote_hash_matches(session: &Session, expected: &str) -> Result> { + let mut channel = session.channel_session()?; + channel.exec(&format!( + "sha256sum {} 2>/dev/null | cut -d' ' -f1", + REMOTE_CLIENT_PATH + ))?; + let mut output = String::new(); + channel.read_to_string(&mut output)?; + channel.close()?; + channel.wait_close()?; + if channel.exit_status()? != 0 { + return Ok(false); + } + Ok(output.trim() == expected) +} + +fn upload_bytes( + session: &Session, + data: &[u8], +) -> Result<(), Box> { + let mut channel = session.channel_session()?; + let path = REMOTE_CLIENT_PATH; + channel.exec(&format!( + "cat > {path}.$$ && chmod +x {path}.$$ && mv -f {path}.$$ {path}" + ))?; + channel.write_all(data)?; + channel.send_eof()?; + channel.wait_eof()?; + channel.close()?; + channel.wait_close()?; + if channel.exit_status()? != 0 { + return Err("upload rm-client-screen failed".into()); + } + Ok(()) +} + +/// Ensure `/tmp/rm-client-screen` exists and matches `binary` bytes. +pub fn ensure_client_on_device( + session: &Session, + binary: &[u8], +) -> Result<(), Box> { + let h = compute_hash(binary); + if remote_hash_matches(session, &h)? { + log::debug!("rm-client-screen already up to date on device"); + return Ok(()); + } + log::info!( + "Uploading rm-client-screen ({} bytes, sha256 {}...) to {}", + binary.len(), + &h[..16.min(h.len())], + REMOTE_CLIENT_PATH + ); + upload_bytes(session, binary)?; + Ok(()) +} + +/// Build `ssh` argv for key-based auth (password auth is not supported for the tunnel subprocess). +pub fn ssh_base_args(config: &Config) -> Result, Box> { + match config.auth() { + Auth::Key(path) => { + let expanded = crate::config::expand_tilde(path.to_string_lossy().as_ref()); + Ok(vec![ + "-i".into(), + expanded.to_string_lossy().into_owned(), + ]) + } + Auth::Password(_) => Err( + "rm-screen reverse tunnel needs SSH public-key auth (password-only is not supported for OpenSSH -R). \ + Set key_path in rm-pad.toml or use --key-path." + .into(), + ), + } +} + +/// Spawn `ssh -R remote_port:local_host:local_port ... exec remote_cmd`. +/// Keep the child alive for the lifetime of the screen session; kill it on shutdown. +/// +/// When `stderr_inherit` is true, the child's stderr is inherited so OpenSSH messages +/// (e.g. "Exec format error", permission denied) show in the terminal. +pub fn spawn_reverse_tunnel( + config: &Config, + remote_forward_port: u16, + local_host: &str, + local_port: u16, + remote_cmd: &str, + stderr_inherit: bool, +) -> Result> { + let mut args = vec![ + "-o".into(), + "BatchMode=yes".into(), + "-o".into(), + "ServerAliveInterval=15".into(), + "-o".into(), + "ExitOnForwardFailure=yes".into(), + "-o".into(), + "StrictHostKeyChecking=accept-new".into(), + "-p".into(), + "22".into(), + ]; + args.extend(ssh_base_args(config)?); + args.push("-R".into()); + args.push(format!("{}:{}:{}", remote_forward_port, local_host, local_port)); + args.push(format!("root@{}", config.host)); + args.push(remote_cmd.into()); + + log::info!("Starting reverse SSH tunnel: ssh {}", args.join(" ")); + + let stderr = if stderr_inherit { + Stdio::inherit() + } else { + Stdio::piped() + }; + + let child = Command::new("ssh") + .args(&args) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(stderr) + .spawn()?; + + Ok(child) +} + +/// Load client binary for the given tablet architecture from disk. +pub fn load_client_binary(path: &Path) -> Result, Box> { + let data = std::fs::read(path)?; + if data.is_empty() { + return Err(format!("client binary is empty: {}", path.display()).into()); + } + Ok(data) +} diff --git a/src/ssh.rs b/rm-common/src/ssh.rs similarity index 100% rename from src/ssh.rs rename to rm-common/src/ssh.rs diff --git a/rm-pad/Cargo.toml b/rm-pad/Cargo.toml new file mode 100644 index 0000000..369522a --- /dev/null +++ b/rm-pad/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "rm-pad" +version = "0.1.0" +edition = "2021" + +[dependencies] +rm-common = { path = "../rm-common", features = ["ssh"] } +clap = { version = "4", features = ["derive", "env"] } +env_logger = "0.11" +evdevil = "0.4.0" +log = "0.4" +socket2 = { version = "0.5", features = ["all"] } diff --git a/rm-pad/build.rs b/rm-pad/build.rs new file mode 100644 index 0000000..cec8aa5 --- /dev/null +++ b/rm-pad/build.rs @@ -0,0 +1,101 @@ +use std::env; +use std::path::PathBuf; +use std::process::Command; + +/// Cross-compile evgrab; source lives in `rm-common/helper`. +fn main() { + println!("cargo:rerun-if-changed=../rm-common/helper/evgrab.c"); + + let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); + let c_src = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("../rm-common/helper/evgrab.c"); + + build_helper("armv7", &out_dir, &c_src); + build_helper("aarch64", &out_dir, &c_src); +} + +fn build_helper(arch: &str, out_dir: &PathBuf, c_src: &PathBuf) { + let cc = find_compiler(arch); + let output = out_dir.join(format!("evgrab-{}", arch)); + + eprintln!("Compiling evgrab for {} using {}", arch, cc); + + let status = Command::new(&cc) + .args(["-static", "-Os", "-o"]) + .arg(&output) + .arg(c_src) + .status() + .unwrap_or_else(|e| { + panic!( + "Failed to run cross-compiler '{}': {}\n\ + Install gcc-arm-linux-gnueabihf and gcc-aarch64-linux-gnu, or set {}_CC.", + cc, + e, + arch.to_uppercase() + ) + }); + + if !status.success() { + panic!("Cross-compiler '{}' failed with {}.", cc, status); + } + + if let Some(strip) = find_tool("strip", arch) { + let _ = Command::new(strip).arg(&output).status(); + } +} + +fn find_compiler(arch: &str) -> String { + let env_var = format!("{}_CC", arch.to_uppercase()); + if let Ok(cc) = env::var(&env_var) { + return cc; + } + + for cc in compiler_candidates(arch) { + if command_exists(cc) { + return cc.to_string(); + } + } + + panic!( + "No C cross-compiler found for {arch}. Tried: {}. Set {env_var}.", + compiler_candidates(arch).join(", "), + env_var = env_var, + ); +} + +fn compiler_candidates(arch: &str) -> Vec<&'static str> { + match arch { + "armv7" => vec![ + "arm-none-linux-gnueabihf-gcc", + "arm-linux-musleabihf-gcc", + "arm-linux-gnueabihf-gcc", + ], + "aarch64" => vec!["aarch64-linux-musl-gcc", "aarch64-linux-gnu-gcc"], + _ => panic!("Unknown arch {}", arch), + } +} + +fn find_tool(tool: &str, arch: &str) -> Option { + let prefixes = match arch { + "armv7" => &["arm-none-linux-gnueabihf-", "arm-linux-musleabihf-", "arm-linux-gnueabihf-"][..], + "aarch64" => &["aarch64-linux-musl-", "aarch64-linux-gnu-"][..], + _ => return None, + }; + + for prefix in prefixes { + let name = format!("{}{}", prefix, tool); + if command_exists(&name) { + return Some(name); + } + } + None +} + +fn command_exists(name: &str) -> bool { + Command::new(name) + .arg("--version") + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .is_ok() +} diff --git a/src/dump.rs b/rm-pad/src/dump.rs similarity index 95% rename from src/dump.rs rename to rm-pad/src/dump.rs index 7e4e60d..be4bb9d 100644 --- a/src/dump.rs +++ b/rm-pad/src/dump.rs @@ -1,9 +1,9 @@ use std::io::Read; -use crate::config::Config; -use crate::device::DeviceProfile; use crate::input::parse_input_event; -use crate::ssh; +use rm_common::config::Config; +use rm_common::device::DeviceProfile; +use rm_common::ssh; pub fn run_touch( config: &Config, diff --git a/src/input/event.rs b/rm-pad/src/input/event.rs similarity index 100% rename from src/input/event.rs rename to rm-pad/src/input/event.rs diff --git a/src/input/mod.rs b/rm-pad/src/input/mod.rs similarity index 100% rename from src/input/mod.rs rename to rm-pad/src/input/mod.rs diff --git a/src/input/pen.rs b/rm-pad/src/input/pen.rs similarity index 97% rename from src/input/pen.rs rename to rm-pad/src/input/pen.rs index f38a86d..74238e3 100644 --- a/src/input/pen.rs +++ b/rm-pad/src/input/pen.rs @@ -5,11 +5,11 @@ use evdevil::event::{Abs, InputEvent, Key}; use evdevil::uinput::{AbsSetup, UinputDevice}; use evdevil::{AbsInfo, Bus, InputId, InputProp}; -use crate::config::Config; -use crate::device::DeviceProfile; -use crate::orientation::Orientation; use crate::palm::SharedPalmState; -use crate::ssh; +use rm_common::config::Config; +use rm_common::device::DeviceProfile; +use rm_common::orientation::Orientation; +use rm_common::ssh; use super::event::{key_event, parse_input_event, ABS_PRESSURE, EV_ABS, EV_SYN, SYN_REPORT}; diff --git a/src/input/touch.rs b/rm-pad/src/input/touch.rs similarity index 99% rename from src/input/touch.rs rename to rm-pad/src/input/touch.rs index 9ac49b3..599227a 100644 --- a/src/input/touch.rs +++ b/rm-pad/src/input/touch.rs @@ -5,11 +5,11 @@ use evdevil::event::{Abs, Key, KeyEvent, KeyState}; use evdevil::uinput::{AbsSetup, UinputDevice}; use evdevil::{AbsInfo, InputProp, Slot}; -use crate::config::Config; -use crate::device::DeviceProfile; -use crate::orientation::Orientation; use crate::palm::SharedPalmState; -use crate::ssh; +use rm_common::config::Config; +use rm_common::device::DeviceProfile; +use rm_common::orientation::Orientation; +use rm_common::ssh; use super::event::{ parse_input_event, ABS_MT_POSITION_X, ABS_MT_POSITION_Y, ABS_MT_SLOT, ABS_MT_TRACKING_ID, diff --git a/src/main.rs b/rm-pad/src/main.rs similarity index 97% rename from src/main.rs rename to rm-pad/src/main.rs index f56c87f..1b0c096 100644 --- a/src/main.rs +++ b/rm-pad/src/main.rs @@ -1,11 +1,6 @@ -mod config; -mod device; mod dump; -mod grab; mod input; -mod orientation; mod palm; -mod ssh; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -14,8 +9,9 @@ use std::time::Duration; use clap::Parser; -use config::{Cli, Command, Config}; -use device::DeviceProfile; +use rm_common::config::{Cli, Command, Config}; +use rm_common::device::DeviceProfile; +use rm_common::ssh; use palm::{PalmState, SharedPalmState}; type Result = std::result::Result>; diff --git a/src/palm.rs b/rm-pad/src/palm.rs similarity index 100% rename from src/palm.rs rename to rm-pad/src/palm.rs diff --git a/rm-screen/Cargo.toml b/rm-screen/Cargo.toml new file mode 100644 index 0000000..bca4053 --- /dev/null +++ b/rm-screen/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rm-screen" +version = "0.1.0" +edition = "2021" + +[dependencies] +ashpd = { version = "0.13.9", default-features = false, features = ["tokio", "remote_desktop", "screencast"] } +rm-common = { path = "../rm-common", features = ["ssh"] } +clap = { version = "4", features = ["derive", "env"] } +env_logger = "0.11" +lamco-pipewire = { version = "0.4.2", default-features = false, features = ["damage"] } +lamco-portal = "0.4.0" +log = "0.4" +lz4_flex = "0.11" +socket2 = { version = "0.5", features = ["all"] } +tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal", "sync", "time"] } diff --git a/rm-screen/src/main.rs b/rm-screen/src/main.rs new file mode 100644 index 0000000..d656f10 --- /dev/null +++ b/rm-screen/src/main.rs @@ -0,0 +1,391 @@ +//! PC-side screen mirror: PipeWire (via portal) → dirty regions → LZ4 → TCP to tablet. + +use std::io::Write; +use std::net::TcpListener; +use std::os::fd::{AsRawFd, FromRawFd, OwnedFd}; +use std::path::PathBuf; +use std::process::Child; +use std::sync::mpsc; +use std::time::Duration; + +use ashpd::desktop::PersistMode; +use clap::Parser; +use lamco_pipewire::damage::{DamageConfig, DamageDetector, DetectedRegion}; +use lamco_pipewire::format::PixelFormat; +use lamco_pipewire::{PipeWireConfig, PipeWireManager, SourceType, StreamInfo, VideoFrame}; +use lamco_portal::{PortalConfig, PortalManager}; +use log::{error, info, warn}; +use rm_common::config::Config; +use rm_common::device::DeviceProfile; +use rm_common::grab; +use rm_common::protocol::UpdateHeader; +use rm_common::screen_client::{ + ensure_client_on_device, load_client_binary, spawn_reverse_tunnel, validate_client_elf_for_arch, +}; +use rm_common::ssh; +use socket2::{Socket, TcpKeepalive}; + +type DynResult = Result>; + +const WAVEFORM_DU: u8 = 1; + +#[derive(Parser)] +#[command(name = "rm-screen")] +#[command(about = "Mirror PC screen to reMarkable over PipeWire and custom TCP")] +struct ScreenCli { + /// reMarkable host (IP or hostname) + #[arg(long, env = "RMPAD_HOST")] + host: Option, + + #[arg(long)] + key_path: Option, + + #[arg(long, env = "RMPAD_PASSWORD")] + password: Option, + + #[arg(long, env = "RMPAD_CONFIG")] + config: Option, + + /// Cross-compiled rm-client-screen binary (armv7 or aarch64) + #[arg(long, env = "RM_CLIENT_SCREEN_BIN")] + client_binary: PathBuf, + + /// Local port the tablet connects to (via reverse SSH) + #[arg(long, default_value_t = 9876)] + local_port: u16, + + /// Remote port on the tablet side (forwarded to local_port) + #[arg(long, default_value_t = 9876)] + remote_port: u16, + + /// Seconds to wait for the tablet client to connect after the SSH tunnel starts + #[arg(long, default_value_t = 120)] + accept_timeout_secs: u64, +} + +#[tokio::main] +async fn main() -> DynResult<()> { + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); + + let screen_cli = ScreenCli::parse(); + let device = DeviceProfile::current(); + let config = load_merged_config(&screen_cli, device); + + info!("Connecting to {} for device detection…", config.host); + if config.host.contains("10.11.99.") { + info!( + "USB Ethernet: the tablet is usually 10.11.99.1 and your PC often gets 10.11.99.x — \ + SSH must target the tablet ({})", + config.host + ); + } + let session = ssh::connect_for_detection(&config)?; + let device = DeviceProfile::detect_via_ssh(&session)?; + info!("Device: {}", device.name); + + let arch = grab::detect_arch(&session)?; + info!("Tablet CPU architecture: {} (use a matching cross-compiled rm-client-screen)", arch); + let client_bytes = load_client_binary(&screen_cli.client_binary)?; + validate_client_elf_for_arch(&client_bytes, arch).map_err(|e| -> Box { e.into() })?; + ensure_client_on_device(&session, &client_bytes)?; + drop(session); + + let listener = TcpListener::bind(("127.0.0.1", screen_cli.local_port))?; + + lamco_pipewire::init(); + + // Remote-desktop portal sessions must not request persistence (GNOME/KDE reject it). + let portal_config = PortalConfig::builder() + .persist_mode(PersistMode::DoNot) + .build(); + let portal = PortalManager::new(portal_config).await?; + let (portal_session, _token) = portal + .create_session("rm-screen".to_string(), None) + .await + .map_err(|e| format!("portal session failed: {e}"))?; + + let pw_fd = unsafe { OwnedFd::from_raw_fd(portal_session.pipewire_fd()) }; + + let pw_config = PipeWireConfig::builder() + .use_dmabuf(false) + .preferred_format(PixelFormat::BGRA) + .enable_damage_tracking(true) + .frame_buffer_size(8) + .build(); + + let mut pw = PipeWireManager::new(pw_config)?; + pw.connect(pw_fd).await?; + + let streams = portal_session.streams(); + if streams.is_empty() { + return Err("portal returned no PipeWire streams".into()); + } + let s0 = &streams[0]; + let stream_info = StreamInfo { + node_id: s0.node_id, + position: s0.position, + size: s0.size, + source_type: match s0.source_type { + lamco_portal::SourceType::Monitor => SourceType::Monitor, + lamco_portal::SourceType::Window => SourceType::Window, + lamco_portal::SourceType::Virtual => SourceType::Virtual, + }, + }; + + let handle = pw.create_stream(&stream_info).await?; + let mut rx = pw + .frame_receiver(handle.id) + .await + .ok_or("frame receiver already taken")?; + + let remote_cmd = format!( + "exec {} 127.0.0.1 {}", + rm_common::screen_client::REMOTE_CLIENT_PATH, + screen_cli.remote_port + ); + let mut tunnel: Child = spawn_reverse_tunnel( + &config, + screen_cli.remote_port, + "127.0.0.1", + screen_cli.local_port, + &remote_cmd, + true, + )?; + + let (tx, rx_sock) = mpsc::channel::>(); + let lis = listener; + std::thread::spawn(move || { + let _ = tx.send(lis.accept().map(|(s, _)| s)); + }); + + let deadline = std::time::Instant::now() + Duration::from_secs(screen_cli.accept_timeout_secs); + let sock = loop { + if let Some(status) = tunnel.try_wait()? { + return Err(format!( + "SSH reverse tunnel exited before the tablet connected (exit status {:?}). \ + If stderr above mentions \"Exec format error\" or similar, cross-compile rm-client-screen for {}. \ + Also check sshd `PermitOpen` / reverse forwarding settings.", + status.code(), + arch + ) + .into()); + } + let remaining = deadline.saturating_duration_since(std::time::Instant::now()); + if remaining.is_zero() { + let _ = tunnel.kill(); + let _ = tunnel.wait(); + return Err(format!( + "Timed out after {}s waiting for the tablet to connect to 127.0.0.1:{}. \ + The PC listens here; traffic is tunneled from the tablet via `ssh -R`. \ + Your SSH host ({}) should be the tablet (often 10.11.99.1 over USB); your PC is usually 10.11.99.x. \ + Pass a cross-compiled --client-binary for {} (not `target/debug/rm-client-screen` built for the laptop).", + screen_cli.accept_timeout_secs, + screen_cli.local_port, + config.host, + arch + ) + .into()); + } + let step = Duration::from_secs(1).min(remaining); + match rx_sock.recv_timeout(step) { + Ok(Ok(s)) => break s, + Ok(Err(e)) => return Err(format!("TCP accept failed: {e}").into()), + Err(mpsc::RecvTimeoutError::Timeout) => continue, + Err(mpsc::RecvTimeoutError::Disconnected) => { + return Err("TCP accept thread ended unexpectedly".into()); + } + } + }; + configure_tcp_stream(&sock)?; + + let mut sock = sock; + let mut damage = DamageDetector::new(DamageConfig::low_bandwidth()); + + while let Some(frame) = rx.recv().await { + if let Err(e) = process_frame(&mut sock, &mut damage, &frame) { + error!("stream error: {e}"); + break; + } + } + + let _ = tunnel.kill(); + let _ = tunnel.wait(); + pw.shutdown().await.ok(); + lamco_pipewire::deinit(); + portal.cleanup().await.ok(); + + Ok(()) +} + +fn load_merged_config(cli: &ScreenCli, device: &'static DeviceProfile) -> Config { + let fake_cli = rm_common::config::Cli { + command: None, + host: cli.host.clone(), + key_path: cli.key_path.clone(), + password: cli.password.clone(), + pen_device: None, + touch_device: None, + touch_only: false, + pen_only: false, + grab_input: true, + no_grab_input: false, + no_palm_rejection: false, + palm_grace_ms: None, + orientation: None, + config: cli.config.clone(), + }; + Config::load(&fake_cli, device) +} + +fn configure_tcp_stream(sock: &std::net::TcpStream) -> DynResult<()> { + sock.set_nodelay(true)?; + sock.set_write_timeout(Some(Duration::from_secs(30)))?; + let raw = sock.as_raw_fd(); + let s = unsafe { Socket::from_raw_fd(raw) }; + let ka = TcpKeepalive::new().with_time(Duration::from_secs(30)); + s.set_tcp_keepalive(&ka)?; + std::mem::forget(s); + Ok(()) +} + +fn process_frame( + sock: &mut std::net::TcpStream, + damage: &mut DamageDetector, + frame: &VideoFrame, +) -> DynResult<()> { + let Some(data_arc) = frame.data() else { + warn!("DMA-BUF frame skipped (no CPU pixels); disable GPU-only capture in compositor if this repeats"); + damage.invalidate(); + return Ok(()); + }; + let data = data_arc.as_slice(); + let w = frame.width; + let h = frame.height; + + let regions = regions_for_frame(frame, damage, data, w, h); + + for r in regions { + let (x, y, rw, rh) = clip_region(r, w, h); + if rw < 2 || rh < 1 { + continue; + } + let rw = rw & !1; + let packed = pack_region_gray4(data, frame.stride, frame.format, x, y, rw, rh)?; + let compressed = lz4_flex::block::compress_prepend_size(&packed); + let header = UpdateHeader { + x, + y, + width: rw, + height: rh, + waveform: WAVEFORM_DU, + payload_size: compressed.len() as u32, + }; + sock.write_all(&header.to_bytes())?; + sock.write_all(&compressed)?; + sock.flush()?; + } + + Ok(()) +} + +fn regions_for_frame( + frame: &VideoFrame, + damage: &mut DamageDetector, + data: &[u8], + w: u32, + h: u32, +) -> Vec { + let mut from_meta: Vec = frame + .damage_regions + .iter() + .filter(|d| d.is_valid()) + .map(|d| DetectedRegion { + x: d.x.max(0) as u32, + y: d.y.max(0) as u32, + width: d.width, + height: d.height, + }) + .collect(); + + if !from_meta.is_empty() { + from_meta.retain(|r| r.x < w && r.y < h); + for r in &mut from_meta { + r.width = r.width.min(w.saturating_sub(r.x)); + r.height = r.height.min(h.saturating_sub(r.y)); + } + from_meta.retain(|r| r.width >= 2 && r.height >= 1); + if !from_meta.is_empty() { + return from_meta; + } + } + + damage.detect(data, w, h) +} + +fn clip_region(r: DetectedRegion, w: u32, h: u32) -> (u16, u16, u16, u16) { + let x = r.x.min(w.saturating_sub(1)); + let y = r.y.min(h.saturating_sub(1)); + let rw = r.width.min(w.saturating_sub(x)); + let rh = r.height.min(h.saturating_sub(y)); + (x as u16, y as u16, rw as u16, rh as u16) +} + +fn gray_from_pixel(format: PixelFormat, chunk: &[u8]) -> Option { + if chunk.len() < 3 { + return None; + } + let (r, g, b) = match format { + PixelFormat::BGRA | PixelFormat::BGRx => (chunk[2], chunk[1], chunk[0]), + PixelFormat::RGBA | PixelFormat::RGBx => (chunk[0], chunk[1], chunk[2]), + PixelFormat::RGB => { + if chunk.len() < 3 { + return None; + } + (chunk[0], chunk[1], chunk[2]) + } + PixelFormat::BGR => (chunk[2], chunk[1], chunk[0]), + PixelFormat::GRAY8 => return Some(chunk[0]), + _ => { + if chunk.len() >= 4 { + (chunk[2], chunk[1], chunk[0]) + } else { + return None; + } + } + }; + Some(((r as u16 * 77 + g as u16 * 150 + b as u16 * 29) >> 8) as u8) +} + +fn pack_region_gray4( + data: &[u8], + stride: u32, + format: PixelFormat, + ox: u16, + oy: u16, + w: u16, + h: u16, +) -> DynResult> { + let bpp = format.bytes_per_pixel().max(3); + let stride = stride as usize; + let mut out = Vec::with_capacity((w as usize / 2) * h as usize); + for row in 0..h { + let y = oy as usize + row as usize; + let row_off = y * stride; + for col in (0..w).step_by(2) { + let x0 = ox as usize + col as usize; + let x1 = x0 + 1; + let o0 = row_off + x0 * bpp; + let o1 = row_off + x1 * bpp; + let g0 = gray_from_pixel(format, &data[o0..data.len().min(o0 + bpp)]).unwrap_or(0); + let g1 = if x1 * bpp <= stride { + gray_from_pixel(format, &data[o1..data.len().min(o1 + bpp)]).unwrap_or(0) + } else { + 0 + }; + let n0 = (g0 >> 4) & 0x0f; + let n1 = (g1 >> 4) & 0x0f; + out.push((n0 << 4) | n1); + } + } + Ok(out) +} diff --git a/src/device/mod.rs b/src/device/mod.rs deleted file mode 100644 index 692a5b7..0000000 --- a/src/device/mod.rs +++ /dev/null @@ -1,82 +0,0 @@ -mod rm2; -mod rmpp; - -use std::io::Read; - -pub use rm2::RM2; -pub use rmpp::RMPP; - -/// Device-specific parameters for input handling. -#[derive(Debug, Clone, Copy)] -pub struct DeviceProfile { - #[allow(dead_code)] - pub name: &'static str, - - // Raw input_event size on the device (bytes) - pub input_event_size: usize, - - // Pen digitizer ranges - pub pen_x_max: i32, - pub pen_y_max: i32, - pub pen_pressure_max: i32, - pub pen_distance_max: i32, - pub pen_tilt_range: i32, - - // Touch screen dimensions - pub touch_x_max: i32, - pub touch_y_max: i32, - pub touch_resolution: i32, - - // Default device paths - pub pen_device: &'static str, - pub touch_device: &'static str, -} - -impl DeviceProfile { - /// Get profile for the current device. - /// - /// Defaults to RM2. For actual detection, use `detect_via_ssh()`. - pub fn current() -> &'static Self { - &RM2 - } - - /// Detect device via SSH connection. - /// - /// Reads the device model from /proc/device-tree/model on the remote device. - /// Returns an error if the model cannot be detected or is unsupported. - pub fn detect_via_ssh(session: &ssh2::Session) -> Result<&'static Self, Box> { - let mut channel = session.channel_session()?; - channel.exec("cat /proc/device-tree/model")?; - - let mut output = String::new(); - channel.read_to_string(&mut output)?; - channel.close()?; - channel.wait_close()?; - - let status = channel.exit_status()?; - if status != 0 { - return Err(format!("Failed to read device model (exit status {})", status).into()); - } - - let model = output.trim(); - if model.is_empty() { - return Err("Device model is empty".into()); - } - - log::debug!("Detected remote device model: {}", model); - - // Check for rMPP first (more specific) - if model.contains("reMarkable Ferrari") { - log::info!("Detected reMarkable Paper Pro"); - return Ok(&RMPP); - } - - // Check for RM2 (matches "reMarkable 2.0", "reMarkable 2", etc.) - if model.contains("reMarkable 2.0") { - log::info!("Detected reMarkable 2"); - return Ok(&RM2); - } - - Err(format!("Unsupported device model: '{}'", model).into()) - } -}