Skip to content

Add workspace: rm-common, rm-screen, rm-client-screen (PipeWire screen mirror) - #7

Draft
alvesvaren wants to merge 3 commits into
mainfrom
cursor/screen-mirror-workspace-28fd
Draft

alvesvaren wants to merge 3 commits into
mainfrom
cursor/screen-mirror-workspace-28fd

Conversation

@alvesvaren

Copy link
Copy Markdown
Owner

Summary

This change turns the repo into a Cargo workspace and adds low-latency PC→reMarkable screen mirroring alongside the existing rm-pad input tool.

Crates

  • rm-common — Shared config (CLI + TOML), device profiles, optional SSH/evgrab (ssh feature), UpdateHeader wire format, and helpers to upload/run the tablet client plus spawn a reverse SSH tunnel.
  • rm-pad — Unchanged behavior; depends on rm-common with SSH enabled; build.rs still cross-compiles evgrab from rm-common/helper/.
  • rm-screen — Wayland screen capture via XDG Desktop Portal + PipeWire (lamco-portal, lamco-pipewire with damage). Uses PipeWire damage metadata when present, otherwise tile-based frame differencing. Converts regions to 4-bit packed grayscale, LZ4-compresses with size prefix, sends 13-byte little-endian headers + payload over TCP with TCP_NODELAY. Starts the reverse SSH tunnel after PipeWire is ready so the tablet can connect without blocking tunnel setup.
  • rm-client-screen — Listens on TCP, reads headers, decompresses LZ4, uses libremarkable restore_region + partial_refresh with DU (wire value 1). After 3s without receiving data, triggers a full-screen GC16 refresh to reduce ghosting.

Cross-compilation

rm-common defaults to ssh for host tools; rm-client-screen uses default-features = false so it does not pull openssl-sys for ARM targets. .cargo/config.toml sets GCC as the linker for armv7-unknown-linux-gnueabihf and aarch64-unknown-linux-gnu.

CI / packaging

GitHub Actions and PKGBUILD install libssl-dev, pkg-config, and libpipewire-0.3-dev; release tarball includes rm-screen in addition to rm-pad.

Usage notes

  • Build tablet binary: cargo build -p rm-client-screen --release --target armv7-unknown-linux-gnueabihf (or aarch64-unknown-linux-gnu for Paper Pro).
  • Run on PC: rm-screen --client-binary /path/to/rm-client-screen (plus usual RMPAD_HOST / key options). Reverse tunnel requires SSH key auth (password-only is rejected with a clear error).
Open in Web Open in Cursor 

Split shared SSH/config/device/grab code into rm-common. rm-pad remains the
input forwarder; rm-screen captures via XDG portal + PipeWire, tracks dirty
regions, packs 4-bit grayscale with LZ4, and streams over TCP with TCP_NODELAY.
rm-client-screen uses libremarkable to restore RGB565 regions and refresh the
e-paper display, with a 3s idle GC16 full refresh.

Reverse SSH (-R) starts the tablet client after PipeWire is ready so the TCP
accept does not block the tunnel. rm-common ssh2 is optional so the tablet
binary cross-compiles without OpenSSL for the target.

CI installs libssl-dev, pkg-config, and libpipewire-0.3-dev; PKGBUILD and
release workflow build rm-screen alongside rm-pad.

Co-authored-by: Alve Svarén <alve@hotmail.se>
@alvesvaren

Copy link
Copy Markdown
Owner Author

@cursor

Error: "portal session failed: Session creation failed: Source selection: Portal request failed: org.freedesktop.portal.Error.InvalidArgument: Remote desktop sessions cannot persist"

when running cargo run --bin rm-screen -- --client-binary target/debug/rm-client-screen

@cursor

cursor Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

Here is what was going wrong and what we changed.

Cause

lamco-portal’s default PortalConfig sets persist_mode to PersistMode::ExplicitlyRevoked (see its Default impl). That tells the portal to persist the session.

For Remote Desktop sessions, several implementations (your error matches this) do not allow any persist mode other than “do not persist”. They answer with:

org.freedesktop.portal.Error.InvalidArgument: Remote desktop sessions cannot persist

So select_sources failed during session creation.

Fix

rm-screen no longer uses PortalManager::with_default(). It builds a custom config with:

PortalConfig::builder()
    .persist_mode(PersistMode::DoNot)
    .build()

and passes that to PortalManager::new(...).

A direct ashpd dependency was added in rm-screen/Cargo.toml (same version as in the lockfile, with tokio + remote_desktop + screencast) so we can import PersistMode without relying on a re-export.

Trade-off

You may get the permission dialog every run instead of “remember forever”, which is what portals allow for this session type.

The change is committed and pushed on cursor/screen-mirror-workspace-28fd (commit e1476a3). Re-run:

cargo run --bin rm-screen -- --client-binary …

Open in Web Open in Cursor 

lamco-portal defaults to ExplicitlyRevoked persistence, which many portals
reject for remote-desktop sessions (InvalidArgument: cannot persist).
Build PortalConfig with DoNot so source selection succeeds.

Co-authored-by: Alve Svarén <alve@hotmail.se>
@alvesvaren

Copy link
Copy Markdown
Owner Author

@cursor

➜ rm-mouse git:(cursor/screen-mirror-workspace-28fd) cargo run --bin rm-screen -- --client-binary target/debug/rm-client-screen
Compiling rm-screen v0.1.0 (/home/alve-skola/dev/rm-mouse/rm-screen)
Finished dev profile [unoptimized + debuginfo] target(s) in 2.07s
Running target/debug/rm-screen --client-binary target/debug/rm-client-screen
[2026-04-09T21:47:11Z INFO rm_screen] Connecting to 10.11.99.1 for device detection…
[2026-04-09T21:47:11Z INFO rm_common::device::detect_ssh] Detected reMarkable 2
[2026-04-09T21:47:11Z INFO rm_screen] Device: reMarkable 2
[2026-04-09T21:47:17Z INFO rm_common::screen_client] Starting reverse SSH tunnel: ssh -o BatchMode=yes -o ServerAliveInterval=15 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=accept-new -p 22 -i rm-key -R 9876:127.0.0.1:9876 root@10.11.99.1 exec /tmp/rm-client-screen 127.0.0.1 9876
Error: "timed out waiting for tablet TCP connection (check SSH reverse tunnel)"

I wonder if the IP is correct. The laptop that is connected to the remarkable has the ip 10.11.99.10

@cursor

cursor Bot commented Apr 9, 2026 •

Copy link
Copy Markdown

About the IPs

For USB tethering, 10.11.99.1 is normally the tablet and 10.11.99.10 is your laptop. You should keep RMPAD_HOST / SSH pointed at 10.11.99.1 (the reMarkable), not at the laptop. The log line Connecting to 10.11.99.1 is the right target.

Why it timed out

The usual mistake is passing target/debug/rm-client-screen built on the laptop (x86_64). That file is uploaded to /tmp/rm-client-screen on the tablet, but ARM cannot run it. The remote exec then fails immediately (often “Exec format error”), so nothing ever connects to your PC’s 127.0.0.1:9876, and you see a timeout.

What we changed (pushed on the PR branch)

  1. ELF check — After detecting the tablet arch over SSH, we verify --client-binary is ARM ELF for rM2 or AARCH64 for Paper Pro. If you pass a host binary, you get an error before upload, with the correct cargo build --target … hint.

  2. USB hint — If the host looks like 10.11.99.*, we log that .1 is usually the tablet and .x is often the PC.

  3. Longer wait — Default accept wait is 120s (was 30s), with --accept-timeout-secs to override.

  4. SSH stderr — The tunnel’s stderr is inherited, so OpenSSH messages (e.g. exec errors) show in your terminal.

What you should run

Cross-compile for reMarkable 2, then point --client-binary at that path:

cargo build -p rm-client-screen --release --target armv7-unknown-linux-gnueabihf
cargo run --bin rm-screen -- --client-binary target/armv7-unknown-linux-gnueabihf/release/rm-client-screen

(Paper Pro: --target aarch64-unknown-linux-gnu and the matching target/.../release/rm-client-screen.)

Commit 565aad8 is on cursor/screen-mirror-workspace-28fd.

Open in Web Open in Cursor 

…er accept wait

- Reject host-built rm-client-screen via ELF e_machine vs tablet arch from SSH
- Log 10.11.99.x USB hint (tablet is usually .1, PC often .10)
- Poll accept loop with configurable --accept-timeout-secs (default 120s)
- Inherit SSH stderr so OpenSSH errors (e.g. Exec format error) are visible
- Clearer timeout message referencing correct host and cross-compile targets

Co-authored-by: Alve Svarén <alve@hotmail.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants