I installed an external monitor connected to my laptop. Since I'm on archlinux I needed to configure almost two things: screen and keyboards.
I wanted that screen stay poweron when I close the laptop and switch to the correct layout for the external keyboard (pure key pro).
## Configure ACPI `handle.sh` script
One easy way is to install acpi and setup script in `/etc/acpi/handler.sh`.
One major issue I faced was that randr need `.Xauthority` of the current session user to work and acpi script handle.sh run as root. So I added this adapted script I originally found on internet :
---
```bash
function GetXuser()
{
#Guess the user logged on server $1
w -huf|grep " $1 "|cut -d " " -f 1|head -n 1
}
export DISPLAY=:0
export USER=$(GetXuser $DISPLAY)
export XAUTHORITY=/home/$(GetXuser $DISPLAY)/.Xauthority
```
---
Here piece of code I used to set screen and keyboard on lid events:
Keyboard part is not tested yet, still a WIP and I will update this entry as soon as I progress !
# TODO
* [ ] started to have some udev rules to detect screen plug but not much success to get the event launch the monitor script
* [ ] change layout keyboard on plugin via udev rules