Skip to content

Instantly share code, notes, and snippets.

@thomasleveil
Last active August 4, 2019 17:10
Show Gist options
  • Save thomasleveil/975bd3bb186add9dc34dc1e3fc3f403d to your computer and use it in GitHub Desktop.
Save thomasleveil/975bd3bb186add9dc34dc1e3fc3f403d to your computer and use it in GitHub Desktop.
workaround BIOS / NVidia backlight issues

From https://wiki.archlinux.org/index.php/backlight#sysfs_modified_but_no_brightness_change

Works for Laptop msi GT72VR 6RD Dominator

sysfs modified but no brightness change

Note: This behavior and their workarounds have been confirmed on the Dell M6700 with Nvidia K5000m (BIOS version prior to A10) and Clevo P750ZM (Eurocom P5 Pro Extreme) with Nvidia 980m.

On some systems, the brighness hotkeys on your keyboard correctly modify the values of the acpi interface in /sys/class/backlight/acpi_video0/actual_brightness but the brightness of the screen is not changed. Brigthness applets from desktop environments may also show changes to no effect.

If you have tested the recommended kernel parameters and only xbacklight works, then you may be facing an incompatibility between your BIOS and kernel driver.

In this case the only solution is to wait for a fix either from the BIOS or GPU driver manufacturer.

A workaround is to use the inotify kernel api to trigger xbacklight each time the value of /sys/class/backlight/acpi_video0/actual_brightness changes.

First install inotify-tools. Then create a script around inotify that will be launched upon each boot or through autostart.

sudo apt install inotify-tools xbacklight
cat <<-EO1 | sudo tee /usr/local/bin/xbacklightmon.sh
  #!/bin/bash
  # https://wiki.archlinux.org/index.php/backlight#sysfs_modified_but_no_brightness_change
  # apt install inotify-tools xbacklight 

  path=/sys/class/backlight/acpi_video0

  luminance() {
      read -r level < "$path"/actual_brightness
      factor=$((100 / max))
      printf '%d\n' "$((level * factor))"
  }

  read -r max < "$path"/max_brightness
  xbacklight -set "$(luminance)"


  inotifywait -me modify --format '' "$path"/actual_brightness | while read; do
      xbacklight -set "$(luminance)"
  done
EO1
sudo chmod +x /usr/local/bin/xbacklightmon.sh

cat <<-EO2 >~/.config/autostart/xbacklightmon.desktop
    [Desktop Entry]
    Type=Application
    Exec=/usr/local/bin/xbacklightmon.sh
    Hidden=false
    X-GNOME-Autostart-enabled=true
    Name=xbacklightmon
EO2
#!/bin/bash
# https://wiki.archlinux.org/index.php/backlight#sysfs_modified_but_no_brightness_change
# apt install inotify-tools xbacklight
path=/sys/class/backlight/acpi_video0
luminance() {
read -r level < "$path"/actual_brightness
factor=$((100 / max))
printf '%d\n' "$((level * factor))"
}
read -r max < "$path"/max_brightness
xbacklight -set "$(luminance)"
inotifywait -me modify --format '' "$path"/actual_brightness | while read; do
xbacklight -set "$(luminance)"
done
@lalten
Copy link

lalten commented Aug 4, 2019

Nice! Needs a LC_NUMERIC="en_US.UTF-8" in front of printf for me: https://stackoverflow.com/a/12846145/5559867

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