Files
mediadeck/README-EN.md
T
Denis 851b7681ff Add held mouse buttons (Left click / Right click toggles) to the Touchpad tab
Two toggle buttons in the free corners of the D-pad press and hold the PC's
left or right mouse button until tapped again, for drag and drop, text
selection and window moves, with the touchpad moving the pointer in between.

- New input action "button" ({button, pressed}); the state carries
  input.buttons. VirtualInput remembers which connection pressed each button.
- A click on a held button is ignored so a touchpad tap does not drop the
  drag; the other button stays usable. Repeating a state is a no-op.
- A held button is always released: when its client disconnects (only its own
  buttons), when the server stops, and in the client when the tab is left or
  the page is hidden.
- Incoming states are set aside for 500 ms after a local tap, so a state
  already in flight cannot undo the toggle for a moment.
- D-pad rows are equal-sized (minmax(0, 1fr)) so the corner buttons do not
  stretch the top row.

tests/test_input.py covers the device logic and the full server (disconnect,
several clients); tests/test_ui_mouse_hold.py drives a real Chromium. Also
checked through the real uinput device with its pointer grabbed exclusively.
README (fr/en) and CLAUDE.md are updated.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-31 09:02:19 +01:00

24 KiB

MediaDeck

Web remote for a Linux media PC, designed for an Android tablet sitting next to it. The PC runs a small Python bridge; the tablet only needs a browser.

Version française : README.md

Features

Tab Content PC side
Playing Cover art (or, failing that, an image of the file played), title (or file name), progress, play/pause, next/previous, shuffle, repeat, player volume, player selection MPRIS (session D-Bus): Elisa, VLC, mpv, Firefox, Chromium, Spotify, Kodi…
Volume bar under the player: master volume, mute; the active output's button opens a window with the output selection (HDMI, Bluetooth…) and per-output volume; the bar is always visible pactl (PipeWire or PulseAudio)
Media Sound, image and video files from the PC's folders, as icons or thumbnails, with search and sorting (name, date, size); a tap opens the file on the PC with the player chosen for its type gio; folders and players: see "Media"
Touchpad Touchpad (click, right click, 2-finger scroll), D-pad with two held "Left click" / "Right click" toggle buttons (drag and drop, text selection), Esc, Space, F, F11…, text entry with the tablet's keyboard /dev/uinput: works on X11 and Wayland
Launchers Configurable buttons: websites and installed applications (/admin page) browser, gio launch
System Lock, sleep, restart, shut down (1 s long press): sensitive operations, kept apart from launchers logind, org.freedesktop.ScreenSaver

State is pushed in real time over WebSocket (PropertiesChanged, Seeked, pactl subscribe); the playback position is interpolated on the tablet.

Architecture

Tablet (fullscreen browser)
        │  HTTP + WebSocket, access token
        ▼
mediadeck (aiohttp, systemd --user service)
   ├─ mpris.py   → org.mpris.MediaPlayer2.*          (session bus)
   ├─ audio.py   → pactl list/set-sink-*, subscribe
   ├─ input.py   → python-evdev / uinput             (virtual keyboard + pointer)
   ├─ keymap.py / text.py → text entry following the PC's real keyboard layout (libxkbcommon)
   ├─ media.py   → Media tab: allowed folders, safe browsing, /api/media API
   └─ system.py  → org.freedesktop.login1, ScreenSaver, launchers (SQLite database, /admin page)

KDE Connect is not required; it can stay installed for its other features.

Installation (Debian / LMDE)

make deps             # system packages (sudo): venv, gcc, pactl, qrencode, ffmpeg
make install          # .venv + Python dependencies
make config           # ~/.config/mediadeck/config.toml (mode 600) with a random token
                      # PC with a VPN: set `advertise_host` HERE, before `make cert` (see below)
make cert             # secure access (HTTPS): local CA + certificate, enabled in config.toml
make http-on          # optional: also keep an unencrypted HTTP access (port 8766)
make uinput           # "uaccess" udev rule for /dev/uinput (sudo)
make service-install  # systemd user service, started with the graphical session
make url              # URL(s) + QR code(s) to scan with the tablet
make qr               # or a PC browser page with the QR codes shown large

Run every make command from the project folder (the one containing the Makefile), not from ~/.config/mediadeck. make cert and make http-on come after make config (they edit config.toml) and before make service-install, so the service starts in the right mode; if run later, restart the service (systemctl --user restart mediadeck).

  • Secure access (HTTPS), recommended: encrypted traffic, Wake Lock and app installation. The CA must be installed on the tablet once (see "Local HTTPS").

  • Text entry ("Keyboard" button), optional and off by default: set text_input = true under [features] in config.toml to enable it (see "Text entry"). Without it the button stays greyed out.

  • Unsecured access (HTTP): nothing to install, but the token travels in clear on the local network. Without make cert it is the only mode; with make cert then make http-on, both coexist (see "Choosing: secure or unsecured").

  • If the ufw firewall is active: make firewall (add HTTP_PORT=8766 if plain HTTP is enabled).

  • PC with a VPN (WireGuard, Proton VPN…): set advertise_host. make url, make qr and make cert work out the PC's address from the default route; with an active VPN that route goes through the tunnel (wg0, tun0, proton0…; for example 10.2.0.2), so the advertised address cannot be reached by the tablet. The HTTPS certificate would also be issued for that wrong address. These three commands print a warning (with candidate addresses) when the detected address belongs to a virtual interface (tunnel, Docker bridge). Before make cert, put the PC's address on the local network, outside any tunnel, in ~/.config/mediadeck/config.toml:

    [server]
    advertise_host = "192.168.1.104"
    

    To find it: ip -4 -br addr and take the address of the physical interface (enp…, eno…, wlp…), not a tunnel's or a Docker bridge's. If make cert was already run with a wrong address, fix it and rerun make cert: the CA stays the same, nothing to redo on the tablet. If the tablet still cannot reach the PC, allow local network connections in the PC's VPN application.

On the tablet: scan the QR code, then browser menu → "Add to Home screen". The token is stored, then removed from the address bar.

The service must run inside the graphical session: it needs the user's session D-Bus and audio server.

Configuration

~/.config/mediadeck/config.toml (see config.example.toml):

[server]
host = "0.0.0.0"
port = 8765
token = "…"            # make token to regenerate it
advertise_host = "192.168.1.104"   # address of the QR code and certificate (auto-detected otherwise); set it if the PC has a VPN
tls_cert = "~/.config/mediadeck/tls/server.pem"       # written by `make cert` (HTTPS)
tls_key = "~/.config/mediadeck/tls/server.key"
tls_ca = "~/.config/mediadeck/tls/mediadeck-ca.crt"   # served on /ca.crt for the tablet
http_port = 8766       # optional: plain HTTP port next to HTTPS (0 or absent = disabled)

[audio]
max_volume = 1.0       # cap applied to the tablet

[features]
input = true
power = true
text_input = false       # virtual keyboard: read "Text entry" before enabling

[admin]
enabled = true                 # /admin page and launcher API
allow_custom_command = false   # true: allow raw commands from /admin

[media]
roots = ["~/Music", "~/Videos", "~/Pictures"]   # absent: the user's Music/Videos/Pictures folders; []: tab disabled

# Imported once into the database at first start, then managed on /admin
[[launchers]]
id = "youtube"
label = "YouTube TV"
icon = "tv"            # app, tv, film, globe, music, screen-off, speaker, lock, window
command = ["chromium", "--start-fullscreen", "https://www.youtube.com/tv"]

Launcher commands are argv lists and are never passed to a shell.

Launchers

The buttons of the Launchers tab are stored in a SQLite database (~/.local/share/mediadeck/launchers.db, mode 600). The tab's Manage button opens the /admin page: add, edit, delete and reorder launchers. Changes show up on the tablet immediately.

Type Definition What the client can write
Website http(s) URL, browser (Chromium, Chrome, Brave, Firefox), fullscreen a URL
Installed application picked from the list of .desktop files, started with gio launch nothing (pick from a list)
Command raw argument list anything: disabled by default
  • Security: the API requires the token in the Authorization: Bearer header (never in the URL). A command runs with your rights: unless allow_custom_command = true is set in the [admin] section of config.toml, creating or changing a command is refused (403). An existing command can still be renamed.
  • Migration: at first start, the [[launchers]] of config.toml are imported once (command type). They are ignored afterwards and can be removed from the file. To import them again, delete the database.
  • enabled = false turns off the page and the API; existing launchers keep working.
  • There is no automatic fullscreen with Firefox, whose kiosk mode ignores F11.
  • gio (package libglib2.0-bin, installed by make deps) starts installed applications.

Media

The Media tab (shown as soon as at least one folder is configured) lists sound, image and video files as icons: subfolders, breadcrumb, back button, All / Sounds / Images / Videos filter, search. Tapping a file opens it on the PC; the tablet stays a remote control. A long press (or a right click) offers the other players of the type when there are several.

  • Folders: [media] roots in config.toml (absolute paths or ~/…). Without this key, the user's Music, Videos and Pictures folders are used (read from ~/.config/user-dirs.dirs, never the whole home folder). roots = [] disables the tab. A single folder is opened directly; several appear as a first level.

  • One or several players per type (Sound, Image, Video): the file path is added as the last argument. They are set on the /admin page, "Media file players" section, with the same rules as launchers. Each player has a name; the first one in the list opens by default (a tap), the others are reached with a long press on the file. The ↑ ↓ buttons change the order, hence the default player; at most 8 players per type, and a type always keeps at least one:

    Player Command run What the client can write
    System default application (initial setting) gio open <file> nothing
    Installed application gio launch <app>.desktop <file> nothing (picked from a list)
    Command (e.g. mpv --fs) mpv --fs <file> anything: needs allow_custom_command = true
  • Security: the client never sends an absolute path, only a root folder and a relative path. The server refuses .., absolute paths and hidden entries (.x). Symbolic links are followed wherever they point: a folder kept on another disk is simply linked from the configured folder (ln -s /disk/Films ~/Videos/Films). Your own links therefore decide what can be seen from the tablet; [media] follow_symlinks = false only follows links whose target stays inside the configured folder. Only known media extensions are listed and opened (never a script, even renamed .mp3 or linked to a .sh). GET /api/media requires the token in the Authorization header; thumbnails (/thumb) have it in the URL, like /art, because an image tag sends no header. ffmpeg runs with no standard input, limited to local files, with a timeout and at most three processes; an image is read by the image decoder only (a playlist disguised as .jpg yields nothing). A folder shows at most 1000 entries. The token gives access to the names of the files in these folders: only configure what may be seen from the tablet.

  • Search: the "Search…" field looks in file and folder names (ignoring accents and case, every word must appear) in the folder shown and its subfolders, or in all folders from the first level. Results show their folder; a tap opens the file or folder. At most 300 results and 4 seconds; links are followed, without scanning a folder twice (no loops).

  • Thumbnails: images (jpg, png, gif, webp, bmp, tiff; not HEIC or AVIF), videos (a frame of the film, or a poster in the folder) and sounds (embedded cover or a picture in the folder) are shown as thumbnails, made by ffmpeg (apt install ffmpeg, installed by make deps) and kept in ~/.cache/mediadeck/thumbs (3000 files at most). They are only made for the tiles on screen; a video on a network drive may take a few seconds the first time. Without ffmpeg, or when there is no picture to show (a sound without a cover), the icon stays. [media] thumbnails = false turns them off.

  • Sorting: a selector next to the filters orders files by name (natural order, the default), by date (newest first) or by size (largest first); folders always stay first. The choice is remembered on the tablet.

  • Title and image in the Playing tab: when a player plays a file from a configured folder, the tab shows its title (the file name if the player gives none) and an image: the player's own, else an image from the folder (<name>.jpg, <name>-poster.jpg, poster.jpg, cover.jpg, folder.jpg…), else the cover embedded in a sound file or a frame taken from the video. Without an MPRIS player (image viewer, silent player), the tab shows the last file opened from the Media tab, with its title and image.

Held mouse buttons (drag and drop)

In the Touchpad tab, the two free corners of the D-pad hold Left click and Right click: one tap presses the PC's mouse button, a second tap releases it (the button turns orange while it is down). In between, the touchpad moves the pointer: that is a drag and drop, a text selection or a window move. The two buttons are independent.

  • While held, tapping the touchpad for the same button is ignored (it does not drop the drag); the other button stays usable (right click while the left one is held).
  • Release is guaranteed: a held button is released when you leave the Touchpad tab, when the page is hidden (screen off, another app) and by the server when the client's connection drops or the service stops. A button can never stay stuck on the PC.
  • Several tablets see the same state; one tablet disconnecting only releases its own buttons.

Text entry

The Keyboard button of the Touchpad tab opens an entry window. You type with the tablet's own keyboard (accents, correction, voice dictation), then Send or Send ↵ types the text into the PC's active window. Tab, Backspace and Enter sit next to the field. The window is not modal: the touchpad stays usable (click into a field on the PC, then type). Hide text shows dots, for a password.

Each character is translated into key presses following the PC keyboard's real layout (AZERTY, QWERTY…), read from KDE's configuration (~/.config/kxkbrc, otherwise setxkbmap -query, the active layout coming from D-Bus), using libxkbcommon. Shift, AltGr and dead keys (ê, ñ…) are handled; keys go through uinput like a real keyboard's. The clipboard is not used: nothing stays in Klipper's history, passwords included.

  • Off by default: set [features] text_input = true to enable it. It is a full keyboard: with the token, someone can open a terminal (Super key) and type commands. Enable it only if that is acceptable. After editing config.toml, restart the service (systemctl --user restart mediadeck).
  • "Keyboard" button greyed out? Tapping it shows the reason (it is also in the service log, line text entry unavailable: …, via journalctl --user -u mediadeck). On a fresh install it is almost always disabled in config (features.text_input): add text_input = true under [features]. Other reasons: cannot open /dev/uinput (run make uinput, then log out and back in to the graphical session); libxkbcommon not found (apt install libxkbcommon0 xkb-data); python3-evdev not installed (make install).
  • 500 characters per send (WebSocket message size limit).
  • A character missing from the layout (→, emoji…) is skipped, the rest is typed and an error reports it. Typographic apostrophes, quotes, "…" and dashes are replaced by their ASCII equivalent.
  • The PC's Caps Lock state is not detected: if it is on, capitals are inverted.
  • Accented letters made with dead keys rely on the application's compose handling (checked with an xkb simulation, not in every application). An input method running on the PC (fcitx, ibus) may change the result.
  • Needs libxkbcommon and the xkb data (packages libxkbcommon0 and xkb-data, installed by make deps).

QR codes page

make qr opens a page in the PC browser that shows, large, the codes to scan with the tablet: secure access (HTTPS), unsecured access (HTTP, if http_port is enabled) and the CA certificate to install. Only the codes relevant to the current configuration are shown. The language follows LANG.

The codes contain the token, so the page is never served by the server (any client on the network could read it). It is written with mode 600 to $XDG_RUNTIME_DIR/mediadeck/access.html (cleared at logout) and opened as file://. It relies on qrencode (installed by make deps) and needs no script or external resource.

Local HTTPS

Some mobile browsers require HTTPS, and so do the Wake Lock API and a proper PWA install. MediaDeck creates its own local certificate authority (CA) with openssl:

make cert                              # CA + server certificate, enables HTTPS in config.toml
systemctl --user restart mediadeck     # or rerun `make dev`

On the tablet, once:

  1. Open https://<ip>:8765/ca.crt (address and QR code printed by make cert) and accept the certificate warning: the file mediadeck-ca.crt is downloaded.
  2. Settings → Security → Encryption & credentials → Install a certificate → CA certificate, then pick that file (the exact path depends on the Android version).
  3. Rescan the QR code from make url: the address now starts with https://, so the token remembered for the old http:// address is no longer used.

Notes:

  • The port now speaks HTTPS only: a plain http:// request to it fails. To keep plain HTTP as well, see "Choosing: secure or unsecured" below.
  • The CA can only sign private addresses (10/8, 172.16/12, 192.168/16, 127/8) and the names localhost, *.local, *.lan and the machine's own name (nameConstraints). Its key ca.key stays on the PC (mode 600): never copy it.
  • The certificate is only valid for the advertised address (advertise_host, the one in the QR code), the machine name (<name>, <name>.local) and localhost. A PC connected by both cable and Wi-Fi has two addresses: use the one in the QR code; the other shows "Your connection is not private" even with the CA installed.
  • The server certificate is valid for 825 days. make cert reissues it without changing the CA, so nothing needs redoing on the tablet. If the PC's address changes, fix advertise_host and rerun make cert.
  • Tablet browser: use a standalone Chromium browser (Chrome, Brave, Vivaldi, Vanadium…), which trusts user-installed CAs. Browsers built on the system WebView (DuckDuckGo…) may ignore them, and Firefox for Android needs a hidden setting: not verified for this project. Only installing the CA is system-wide; /ca.crt can be downloaded from any browser.
  • To start over (new CA, to be reinstalled on the tablet): delete ~/.config/mediadeck/tls/ and the three tls_* lines from config.toml, then run make cert.

Choosing: secure or unsecured

Two ways in, chosen by the tablet, which can coexist:

Mode Address Good for Limits
Unsecured (HTTP) http://<ip>:<port> nothing to install; works with every browser traffic and token in clear text on the LAN; no Wake Lock or PWA
Secure (HTTPS) https://<ip>:<port> encrypted traffic, Wake Lock, PWA the CA must be installed on the tablet (see above)
Configuration ([server]) Result
no tls_* and no http_port plain HTTP only, on port (default)
tls_* (make cert) HTTPS only, on port
tls_* + http_port = 8766 HTTPS on port and plain HTTP on http_port

To offer both: make cert, then make http-on (writes http_port = 8766; make http-on HTTP_PORT=9000 for another port), open that port if needed (make firewall HTTP_PORT=8766), then restart the service (systemctl --user restart mediadeck, or rerun make run). make url then prints two addresses and two QR codes, one "Secure", one "Unsecured". Each address is a distinct origin: the token is remembered separately for each, and a PWA can only be installed from the HTTPS one.

To remove plain HTTP: make http-off (HTTPS only). To go back to plain HTTP only, also remove the three tls_* lines from config.toml (the certificates stay in ~/.config/mediadeck/tls/). /ca.crt is served on both ports, so the CA can be fetched from the HTTP port without a certificate warning.

Make targets

Target Purpose
make run / make dev run in the foreground (normal / verbose)
make check validate the configuration
make token regenerate the token (tablets must rescan)
make qr open a page in the PC browser showing the QR codes to scan (HTTPS, HTTP, CA)
make cert create the local CA and HTTPS certificate, enable HTTPS
make http-on / make http-off add / remove the unsecured plain HTTP port next to HTTPS
make status / make logs service status and journal
make firewall open the port to private networks with ufw (HTTP_PORT=8766 for the plain HTTP port)
make lint / make test pyright / unit tests
make test-ui UI in Chromium (layout, Media tab, launchers, /admin); skipped without chromium; also part of make test
make test-integration full scenario (server, private D-Bus bus, fake player, fake gio and pactl); also part of make test
make service-uninstall, make uinput-remove, make distclean uninstall

Security

  • /api/media (file listing) requires the token in a header; opening a file goes through the WebSocket, with a root folder and a relative path validated on the server (see "Media").
  • /ws and /art require the token (constant-time comparison); only the HTML page is public.
  • The config file is rejected if it is readable by group or others.
  • /art only serves the file:// cover of the requested player, and only images under 10 MB.
  • The launcher API /api/* requires the token in the Authorization header (no CSRF possible from another site); raw commands are refused there unless allow_custom_command = true is set in the config file.
  • WebSocket messages are capped at 4 KB; mouse moves and scrolls are bounded.
  • uinput access is granted through a logind ACL (uaccess) to the active session user, not through the input group, which would allow reading every keyboard.
  • Without make cert, or on the http_port port, traffic is plain HTTP (token included) and meant for a trusted LAN only. With HTTPS it is encrypted, but the port must still not be exposed outside the LAN: for remote access, go through WireGuard. http_port is disabled by default.

Known limitations

  • Old interface after an update: if the tablet still shows the old version (missing tabs…), refresh the page once (browser menu → Refresh). Opening the same link or the home-screen shortcut reuses the cached page; refreshing replaces it, and the interface files are then versioned (/static/<version>/…), so they can no longer go stale. Also remember to restart the server after an update: the running Python code is not reloaded.

  • Screen always on: the Wake Lock API requires HTTPS (see "Local HTTPS"). Over HTTP, adjust the tablet's sleep setting or use a kiosk browser (Fully Kiosk Browser…).

  • VPN on the tablet: an active VPN on the client device cuts off the local network, and the page times out ("site can't be reached, took too long to respond"). Allow LAN connections in the VPN app (Proton VPN: Settings → Connection → Advanced settings → LAN connections), turn off Android's lockdown / kill switch, or disconnect the VPN.

  • Text entry: see its section; off by default, and limited to the characters the PC keyboard layout can produce.

  • Lock / power: depend on polkit rules. An active local session is allowed by default on Debian.

  • Some players (browsers especially) expose no volume, shuffle or repeat: the matching controls are then hidden.

License

MIT