我在/etc/acpi/events和 中有以下文件/etc/udev/rules.d。
/etc/acpi/events/lidclose
# Pass all events to our one handler script
event=button/lid
action=/etc/acpi/monitors.sh
Run Code Online (Sandbox Code Playgroud)/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"
Run Code Online (Sandbox Code Playgroud)现在,(可执行并由 root 拥有) /etc/acpi/monitors.sh
#!/bin/sh
# default monitor is LVDS1
STATE=internal
INTERNAL=LVDS1
EXTERNAL=HDMI3
# functions to switch from LVDS1 to VGA and vice versa
function internal {
echo "Switching to internal"
xrandr --output $EXTERNAL --off --output $INTERNAL --auto
STATE=internal
}
function external {
echo "Switching to …Run Code Online (Sandbox Code Playgroud)