Skip to content

Instantly share code, notes, and snippets.

@ottosch
Last active January 13, 2025 21:57
Show Gist options
  • Save ottosch/abb3a98535efbca7ff5c20298ddcf114 to your computer and use it in GitHub Desktop.
Save ottosch/abb3a98535efbca7ff5c20298ddcf114 to your computer and use it in GitHub Desktop.
Settings to avoid laptop sleeping after lid is closed

Laptop lid configuration

Ignore the lid being closed

sudo nano /etc/systemd/logind.conf, change these values to ignore:

HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore

Restart service: sudo systemctl restart systemd-logind

Turn the screen off automatically

System without GUI

sudo nano /etc/default/grub, add consoleblank=<seconds> to GRUB_CMDLINE_LINUX_DEFAULT. Example:

GRUB_CMDLINE_LINUX_DEFAULT="quiet consoleblank=180"

sudo update-grub and reboot.

System with GUI

Call a script that turns the screen off when the lid is being closed.

sudo pacman -S acpid # or sudo apt install acpid
sudo systemctl start acpid
sudo systemctl enable acpid
sudo nano /etc/acpi/events/lid-close # any file name as long as it's in this directory

/etc/acpi/events/lid-close:

event=button/lid
action=/usr/local/bin/lid-close.sh # anywhere you want

/usr/local/bin/lid-close.sh:

#! /usr/bin/env bash

xset dpms force off

Make the script executable, then restart the service:

sudo chmod +x /usr/local/bin/lid-close.sh
sudo systemctl restart acpid

Bonus: set the screen brightness

echo 15 | sudo tee /sys/class/backlight/*/brightness >/dev/null

Brightness range: zero to /sys/class/backlight/*/max_brightness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment