# Don't go to sleep if lid closed and monitor connected:
sed --in-place .backup 's/#HandleLidSwitchDocked=ignore/HandleLidSwitchDocked=ignore/' /etc/systemd/logind.conf
$ /etc/systemd/logind.conf
HandleLidSwitch=suspend # suspend when on battery
HandleLidSwitchExternalPower=ignore # inhibit suspend when on AC
HandleLidSwitchDocked=ignore # inhibit suspend when on external monitor
$ reboot
# ↓ or ↑
$ sudo systemctl restart systemd-logind # will kill current X/Wayland session