The whole Wayland ecosystem has improved a LOT since last time I used it. That was last year, as I give Wayland a try once a year since 2016.
However, I had to ditch an useful daemon, dockd. It does automatically disable my laptop screen when I put it in the dock station, but it does relies over xrandr.
What to use then?
The acpid daemon can be configured to listen to ACPI events and to trigger your custom script. You just have to define which events are you interested in (it does accept wildcards also) and which script acpid should trigger when such events occurs.
acpi_listen to catch the events which gets triggered by the physical dock/undock actions:
# acpi_listen ibm/hotkey LEN0068:00 00000080 00004010 [...] ibm/hotkey LEN0068:00 00000080 00004011 [...]
Then, I setup an
acpid listener by creating the file
/etc/acpi/events/dock with the following content:
event=ibm/hotkey action=/etc/acpi/actions/dock.sh %e
This listener will call my script only when an event of type
ibm/hotkey occurs, then it tells
sway to disable or enable the laptop screen based on the action code. Here’s my
#!/bin/sh pid=$(pgrep '^sway$') if [ -z $pid ]; then logger "sway isn't running. Nothing to do" exit fi user=$(ps -o uname= -p $pid) case "$4" in 00004010) runuser -l $user -c 'SWAYSOCK=/run/user/$(id -u)/sway-ipc.$(id -u).$(pidof sway).sock swaymsg "output LVDS-1 disable"' logger "Disabled LVDS-1" ;; 00004011) runuser -l $user -c 'SWAYSOCK=/run/user/$(id -u)/sway-ipc.$(id -u).$(pidof sway).sock swaymsg "output LVDS-1 enable"' logger "Enabled LVDS-1" ;; esac
Don’t forget to make it executable!
chmod +x /etc/acpi/actions/dock.sh
And then start the
systemctl enable --now acpid
Tags: linux, howto