Ubuntu 18.04 – Disable screen on lid close

In order to force your Ubuntu to just disable the screen on lid close, you need to do two things:

  1. Disable sleep (do nothing) on lid close
  2. Disable screen on lid close

Just follow all the steps from both sections and you should be fine.

Disable sleep (do nothing) on lid close

Copy-paste this into the terminal (as a root):

# sudo su
echo 'HandleLidSwitch=ignore' | tee --append /etc/systemd/logind.conf
echo 'HandleLidSwitchDocked=ignore' | tee --append /etc/systemd/logind.conf
sudo service systemd-logind restart

Disable screen on lid close

Copy-paste this into the terminal (as a root):

# sudo su
echo 'event=button/lid.*' | tee --append /etc/acpi/events/lm_lid
echo 'action=/etc/acpi/lid.sh' | tee --append /etc/acpi/events/lm_lid
touch /etc/acpi/lid.sh
chmod +x /etc/acpi/lid.sh

Edit the /etc/acpi/lid.sh file, paste following content and replace the your_username with your main user name:

#!/bin/bash

USER=your_username

grep -q close /proc/acpi/button/lid/*/state

if [ $? = 0 ]; then
  su -c  "sleep 1 && xset -display :0.0 dpms force off" - $USER
fi

grep -q open /proc/acpi/button/lid/*/state

if [ $? = 0 ]; then
  su -c  "xset -display :0 dpms force on &> /tmp/screen.lid" - $USER
fi

Categories: Linux, Other

1 Comment

  1. If you want to disable e.g. the touchscreen you have to use xinput instead. Xinput does not have a display flag. Inthat case you have to use the DISPLAY variable in front of the command like:
    su -c ‘DISPLAY=:0.0 xinput disable “FTSC1000:00 2808:5120″‘ – $USER

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑