Views:
5,430â
Votes: 5â
â
Solution
Tags:
brightness
acpi
Link:
đ See Original Answer on Ask Ubuntu ⧠đ
URL:
https://askubuntu.com/q/1045763
Title:
How to switch between options in `/sys/class/backlight` to solve brightness problem?
ID:
/2018/06/12/How-to-switch-between-options-in-__sys_class_backlight_-to-solve-brightness-problem_
Created:
June 12, 2018
Edited: April 4, 2019
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: true
Copy to clipboard: false
Bash script redirect-brightness
Your problem is function keys to increase/decrease brightness are updating /sys/class/backlight/acpi_video0/brightness
instead of /sys/class/backlight/nv_backlight/brightness
The original request was to intercept the function keys and use them to control the nv_backlight
driver. The problem with this is:
- Tricky
udev
scripts - No pop-up notification slider displaying brightness without complicated Python scripting.
The solution is to use inotify
to monitor changes to acpi_video0
. Then calculate the brightness percentage and apply that same percentage to nv_backlight
.
In the bash script below you need to set:
WatchDriver="/sys/class/backlight/acpi_video0/brightness"
PatchDriver="/sys/class/backlight/nv_backlight/brightness"
Place the script in /usr/local/bin
and make it executable using:
chmod a+x /usr/local/bin/redirect-brightness
First run the script from the command line using
redirect-brightness -l
If there is a problem check the log file using:
cat /tmp/redirect-brightness.log
If all works well add redirect-brightness
to your startup applications.
redirect-brightness
bash script
``` bash #!/bin/bash
NAME: redirect-brightness
PATH: /usr/local/bin
DESC: Redirect to correct driver when Ubuntu is adjusting the wrong
/sys/class/DRIVER_NAME/brightness
DATE: June 13, 2018. Modified June 14, 2018.
NOTE: Written for Ubuntu question:
https://askubuntu.com/q/1045624/307523
WatchDriver=â/sys/class/backlight/intel_backlightâ PatchDriver=â/sys/class/backlight/intel_backlightâ
Must be running as sudo
if [[ $(id -u) != 0 ]]; then echo >&2 âRoot access required. Use: âsudo redirect-brightnessââ exit 1 fi
inotifywait required
type inotifywait >/dev/null 2>&1 ||
{ echo >&2 ââinotifywaitâ required but itâs not installed. Aborting.â;
echo >&2 âUse âsudo apt install inotify-toolsâ to install it.ââ;
exit 1; }
Was right watch driver directory name setup correctly?
if [[ ! -d $WatchDriver ]]; then
echo >&2 âWatch directory: â$WatchDriverââ;
echo >&2 âdoes not exist. Did you spell it correctly? Aborting.ââ;
exit 1;
fi
Was right patch driver directory name setup correctly?
if [[ ! -d $PatchDriver ]]; then
echo >&2 âRedirect to directory: â$PatchDriverââ;
echo >&2 âdoes not exist. Did you spell it correctly? Aborting.ââ;
exit 1;
fi
Get maximum brightness values
WatchMax=$(cat $WatchDriver/max_brightness) PatchMax=$(cat $PatchDriver/max_brightness)
PARM: 1=â-lâ or ââlog-fileâ then write each step to log file.
fLogFile=false if [[ $1 == â-lâ ]] || [[ $1 == ââlog-fileâ ]]; then fLogFile=true LogFile=/tmp/redirect-brightness.log echo redirect-brightness LOG FILE > $LogFile echo WatchMax: $WatchMax PatchMax: $PatchMax » $LogFile fi
SetBrightness () { # Calculate watch current percentage WatchAct=$(cat $WatchDriver/actual_brightness) WatchPer=$(( WatchAct * 100 / WatchMax )) [[ $fLogFile == true ]] && echo WatchAct: $WatchAct WatchPer: $WatchPer » $LogFile # Reverse engineer patch brightness to set PatchAct=$(( PatchMax * WatchPer / 100 )) echo $PatchAct | sudo tee $PatchDriver/brightness [[ $fLogFile == true ]] && echo PatchAct: $PatchAct » $LogFile }
When machine boots, set brightness to last saved value
SetBrightness
Wait forever for user to press Fn keys adjusting brightness up/down.
while (true); do
inotifywait âevent modify $WatchDriver/actual_brightness
[[ $fLogFile == true ]] &&
echo âProcessing modify event in $WatchDriver/actual_brightnessâ » $LogFile
SetBrightness
done
```
Original Answer June 11, 2018.
Work In Progress Answer
There are many nVidia users with similar problems in Ubuntu 18.04:
- Brightness on laptop MSI GT72VR in Ubuntu 18.04 with NVIDIA GTX 1060 Mobile doesn't work
- computer doesnt wake from suspension and couldnt change the brightness
- Brightness control missing when using Nvidia drivers but re-appears with X.Org
- Xubuntu 18.04: make Fn brightness keys work with /sys/class/backlight/nv_backlight/
- How to alter backlight driver in lubuntu
- Brightness on laptop MSI GT72VR in Ubuntu 18.04 with NVIDIA GTX 1060 Mobile doesn't work
- NVIDIA display issue with brightness control and video playback
- Unable to change the screen brightness
- The brightness of laptop screen cannot be adjusted with either the buttons or the slider. Edit
Before writing a script
I can write a script to mimic changes to /acpi_video and populate /nv_backlight but before I do try this:
- Edit
/etc/default/grub
. - Find
quiet splash
- Add behind splash:
acpi_backlight=vendor
- Save the file
- Run
sudo update-grub
According to this answer it should work for you: Xubuntu 18.04: make Fn brightness keys work with /sys/class/backlight/nv_backlight/
Wayland
Brightness doesnât work under Wayland. Make sure you arenât using it. See: The brightness of laptop screen cannot be adjusted with either the buttons or the slider. Edit