Brightness resets on resuming from sleep

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
shalin

Brightness resets on resuming from sleep

Post by shalin »

Hi,

Mint doesn't seem to remember the Brightness setting after resuming from sleep. Brightness setting is increased to Max upon every resume after sleep, even though the slider in the power setting applet is showing my desired setting level. I now need to manually adjust this every time. Other than this
I really love using Linux Mint 19. It has given my 7 year old Sony Vaio laptop a new life. Any help?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

I don't know what's wrong but maybe this workaround helps?

Run this in a terminal (copy & paste as a whole):

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/*/brightness > /tmp/backlight-brightness
        ;;
    post)
        cat /tmp/backlight-brightness > tee /sys/class/backlight/*/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
and finally this:

Code: Select all

sudo chmod +x /lib/systemd/system-sleep/restore_backlight_brightness
Suspend and resume to see if it works.
Lord Boltar

Re: Brightness resets on resuming from sleep

Post by Lord Boltar »

Option 1

Install xbacklight program by typing the following in the terminal:

sudo apt-get install xbacklight or get it from the Synaptic Package Manager

Now press alt+f2 from your keyboard, and type gnome-session-properties. Click on the application, and from the window popped, click add, and fill the following:

name = Brightness Fixed

command= xbacklight -set 25

click add and you're done. Restart to check the effects.

Option 2

1) open your terminal and type gedit /etc/default/grub (note where gedit is this may need to be changed to whatever text editor you are using)

Example - in my case i use Xed as a text editor so on my machine it would be xed /etc/default/grub

2) after gedit (whatever text editor you are using) open then find this line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

ps: it can be “quiet splash” or just “quiet”

3) change that line to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_backlight=vendor"

4) save it and then type in your terminal update-grub

5) restart your computer, and set your brightness to whatever you want restart again and see that your brightness will not set to max every time you reset your computer

Option 2 seems to work better for most that I have search for with this issue hope this helps
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

gm10 wrote: Tue Sep 11, 2018 1:19 pm I don't know what's wrong but maybe this workaround helps?

Run this in a terminal (copy & paste as a whole):

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/*/brightness > /tmp/backlight-brightness
        ;;
    post)
        cat /tmp/backlight-brightness > tee /sys/class/backlight/*/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
and finally this:

Code: Select all

sudo chmod +x /lib/systemd/system-sleep/restore_backlight_brightness
Suspend and resume to see if it works.
I've tried running this in terminal but it didn't help. LM19 seems to remember the brightness setting during restarts or on powering on. The problem occurs only when the systems resumes from inactivity i.e. while the screen turns on from off.
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

Lord Boltar wrote: Tue Sep 11, 2018 1:36 pm Option 1

Install xbacklight program by typing the following in the terminal:

sudo apt-get install xbacklight or get it from the Synaptic Package Manager

Now press alt+f2 from your keyboard, and type gnome-session-properties. Click on the application, and from the window popped, click add, and fill the following:

name = Brightness Fixed

command= xbacklight -set 25

click add and you're done. Restart to check the effects.

Option 2

1) open your terminal and type gedit /etc/default/grub (note where gedit is this may need to be changed to whatever text editor you are using)

Example - in my case i use Xed as a text editor so on my machine it would be xed /etc/default/grub

2) after gedit (whatever text editor you are using) open then find this line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

ps: it can be “quiet splash” or just “quiet”

3) change that line to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_backlight=vendor"

4) save it and then type in your terminal update-grub

5) restart your computer, and set your brightness to whatever you want restart again and see that your brightness will not set to max every time you reset your computer

Option 2 seems to work better for most that I have search for with this issue hope this helps

The problem does not happen between restarts. LM19 remembers the brightness settings between restarts, but on waking up the screen from sleep ( ie monitor off from being away ) the brightness gets maxed up, even though the power setting slider shows my preferred setting. Should I still try installing xbacklight?
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

shalin wrote: Wed Sep 12, 2018 10:03 am I've tried running this in terminal but it didn't help. LM19 seems to remember the brightness setting during restarts or on powering on. The problem occurs only when the systems resumes from inactivity i.e. while the screen turns on from off.
Yes, I had understood that, which is why that script writes your brightness setting to disk just before you enter sleep and restores it after resuming. I did however make a mistake in the script which caused it to fail, my apologies. Please try again like this:

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/*/brightness > /tmp/backlight-brightness
        ;;
    post)
        cp /tmp/backlight-brightness /sys/class/backlight/*/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

gm10 wrote: Wed Sep 12, 2018 10:11 am
shalin wrote: Wed Sep 12, 2018 10:03 am I've tried running this in terminal but it didn't help. LM19 seems to remember the brightness setting during restarts or on powering on. The problem occurs only when the systems resumes from inactivity i.e. while the screen turns on from off.
Yes, I had understood that, which is why that script writes your brightness setting to disk just before you enter sleep and restores it after resuming. I did however make a mistake in the script which caused it to fail, my apologies. Please try again like this:

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/*/brightness > /tmp/backlight-brightness
        ;;
    post)
        cp /tmp/backlight-brightness /sys/class/backlight/*/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
Thanks for the reply, I just tried the above code but it didn't work. On investigating /sys/class/backlight/ as per your code, there are two folders there acpi_video0 and radeon_bl0 and both have a brightness and actual_brightness file. On google searching it shows that value of these files should change on changing the brightness. Currently the acpi_video0 - brightness file shows a value of 2 ( so probably the value for my default setting ) while the readeon_bl0 brightness file shows 255 ( max brightness ??? ). So I tried increasing the brightness and checking the values on the file -
acpi_video0 = both the brightness and actual_brightness increases value
radeon_blo = only actual_brightness is increasing. The value in brightness is still 255.
Is this in any way related to the problem? Thanks for your time.
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

My bad, I usually even ask to check if there are two values for this, dunno why I forgot. I think Lord Boltar's second suggestion might be applicable here actually, not sure (never owned a radeon).

But if we want to stick with the scripting, can you see if this changes your brightness:

Code: Select all

echo 2 | sudo tee /sys/class/backligh/acpi_video0/brightness
and then to put it to max:

Code: Select all

sudo cp /sys/class/backligh/acpi_video0/max_brightness /sys/class/backligh/acpi_video0/brightness
If yes, then I think if you modify my script like this it will probably work:

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backligh/acpi_video0/brightness > /tmp/backlight-brightness
        ;;
    post)
        cp /tmp/backlight-brightness /sys/class/backligh/acpi_video0/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
If your manual test worked but the script didn't, then it probably just needs a delay added. But try as is first.

PS: If you ever deleted my script in-between, you'd need to make it executable again:

Code: Select all

sudo chmod +x /lib/systemd/system-sleep/restore_backlight_brightness
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

Thank you gm10, the manual test worked, but the script didn't work. So might need that delay, how do I add it?
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

The poor man's version is this, note the sleep 1 line which puts it to sleep for a second, choose a longer delay if necessary:

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/acpi_video0/brightness > /tmp/backlight-brightness
        ;;
    post)
    	sleep 1
        cp /tmp/backlight-brightness /sys/class/backlight/acpi_video0/brightness
        rm -f /tmp/backlight-brightness
        ;;
esac
EOB
More sophisticated would be to add a loop and wait for the brightness to get changed and then change it back right away, but I don't mind being a little bit lazy as long as it works. ;)
Last edited by gm10 on Thu Sep 13, 2018 11:13 am, edited 2 times in total.
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

Shockingly, this doesn't seems to work either, gm10. It is not by the minor typo in the code ( backlight ) I've corrected it and tried. I've tried increasing the sleep value to 5 seconds also, no joy. Only the value in actual_brightness in the radeon0 folder seems to change to 255 on each wake, so I tried modifying your code to target radeon0 actual_brightness, that also didn't work. ( I just tried this out of desperation )

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness_radeon <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cat /sys/class/backlight/radeon_bl0/actual_brightness > /tmp/backlight-brightness-radeon
        ;;
    post)
        sleep 1
        cp /tmp/backlight-brightness-radeon /sys/class/backlight/radeon_bl0/actual_brightness
        rm -f /tmp/backlight-brightness-radeon
        ;;
esac
EOB



******

sudo chmod +x /lib/systemd/system-sleep/restore_backlight_brightness_radeon
I've tried editing the grub file as suggested by Lord Boltar but it messed up brightness settings between restarts. So I've reverted back to default grub settings.
Your following code can successfuly change the brightness to maximum through the terminal, so why isn't it working during the script call?

Code: Select all

sudo cp /sys/class/backlight/acpi_video0/max_brightness /sys/class/backlight/acpi_video0/brightness
Any ideas?
Thanks for your valuable time, gm10.
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

Hmm, 5 seconds should have been plenty. And good job catching my typo, I'm terrible when I do these things on the side, sorry. Try like this:

Code: Select all

sudo tee /lib/systemd/system-sleep/restore_backlight_brightness <<'EOB'
#!/bin/sh
case $1 in
    pre)
        cp /sys/class/backlight/acpi_video0/brightness /tmp/backlight-brightness
        ;;
    post)
        cp /tmp/backlight-brightness /sys/class/backlight/acpi_video0/brightness
        ;;
esac
EOB
Suspend, resume, and we already know it won't work. But once you're resumed try this then:

Code: Select all

sudo cp /tmp/backlight-brightness /sys/class/backlight/acpi_video0/brightness
If it does work then I'll have to think of something. However, I have a feeling it may not work, and in that case gather some data:

Code: Select all

cat /tmp/backlight-brightness
cat /sys/class/backlight/acpi_video0/brightness
cat /sys/class/backlight/acpi_video0/max_brightness
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

Following are the test results, seems like our temp file is not getting created or something. What do you say?
shalin@shalin-VPCEB34EN:~$ cat /tmp/backlight-brightness
cat: /tmp/backlight-brightness: No such file or directory
shalin@shalin-VPCEB34EN:~$ cat /sys/class/backlight/acpi_video0/brightness
2
shalin@shalin-VPCEB34EN:~$ cat /sys/class/backlight/acpi_video0/max_brightness
8
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

shalin wrote: Fri Sep 14, 2018 10:36 am Following are the test results, seems like our temp file is not getting created or something. What do you say?
Exactly. Which I believe can only mean two things (other than us wasting our time all this thread): Either you didn't run

Code: Select all

sudo chmod +x /lib/systemd/system-sleep/restore_backlight_brightness
earlier or you are using a non-standard way to suspend the system.

Run

Code: Select all

ll /lib/systemd/system-sleep/restore_backlight_brightness
to confirm the script is executable and/or try to suspend from the command line manually like this

Code: Select all

systemctl suspend
and see if the /tmp/backlight-brightness file gets created.

That aside, and about as important:
shalin wrote: Fri Sep 14, 2018 10:36 am shalin@shalin-VPCEB34EN:~$ cat /sys/class/backlight/acpi_video0/brightness
2
Brightness 2 is the brightness you want though, so was this after adjusting it or what happened here? You said it gets set to max, which is 8. What was the actual screen brightness?
shalin

Re: Brightness resets on resuming from sleep

Post by shalin »

My apologies gm10, you were right, the problem is from the fact that I have been wrongly wording the state as 'sleep mode'.
systemctl suspend makes the system go to sleep mode. My brightness problem arises when monitor brightness dims from being inactive ( not sleep mode where the computer is sleep state )

For testing your codes , I have kept my system idle for some time to "turn the screen inactive after 5 minutes option" from the power settings and lately I've been using this command
#!/bin/bash
sleep 1; xset dpms force off
for switching off the screen faster ( Can't wait 5 mins every time ).

On running suspend command:
shalin@shalin-VPCEB34EN:~$ systemctl suspend
shalin@shalin-VPCEB34EN:~$ cat /tmp/backlight-brightness
2
shalin@shalin-VPCEB34EN:~$ cat /sys/class/backlight/acpi_video0/brightness
2
shalin@shalin-VPCEB34EN:~$ cat /sys/class/backlight/acpi_video0/max_brightness
8
systemctl suspend is not be the trigger that causes the brightness problem. But after running the sytemctl suspend, my problem is fixed completely as my brightness are being remembered after resuming from
#!/bin/bash
sleep 1; xset dpms force off
command on mouse movement.
But problem lies in the fact that I've to manually run systemctl suspend after every restart for this to work. What to do to make it permanent?

Thanks again for your valuable time, it's been almost a week that you are helping me. Really appreciate it. My apologies , If I've been not clearly communicating in previous posts.
gm10

Re: Brightness resets on resuming from sleep

Post by gm10 »

It's ok, shit happens, but I'm sure you'll understand that I'll not invest more time until we are very specific about the cause now. And on that exact note, these two statements seem at odds - screen dimming and restarting:
shalin wrote: Sat Sep 15, 2018 10:57 am My brightness problem arises when monitor brightness dims from being inactive ( not sleep mode where the computer is sleep state )

[...]

But problem lies in the fact that I've to manually run systemctl suspend after every restart for this to work. What to do to make it permanent?
Also please clarify whether the following is with any scripting as above in place or works without that:
shalin wrote: Sat Sep 15, 2018 10:57 am But after running the sytemctl suspend, my problem is fixed completely
Locked

Return to “Graphics Cards & Monitors”