Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

spacedesk-linux

Turn any Linux machine into a network display host — an open, native re-implementation of the spacedesk server for Linux.

spacedesk-linux streams this computer's screen over the local network to any browser or phone (JPEG over WebSocket, plus a classic MJPEG endpoint), injects the client's mouse/keyboard back into the desktop, and advertises itself on the LAN with UDP discovery — so a client app can find the host automatically.

It ships two servers:

  • serve — its own open protocol with the bundled HTML viewer, and
  • serve --compat — a re-implementation of the spacedesk protocol, so the official spacedesk viewer apps (Android / iOS / desktop / HTML5) can connect to a Linux host.

It is independent: no spacedesk code is reused. The protocol was reconstructed from a shipped spacedesk client — see docs/SPACEDESK-PROTOCOL.md.


Why this exists — how spacedesk works, and how Linux maps onto it

The original product ships as a Windows MSI containing 8 kernel drivers and 4 user-mode binaries. A reverse-engineering pass over spacedesk_driver_Win_11_64_v2233.msi (see docs/REVERSE-ENGINEERING.md) recovered this architecture:

spacedesk (Windows) Role spacedesk-linux equivalent
spacedeskDriverBus.sys Virtual bus hosting child devices — (not needed)
spacedeskDisplayUmode*.dll (IddCx) Virtual monitor evdi kernel module, or mirror / Xvfb
spacedeskService.exe → SLIDxgiDuplication Screen capture (DXGI) ffmpeg x11grab / PipeWire
SETaskEncodeJpegCpu (libjpeg-turbo) JPEG encode ffmpeg mjpeg
SETaskEncodeMftH264 (Media Foundation) H.264 encode ffmpeg libx264 (roadmap)
L4/L5/L6 comm stack, TLS, WebSocket Transport asyncio HTTP + WebSocket + MJPEG
L4ThreadNetDiscovery (UDP) LAN discovery UDP beacon/probe
spacedeskKtmInput.sys, HID/mini drivers Input injection Linux uinput / xdotool

The Windows drivers are kernel-mode and cannot run on Linux — there is no "port". Everything they do has an open Linux equivalent, which is what this project assembles into one coherent server.


Architecture

   ┌─────────────────────── spacedesk-linux host ────────────────────────┐
   │                                                                     │
   │   display  ──►  capture backend  ──►  JPEG frames  ──►  FrameHub     │
   │  (mirror /        (ffmpeg x11grab /                      │           │
   │   evdi / Xvfb)     PipeWire / lavfi)                     │           │
   │                                                          ▼           │
   │   uinput / xdotool  ◄── input   ┌────────────────────────────────┐   │
   │        ▲                        │  asyncio server (one TCP port) │   │
   │        │                        │   /            viewer UI       │   │
   │        └── WebSocket text ──────┤   /stream.mjpg MJPEG           │   │
   │            (control channel)    │   /ws          WebSocket frames│   │
   │                                 │   /api/info    JSON status     │   │
   │                                 └────────────────────────────────┘   │
   │   UDP 28253 ◄── discovery beacon/probe ──► clients                    │
   └─────────────────────────────────────────────────────────────────────┘
                                   │
              any browser / phone / VLC / ffplay  ──►  extra screen

Everything is pure Python standard library at runtime; the only external program it needs is ffmpeg (and optionally gst-launch-1.0 for Wayland).


Features

  • Zero Python dependencies — stdlib only (3.9+).
  • Two client transports on one port: WebSocket (low latency, with a control channel) and multipart MJPEG (/stream.mjpg, works in <img>, VLC, ffplay).
  • Bundled browser viewer — canvas rendering, fullscreen, live FPS/bitrate.
  • Remote input — mouse, wheel, keyboard and touch, via uinput (Wayland + X11), falling back to xdotool/ydotool.
  • UDP discovery — spacedesk-linux discover finds hosts on the LAN.
  • Several capture backends — X11/XWayland, PipeWire (Wayland portal), V4L2, a media file, or a synthetic test pattern.
  • Several display modes — mirror, evdi virtual monitor, Xvfb headless, or fully headless.
  • Optional shared-secret token, --name advertising, systemd units and a .deb builder.

Requirements

  • Linux with Python ≥ 3.9
  • ffmpeg (sudo apt install ffmpeg)
  • For a true extra monitor: the evdi kernel module (sudo apt install evdi-dkms && sudo modprobe evdi)
  • For Wayland full-desktop capture: gstreamer1.0-tools + gstreamer1.0-pipewire (xdg-desktop-portal screen cast)
  • For remote input via uinput: read/write access to /dev/uinput (usually by joining the input group: sudo usermod -aG input $USER)

Install

Option A — script (no pip, no sudo for a user install)

git clone <this repo> && cd spacedesk-linux
./scripts/install.sh                 # per-user, installs to ~/.local
# or
sudo ./scripts/install.sh --system   # system-wide, /usr/local

Option B — pip

pip install .            # or: pipx install .

Option C — Debian/Ubuntu package

./packaging/deb/build-deb.sh
sudo apt install ./dist/spacedesk-linux_*_all.deb

Option D — portable AppImage (no install, just run/share)

./packaging/appimage/build-appimage.sh          # bundles CPython + ffmpeg
./dist/spacedesk-linux-0.1.0-x86_64.AppImage doctor

The AppImage is a single self-contained file you can copy to any x86-64 Linux box, chmod +x, and run — nothing to install. Use --slim to skip the bundled ffmpeg (smaller; falls back to the system one).


Quick start

spacedesk-linux doctor                       # check what your machine can do
spacedesk-linux serve                        # mirror the desktop on :28252

Then open http://<host-ip>:28252/ on your phone or another computer.

spacedesk-linux discover                     # find hosts from another machine

Connect the official spacedesk app

spacedesk-linux serve --compat               # speaks the spacedesk protocol on 28252

Then in the spacedesk viewer app, add/connect to this machine's IP on port 28252 (manual IP entry). The server also accepts the official HTML5 viewer from http://viewer.spacedesk.net/. Video is JPEG, and the app's mouse/touch/ keyboard are injected into the Linux desktop.

Both WebSocket and raw TCP are accepted on the same port, so the Android/iOS, desktop and HTML5 viewers all work.

Compatibility is based on the protocol reconstructed from the shipped spacedesk client; see docs/SPACEDESK-PROTOCOL.md for the full specification and the list of what is / isn't implemented.


Usage

spacedesk-linux <command> [options]

commands:
  serve      run the streaming server
  discover   find spacedesk-linux hosts on the LAN
  doctor     print a capability / environment report

serve options

Option Default Meaning
--host 0.0.0.0 Bind address
--port 28252 TCP port (viewer, MJPEG, WebSocket)
--mode mirror mirror · virtual · x11 · xvfb · headless
--backend x11 x11 · lavfi · v4l2 · file · pipewire
--width / --height 1280×720 Capture resolution
--fps 15 Target frame rate
--quality 5 JPEG quality (2 best … 31 smallest)
--display auto X11 display to capture, e.g. :0
--device /dev/video0 V4L2 device
--input-file — Path for --backend file
--token — Shared secret required by clients (own viewer mode)
--compat off Serve the official spacedesk protocol instead (for the real apps)
--no-input off Disable remote input
--no-discovery / --discovery-port on / 28253 UDP discovery
--name hostname Advertised name
-v off Verbose logging

Modes

Mode What it does When to use
mirror Streams the existing primary display Simplest; always works
virtual Attaches a real virtual monitor via evdi (falls back to mirror) You want a separate extra screen
x11 Like mirror but resolves geometry explicitly from X11 Fine-grained control
xvfb Spawns a headless Xvfb screen and streams that Servers, CI, testing
headless No display setup at all Used with --backend lavfi/v4l2

Backends

Backend Source
x11 X11 / XWayland screen grab
pipewire Wayland screen cast via xdg-desktop-portal
v4l2 A capture device (HDMI grabber, webcam)
file Loop an image/video (kiosk signage)
lavfi Synthetic test pattern (testsrc2)

Connecting other clients

# any browser
xdg-open http://<host-ip>:28252/

# VLC / mpv / ffplay / most MJPEG-aware apps
vlc              http://<host-ip>:28252/stream.mjpg
ffplay -f mjpeg  http://<host-ip>:28252/stream.mjpg
mpv              http://<host-ip>:28252/stream.mjpg

Extra monitors on Linux (evdi)

--mode virtual looks for the evdi kernel module, the same mechanism DisplayLink uses to create virtual displays:

sudo apt install evdi-dkms        # Ubuntu/Debian
sudo modprobe evdi
spacedesk-linux serve --mode virtual

Without evdi, --mode mirror still gives you the whole desktop on the client — it just duplicates your primary screen instead of adding a new one.

Wayland notes

Under a Wayland compositor, X11 grab only sees XWayland windows. For the whole desktop use the portal screencast backend:

spacedesk-linux serve --backend pipewire

Remote input

uinput is the preferred backend and works on both X11 and Wayland:

sudo usermod -aG input "$USER"   # then log out/in

Enable the viewer's remote input toggle and the client's mouse/keyboard/touch drive the host. If no backend is available the server logs a warning and stays read-only — video never breaks.

Running as a service

# per-user (recommended: inherits your session's DISPLAY/WAYLAND_DISPLAY)
systemctl --user daemon-reload
systemctl --user enable --now spacedesk-linux

# system-wide (edit DISPLAY= in the unit for your session)
sudo systemctl enable --now spacedesk-linux

Security

  • The server is unauthenticated by default. Use --token <secret> and open http://host:28252/?t=<secret> to require it, and/or restrict with a firewall.
  • Streams are plaintext HTTP/WebSocket. For untrusted networks, tunnel it (e.g. WireGuard, SSH port-forward, or a TLS reverse proxy). Native TLS is on the roadmap.
  • Remote input injects real events into your desktop — only enable it on trusted networks.

Firewall ports

sudo ufw allow 28252/tcp     # viewer / MJPEG / WebSocket
sudo ufw allow 28253/udp     # discovery

Comparison with spacedesk (Windows)

spacedesk (Windows) spacedesk-linux
Virtual monitor IddCx kernel driver evdi (or mirror/Xvfb)
Clients official Android/iOS/Windows/HTML5 apps works with the official apps (--compat) and any browser
Protocol compat — ✅ official spacedesk protocol (reconstructed)
Video codec JPEG + H.264 JPEG (H.264 planned)
Audio virtual audio device ✗ (planned)
Camera passthrough virtual camera driver ✗ (planned)
USB cable mode AOAP driver ✗ (LAN only)
Dependencies proprietary driver Python stdlib + ffmpeg

Limitations & roadmap

  • Mirror + Xvfb + discovery + WebSocket/MJPEG + input
  • Official spacedesk protocol compatibility (serve --compat)
  • H.264 / fragment-MP4 or WebRTC transport (lower bandwidth)
  • TLS (self-signed cert generation, like spacedesk's .pfx)
  • Dirty-region encoding (send only changed tiles)
  • Multi-monitor selection & per-client virtual monitors via evdi
  • Audio streaming (PulseAudio/PipeWire)
  • Native phone apps (the browser viewer already works on Android/iOS)

Development

python3 tests/run_tests.py          # zero-dependency test runner
pip install -e '.[dev]' && pytest   # or use pytest if you have it

Layout:

src/spacedesk_linux/
  cli.py              command line entry point
  server.py           asyncio HTTP/WebSocket/MJPEG server + FrameHub
  compat.py           official spacedesk-protocol server (WebSocket + raw TCP)
  protocol.py         spacedesk wire protocol (packets, headers, enums)
  capture.py          ffmpeg / PipeWire capture backends (JPEG carving)
  websocket.py        dependency-free RFC 6455 server
  discovery.py        UDP LAN discovery
  input_inject.py     uinput / xdotool / ydotool input backends
  virtual_display.py  evdi / Xvfb / xrandr display handling
  platform_detect.py  environment probing
  web/                bundled browser viewer
tests/                unit tests + run_tests.py
packaging/            systemd units, .deb builder, AppImage builder
scripts/              install / uninstall
docs/                 protocol + reverse-engineering notes

License

MIT. See LICENSE. "spacedesk" is a trademark of its owner and is used here only descriptively; this project is independent and unaffiliated.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages