askrobots / network-computer
Public
Your phone is the terminal. Stream a Linux/Mac desktop to an iPhone over WebRTC through NAT, with audio and input. Open source, single binaries.
Dan Quellhorst
Firefox policy: no WebRTC mDNS (a page using WebRTC made Firefox listen on UDP 5353)
a1d92f3
1 month, 3 weeks ago
History
nc-display · 1.8 KB · 33 lines
| 1 | #!/bin/sh |
| 2 | # Resize the headless X screen and set the desktop's UI scale. |
| 3 | # nc-display <width> <height> [scale] e.g. nc-display 1920 1080 1.25 |
| 4 | # nc-host runs this when a client asks for a screen size; safe to run by hand. |
| 5 | set -e |
| 6 | W=${1:?usage: nc-display <width> <height> [scale]}; H=${2:?usage: nc-display <width> <height> [scale]}; S=${3:-1} |
| 7 | export DISPLAY=:0 |
| 8 | |
| 9 | OUT=$(xrandr -q | awk '$2=="connected"{print $1; exit}') |
| 10 | [ -n "$OUT" ] || { echo "nc-display: no connected output on $DISPLAY"; exit 1; } |
| 11 | MODE="${W}x${H}" |
| 12 | if ! xrandr -q | awk '{print $1}' | grep -qx "$MODE"; then |
| 13 | # the screen lacks this size: add a mode with standard (reduced-blanking) timings |
| 14 | ML=$(cvt -r "$W" "$H" 60 2>/dev/null | sed -n 's/^Modeline "[^"]*" *//p') |
| 15 | [ -n "$ML" ] || ML=$(cvt "$W" "$H" 60 | sed -n 's/^Modeline "[^"]*" *//p') |
| 16 | xrandr --newmode "$MODE" $ML 2>/dev/null || true |
| 17 | xrandr --addmode "$OUT" "$MODE" |
| 18 | fi |
| 19 | xrandr --output "$OUT" --mode "$MODE" |
| 20 | |
| 21 | # UI scale, applied live through the desktop session's own settings daemon |
| 22 | . /etc/nc/env 2>/dev/null || true |
| 23 | U=${NC_DESK_USER:-user} |
| 24 | PID=$(pgrep -u "$U" -x xfce4-session | head -1 || true) |
| 25 | [ -n "$PID" ] || { echo "screen $MODE on $OUT; no desktop session for $U, scale not applied"; exit 0; } |
| 26 | BUS=$(tr '\0' '\n' < "/proc/$PID/environ" | sed -n 's/^DBUS_SESSION_BUS_ADDRESS=//p') |
| 27 | # whole-number scales use GTK window scaling; the remainder scales fonts (dpi) |
| 28 | WSF=$(awk -v s="$S" 'BEGIN{print (s>=2) ? int(s) : 1}') |
| 29 | DPI=$(awk -v s="$S" -v w="$WSF" 'BEGIN{printf "%d", 96*s/w + 0.5}') |
| 30 | q() { runuser -u "$U" -- env DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS="$BUS" xfconf-query -c xsettings "$@"; } |
| 31 | q -n -p /Gdk/WindowScalingFactor -t int -s "$WSF" |
| 32 | q -n -p /Xft/DPI -t int -s "$DPI" |
| 33 | echo "screen $MODE on $OUT, scale $S (window scaling ${WSF}x, ${DPI} dpi)" |