#!/bin/bash

set -eu
set -o pipefail

# Don't recall why I stopped using this, but it wasn't in the Mint/Ubuntu/Debian repos.
# which_vnc=TurboVNC

# This is fast, but it tends to distort some (EG chrome/chromium?) menus, and even some windows.
# Also, the latest versions don't do vncserver in a familiar way - that'll require some study later.
# Also, the older (Debian? current, Jan 2021) versions do not run Qt apps.
# which_vnc=TigerVNC

# A little slow, but works well.
which_vnc=TightVNC

# I added the -localhost yes based on https://unix.stackexchange.com/questions/398905/vnc-server-only-listening-for-connections-from-localhost
case "$which_vnc" in
    TurboVNC)
        extra_opts=""
        vncserver=/opt/TurboVNC/bin/vncserver
        ;;
    TigerVNC)
        # extra_opts="-SecurityTypes=VeNCrypt,TLSVnc -shared=1 -localhost yes"
        extra_opts="-localhost yes"
        vncserver=vncserver
        ;;
    TightVNC)
        extra_opts="-localhost yes"
        vncserver=vncserver
        ;;
    *)
        echo "$0: internal error: \$which_vnc has a strange value: $which_vnc" 1>&2
        exit 1
        ;;
esac

# Dimensions from xwininfo on zareason-strata7440 at my place.
# dimensions=1920x1055

# Dimensions from old xwininfo+new guesswork on dstromberg-precision-3530 at GG's.
# dimensions=1920x990
dimensions=1916x890

# shellcheck disable=SC2086
$vncserver -geometry "$dimensions" $extra_opts