Files
ubuntu-kernel-fenix/archives/filesystem/special/Edge1/usr/local/bin/hdmi-toggle
Nick Xie 1098a5a2c0 Edge1: renaming Edge to Edge1
Signed-off-by: Nick Xie <nick@khadas.com>
2022-09-29 10:58:01 +08:00

54 lines
1023 B
Bash
Executable File

#!/usr/bin/env bash
USER="$(who | grep :0\) | cut -f 1 -d ' ')"
export XAUTHORITY=/home/$USER/.Xauthority
export DISPLAY=:0
if [ -z "$USER" ]; then
if dpkg -l | grep lightdm > /dev/null; then
systemctl restart lightdm
fi
exit 0
fi
########### Settings ###########
# Use 'xrandr' to find these
DP="DP-1"
VGA="VGA-1"
HDMI="HDMI-1"
INTERNAL_DISPLAY="LVDS-1"
# Check /sys/class/drm for the exact location
DP_STATUS="$(cat /sys/class/drm/card0-DP-1/status)"
VGA_STATUS="$(cat /sys/class/drm/card0-VGA-1/status)"
HDMI_STATUS="$(cat /sys/class/drm/card0-HDMI-A-1/status)"
# Do no change!
EXTERNAL_DISPLAY=""
# Check to see if the external display is connected
if [ "${DP_STATUS}" = connected ]; then
xrandr
xrandr --output $DP --auto
else
xrandr --output $DP --off
fi
if [ "${VGA_STATUS}" = connected ]; then
xrandr
xrandr --output $VGA --auto
else
xrandr --output $VGA --off
fi
if [ "${HDMI_STATUS}" = connected ]; then
xrandr
xrandr --output $HDMI --auto
else
xrandr --output $HDMI --off
fi
exit 0