0

Title says it all. When I lock, it stays the same, but if I suspend I'd say its going +100% brightness or idk what to call it. If I set the brightness to 0 I get a grey screen, if I set it to 1 I get a screen that has a massive white tint

On boot it works perfectly fine too btw. ONLY on suspend it breaks

2 Answers 2

0

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:

  1. Open Terminal (if it's not already open)

  2. Create a file in /etc/pm/sleep.d as root using your preferred text editor:

    sudo vi /etc/pm/sleep.d/10_brightness_control
    
  3. 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
    

  4. 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:

  • the file can be named just about anything, but it should have two digits up front — ideally 10
  • the file must be in /etc/pm/sleep.d/
  • the file must be owned by root
    sudo chown root:root /etc/pm/sleep.d/10_brightness_control
    
  • the file must be executable
    sudo chmod +x /etc/pm/sleep.d/10_brightness_control
    

Hope this gives you what you need 👍🏻

1
  • even after a restart it dosen't work. I did sudo nano and pasted all that inside, saved it as the right name, and made it executable. Is line 5 at sleep) a mistake? the brackets don't close making it end up as ) ( ) ) Feb 9, 2021 at 19:40
0

I did some testing and found out @user1091774 answer is partially correct. I wanted to share this as a comment but not enough reputation.

On ubuntu 22.04 you need to save such script in /lib/systemd/system-sleep (got that hint from here) and make it executable. You also need to change the cases, as sleep will have post and pre instead of sleep and thaw. You don't need to save the value in a variable, just reading and saving the same value into the file will do the work.

This script is working for me:

#!/bin/sh
# Description: Set brightness upon awakening
case "$1" in
    post)
        sleep 0.33 && cat /sys/class/backlight/nv_backlight/brightness | tee /sys/class/backlight/nv_backlight/brightness
        ;;
esac

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .