Created
October 17, 2023 19:53
-
-
Save T-X/67ded984a168923da0a3f156783e6ae7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)" | |
echo "hmd_on(): Setting $MONITOR to non-desktop 0" >&2 | |
xrandr --output "$MONITOR" --prop --set non-desktop 0 | |
echo "hmd_on(): Setting $MONITOR to right-of eDP-1-1" >&2 | |
xrandr --output "$MONITOR" --mode 4320x2160 --right-of eDP-1-1 | |
echo "hmd_on(): $MONITOR finished" >&2 | |
} | |
hmd_off() { | |
echo "hmd_off(): Setting $MONITOR off" >&2 | |
xrandr --output "$MONITOR" --off | |
echo "hmd_off(): Setting $MONITOR to non-desktop 1" >&2 | |
xrandr --output "$MONITOR" --prop --set non-desktop 1 | |
echo "hmd_off(): Calling monado-cli probe for $MONITOR for shutdown" >&2 | |
monado-cli probe > /dev/null | |
echo "hmd_off(): $MONITOR finished" >&2 | |
} | |
get_hmd_monitor() { | |
echo "DP-0" | |
# 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)" | |
echo "hmd_toggle(): status of $MONITOR: $status" >&2 | |
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