Skip to content

Instantly share code, notes, and snippets.

@mmueller
Last active August 31, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmueller/5553027 to your computer and use it in GitHub Desktop.
Save mmueller/5553027 to your computer and use it in GitHub Desktop.
This is an ugly-ass hack to temporarily fix a brightness jumping problem with some nvidia-based laptops on Linux, until nvidiabl/nvidia drivers fix the issue. Watches the actual brightness of the display, and when it jumps up past the maximum, resets it to the original desired value.
#!/usr/bin/env python
import os
import time
BACKLIGHT = 'nvidia_backlight'
DELAY = 0.2
def get_value(name):
path = os.path.join('/sys/class/backlight', BACKLIGHT, name)
return int(open(path, 'r').read())
def set_value(name, value):
path = os.path.join('/sys/class/backlight', BACKLIGHT, name)
open(path, 'w').write(str(value))
def watch_brightness():
maximum = get_value('max_brightness')
while True:
actual = get_value('actual_brightness')
if actual > maximum:
desired = get_value('brightness')
set_value('brightness', desired)
time.sleep(DELAY)
if __name__ == '__main__':
watch_brightness()
@mmueller
Copy link
Author

See discussion here: guillaumezin/nvidiabl#56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment