Com a ajuda dos caras que comentaram minha pergunta, descobri o que estava errado e corrigi-lo no script.
Aqui agora as rotinas atualizadas como obter a comutação automática de tela com o seu laptop para funcionar. Você precisa de acpid, kms e udev.
Crie as seguintes regras para o acpi e o udev
/ etc / acpi / events / lidclose
# Pass all events to our one handler script
event=button/lid
action=/etc/acpi/monitors.sh
/etc/udev/rules.d/80-monitor.rules
# change monitor settings when monitor is plugged in or o$
ACTION=="change", SUBSYSTEM=="drm", HOTPLUG=="1", RUN+="/etc/acpi/monitors.sh"
agora crie /etc/acpi/monitors.sh
#!/bin/sh
# specify the monitors to use
INTERNAL=LVDS1
EXTERNAL=HDMI3
USERNAME=oli
# set some variables needed to control the x server
export XAUTHORITY=/home/$USERNAME/.Xauthority
export DISPLAY=:0
# functions to switch from internal screen to external screen and vice versa or to use both screens together
function internal {
echo "Switching to internal" >> /var/log/monitors.log
xrandr --verbose --output $EXTERNAL --off --output $INTERNAL --auto >> /var/log/monitors.log 2>&1
}
function external {
echo "Switching to external" >> /var/log/monitors.log
xrandr --verbose --output $EXTERNAL --auto --output $INTERNAL --off >> /var/log/monitors.log 2>&1
}
function both {
echo "Switching to both" >> /var/log/monitors.log
xrandr --verbose --output $EXTERNAL --auto --right-of $INTERNAL --output $INTERNAL --auto --primary >> /var/log/monitors.log 2>&1
}
# functions to check if external monitor is connected and in use
function externalConnected {
! xrandr | grep "^$EXTERNAL" | grep disconnected >/dev/null
}
function lidOpen {
! cat /proc/acpi/button/lid/LID/state | grep closed >/dev/null
}
# actual script
if externalConnected && lidOpen
then
both
fi
if externalConnected && ! lidOpen
then
external
fi
if ! externalConnected && lidOpen
then
internal
fi
E esperamos que funcione.