I have a Dell XPS 13 that had this problem a couple of years back. The solution was to write a script that would save the current brightness setting when sleeping or hibernating, then re-apply that brightness when waking up.
Here's how you can do the same:
Open Terminal (if it's not already open)
Create a file in /etc/pm/sleep.d
as root
using your preferred text editor:
sudo vi /etc/pm/sleep.d/10_brightness_control
Paste the following:
#!/bin/bash
# Description: Save the brightness before sleeping and set after waking
case "${1}" in
hibernate|sleep) before_suspend=$(cat /sys/class/backlight/*/brightness)
;;
resume|thaw) sleep 0.33 && echo "$before_suspend" > /sys/class/backlight/*/brightness
;;
esac
Set the file as executable:
sudo chmod +x /etc/pm/sleep.d/10_brightness_control
That's all there is to it. Now, when the system goes to hibernate or sleep, the brightness level will be captured and stored in $before_suspend
. When the system wakes from this state, that value will be written to all of the brightness
files that exist under /sys/class/backlight/*
(most computers will have just one) after 0.33 seconds. The delay takes into account situations where this script runs before the desktop environment sets its brightness level. As a result, you might have a split-second of blinding light followed by something readable.
This method has been tested and confirmed working on Ubuntu Desktop 18.04, Ubuntu MATE 18.04, Ubuntu MATE 18.10, Ubuntu Desktop 19.10, and Ubuntu Desktop 20.04.
Notes on the 10_brightness_control
file:
Hope this gives you what you need 👍🏻