#!/bin/bash # On the Brain: show an app that runs on the PC (its window, live; the app is not restarted). # pcapp claude | pcapp chatgpt # Closing the viewer gives the window back to the PC. app=${1:-claude} if pgrep -u "$(id -u)" -f "xtightvncviewer .*localhost:6" >/dev/null; then if [ "$(cat /tmp/lex01-pcapp-$(id -u) 2>/dev/null)" = "$app" ]; then xrestore tightvnc >/dev/null; exit 0 # already showing it: just bring it to the front fi pkill -u "$(id -u)" -f "xtightvncviewer .*localhost:6" # showing the other app: switch sleep 3 fi echo "$app" > /tmp/lex01-pcapp-$(id -u) echo "$app" > /tmp/lex01-request ok= for i in $(seq 30); do # wait until the PC serves the window sleep 1 if exec 3<>/dev/tcp/127.0.0.1/5906 2>/dev/null && read -r -t 3 -n 3 banner <&3 && [ "$banner" = RFB ]; then exec 3>&-; ok=1; break fi exec 3>&- 2>/dev/null done [ -n "$ok" ] || { xmessage -center "$app: the PC did not answer (is pc-vnc/start.sh running, is the app open on the PC?)"; exit 1; } xtightvncviewer -geometry +66+0 -encodings "tight copyrect hextile" -compresslevel 6 -quality 5 localhost:6 # give the window back, unless another pcapp has taken over meanwhile [ "$(cat /tmp/lex01-pcapp-$(id -u) 2>/dev/null)" = "$app" ] && echo share-stop > /tmp/lex01-request