0

In awesome window manager, my screen brightness gets reset to 100% each time I'm away from my computer for a few minutes. How can I get it to sustain the brightness I set prior to these screen-saver/power-management timeouts?

Background:

Using autokey, I've created 3 scripts that enable me to adjust my screen's brightness with hotkeys. These scripts use the debian package brightnessctl to accomplish this:

sudo apt install brightnessctl

For the sake of being helpful to others, I will include these scripts below.

Increase Brightness:

import os
currentBrightness = system.exec_command("brightnessctl g")
brightnessLevel = str(int(currentBrightness) + 1)
if int(brightnessLevel) > 100:
    brightnessLevel = '100'
if brightnessLevel:
    cmd = "brightnessctl s " + brightnessLevel
    os.system(cmd)
    store.set_global_value("lastBrightness",brightnessLevel)

Decrease Brightness:

import os
currentBrightness = system.exec_command("brightnessctl g")
brightnessLevel = str(int(currentBrightness) - 1)
if int(brightnessLevel) < 1:
    brightnessLevel = '1'
if brightnessLevel:
    cmd = "brightnessctl s " + brightnessLevel
    os.system(cmd)
    store.set_global_value("lastBrightness",brightnessLevel)

Set Brightness via Dialog:

import os
currentBrightness = system.exec_command("brightnessctl g")
lastBrightness = store.get_global_value("lastBrightness")
if not lastBrightness:
    lastBrightness = '10'
msg = None
if (currentBrightness == lastBrightness):
    msg = 'Current Brightness = ' + currentBrightness + '\n\nSpecifiy your desired brightness (max is 100)?'
else:
    msg = 'Current Brightness = ' + currentBrightness + '\n\nYou recently changed brightness to ' + lastBrightness + ', but something else changed it since then.\n\nSpecifiy your desired brightness (max is 100)?'
os.system("numlockx on") # Turn Numlock On
#ary = dialog.input_dialog(title="Brightness", message='Specifiy desired brightness (max is 100):', default='5')
ary = dialog.input_dialog(title="Brightness", message=msg, default="10")
brightnessLevel = ary[1]
if brightnessLevel and int(brightnessLevel) > 0:
    store.set_global_value("lastBrightness",brightnessLevel)
    cmd = "brightnessctl s " + brightnessLevel
    os.system(cmd)

While these scripts are working perfectly, I do have an issue:

When I'm away from my computer for a few minutes, and then come back, my monitor will be in some type of power saving state, where the monitor has been either turned off or displays a black screen. When I wake up the monitor (by hitting a key or moving my mouse) the brightness that I previously set (using brightnessctl), has been changed back to 100% brightness.

How can I sustain my brightness settings thorough these screen-saver/power-saving timeouts?

Lonnie Best
  • 4,895
  • 6
  • 27
  • 42

1 Answers1

1

Don't know the direct answer, but here's a workaround.

Store the desired screen brightness value in a parameter file with a suitable default value for the first time it runs.

Write a daemon script (in bash or in your language of choice) that is launched at login. Most Desktop environments have an autostart facility to run such scripts for you. (KDE and Gnome both have this feature. I don't know about AWM.)

This script will loop forever in the background with a suitable delay in each iteration to keep its resource usage low.

In each iteration, the script will read the current screen brightness and compare it to the value in the file. If they're not the same it will adjust the brightness up or down appropriately.

Modify your AutoKey scripts to use/modify the value in the file instead of using the AutoKey global stored variable.

Your script should detect when the screen is off and do nothing so it doesn't inadvertently turn the screen on.

If you want to, you can also add something your script looks for (e.g. another file or another value in its parameter file). If this is not present or true, the script will terminate. You may also want something like this so your script doesn't interfere with special screen brightness settings which might be applied by power management when your battery is low or very low.

It's probably easier though just to use pkill to get rid of it when desired.

Joe
  • 1,368
  • 1
  • 16
  • 18