In the previous post on autorandr
I mentioned how it didn’t respond to the Laptop lid open/close event. It’s a known issue, and a discussion is ongoing on Github: “Be aware of lid state“.
The latest autorandr
is supposed to have a fix for it, but it didn’t work for me. I found another solution from that thread instead.
On a high level, the solution is:
autorandr
can detect the right configuration with lid open/close, it just can’t switch to it automatically since lid close/event is not an external display plug/unplug event.- We simply need to hook into the lid open/close event and manually trigger the switch command:
autorandr --change
. - This can be done using
acpi
on Linux. See the instructions below.
Executing Script on Lid Open/Close Event
Let’s create the script first. Create a file at the following location /etc/acpi/autorandr.sh
with the following content:
#!/bin/bash /usr/bin/autorandr --batch --change
Make sure you provide executable permission to the script by running sudo chmod +x autorandr.sh
, or else it won’t work.
Next, we create a lid open/close event signal and hook the script with it. Create a file at the location /etc/api/events/lid-switch
:
event=button/lid LID (open|close) action=/etc/acpi/autorandr.sh
With this, closing/opening the lid should automatically trigger autorandr
for setting your saved profile.