Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
111.4k stars 10.67k forks source link

VNC server #3473

Open luke-jr opened 2 years ago

luke-jr commented 2 years ago

It would be nice if scrcpy could provide a VNC server so things like vncdotool could be used with it

luke-jr commented 1 year ago

Workaround for now (not ideal: if you move the mouse during a vncdotool, the clicks go the wrong place):

#!/bin/bash
set -m  # enable job control
set -x

orig_display="$DISPLAY"
my_display=:99

scrcpy_pid=

cleanup() {
    local pids=$(jobs -pr | tr '\n' ' ')
    [ -n "$pids" ] || return
    if [[ "$pids" =~ (^|\ )$scrcpy_pid($|\ ) ]]; then
        kill $scrcpy_pid
        wait $scrcpy_pid
    fi
    kill $pids
    wait
}

trap cleanup EXIT
trap 'exit 1' SIGINT SIGTERM

Xvfb -screen 0 1920x1080x24 "$my_display" &
export DISPLAY="$my_display"

scrcpy "$@" &
scrcpy_pid="$!"

wid=$("$HOME/bin/get-x11-winid-by-name" 'Pixel XL' 10)
[ -n "$wid" ] || exit

sleep 1  # give scrcpy more time to initialise

# for xdotool
cmd=(
    x11vnc
    -id "$wid"
    -rfbport 5999 -rfbportv6 5999 -localhost -rfbauth "$HOME/.vnc/passwd"
    -shared -forever
    -nocursor
    -scale 1440x2560
)
"${cmd[@]}" &

# for actual user
cmd=(
    x11vnc
    -id "$wid"
    -rfbport 5998 -rfbportv6 5998 -localhost -rfbauth "$HOME/.vnc/passwd"
    -shared -forever
)
"${cmd[@]}" &

{
    export DISPLAY="$orig_display"
    krdc --qwindowgeometry 570x1015 vnc://localhost:98 &
}

jobs
wait -nf  # for any child to exit