Skip to content

Instantly share code, notes, and snippets.

@T-X
Created October 17, 2023 19:21
Show Gist options
  • Save T-X/e4e6ac15f78a74e3d4d139b922bb5351 to your computer and use it in GitHub Desktop.
Save T-X/e4e6ac15f78a74e3d4d139b922bb5351 to your computer and use it in GitHub Desktop.
#!/bin/sh
hmd_on() {
expect <<EOF
spawn monado-cli probe
expect "Sleep until the HMD display is powered up"
sleep 2
exit
EOF
MONITOR="$(get_hmd_monitor)"
xrandr --output "$MONITOR" --prop --set non-desktop 0
xrandr --output "$MONITOR" --mode 4320x2160 --right-of eDP-1-1
}
hmd_off() {
xrandr --output "$MONITOR" --off
xrandr --output "$MONITOR" --prop --set non-desktop 1
monado-cli probe > /dev/null
}
get_hmd_monitor() {
xrandr | grep -B1 4320x2160 | grep DisplayPort | cut -f1 -d' '
}
get_hmd_status() {
local status="$(xrandr | grep "$MONITOR")"
[ -n "$MONITOR" ] && [ -n "$status" ] && {
case "$status" in
*disconnected*)
echo "disconnected" && return 0
;;
*connected*)
echo "connected" && return 0
;;
*)
;;
esac
}
echo "unknown"
return 1
}
hmd_toggle() {
local status="$(get_hmd_status)"
case "$status" in
connected)
hmd_off
;;
disconnected)
hmd_on
;;
*)
;;
esac
}
MONITOR="$(get_hmd_monitor)"
case "$1" in
"on")
hmd_on
;;
"off")
hmd_off
;;
"toggle"|"")
if [ -z "$MONITOR" ]; then
hmd_on
else
hmd_toggle
fi
;;
*)
echo "unknown command"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment