#!/bin/bash
#
# raspi-disp-switcher for trixie
# yagi@yagiful 2023/11/23, 2024/05/21, 2025/11/27
#

shopt -s nocasematch

usage(){
    cat <<EOF

Usage: ${0##*/} [-h] x11/labwc

       Switch display server to X11 or labwc on Raspberry Pi.
       The command requires sudo privileges.

EOF
}

while getopts h opt; do
    case "${opt}" in
	h)
	    usage
	    exit
	    ;;
    esac
done
shift  $(($OPTIND - 1))

if [ $# -lt 1 ]; then
    usage
    exit
fi

sw="$1"; shift

#

case "$sw" in
    x|x11)
	sudo raspi-config nonint do_wayland "W1"
	;;
    l|labwc)
	sudo raspi-config nonint do_wayland "W2"
	;;
    *)
	echo "Error: Invalid arguments"
	usage
	exit 1
	;;
esac

sudo systemctl restart lightdm
