操作系统:Ubuntu-18.04 LTS
/sys/class/backlight/
我在目录中有 2 个符号链接。
acpi_video0 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/backlight/acpi_video0/
nv_backlight -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/nv_backlight/
亮度热键可改变 的值acpi_video0/brightness
。但这实际上并没有改变显示器的亮度。
但是,手动改变值nv_backlight/brightness
实际上会改变显示器的亮度。
因此,将热键链接到nv_backlight
而不是acpi_video0
将解决我的问题,但我不知道如何做到这一点。
编辑:使用 Fn 键调整亮度(热键)时,屏幕上会出现弹出式滑块进度条。
编辑:
输入:
cat /sys/class/backlight/nv_backlight/max_brightness
输出:
100
输入:
cat /sys/class/backlight/nv_backlight/actual_brightness
输出(这个值自动变为相同的值,我手动给出了
/sys/class/backlight/nv_backlight/brightness
):10
输入:
cat /sys/class/backlight/acpi_video0/max_brightness
输出:
15
答案1
Bash 脚本redirect-brightness
你的问题是增加/减少亮度的功能键正在更新,/sys/class/backlight/acpi_video0/brightness
而不是/sys/class/backlight/nv_backlight/brightness
最初的请求是拦截功能键并使用它们来控制nv_backlight
驱动程序。这样做的问题是:
- 棘手的
udev
脚本 - 无需复杂的 Python 脚本,无需弹出通知滑块显示亮度。
解决方案是使用inotify
来监视 的变化acpi_video0
。然后计算亮度百分比并将该百分比应用于nv_backlight
。
在下面的 bash 脚本中您需要设置:
WatchDriver="/sys/class/backlight/acpi_video0/brightness"
PatchDriver="/sys/class/backlight/nv_backlight/brightness"
放置脚本/usr/local/bin
并使用以下命令使其可执行:
chmod a+x /usr/local/bin/redirect-brightness
首先使用命令行运行脚本
redirect-brightness -l
如果出现问题,请使用以下命令检查日志文件:
cat /tmp/redirect-brightness.log
如果一切顺利,请将其添加redirect-brightness
到您的启动应用程序中。
redirect-brightness
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
原始答案2018 年 6 月 11 日。
正在进行中的答案
许多 nVidia 用户在 Ubuntu 18.04 中遇到类似的问题:
- 搭载 NVIDIA GTX 1060 Mobile 的 Ubuntu 18.04 中 MSI GT72VR 笔记本电脑的亮度不起作用
- 计算机无法从挂起状态唤醒,也无法更改亮度
- 使用 Nvidia 驱动程序时亮度控制缺失,但使用 X.Org 时会重新出现
- Xubuntu 18.04:使 Fn 亮度键与 /sys/class/backlight/nv_backlight/ 配合使用
- 如何在 lubuntu 中修改背光驱动程序
- 搭载 NVIDIA GTX 1060 Mobile 的 Ubuntu 18.04 中 MSI GT72VR 笔记本电脑的亮度不起作用
- NVIDIA 显示亮度控制和视频播放问题
- 无法更改屏幕亮度
- 笔记本电脑屏幕的亮度无法通过按钮或滑块调整。编辑
在编写脚本之前
我可以编写一个脚本来模拟 /acpi_video 的变化并填充 /nv_backlight,但在我尝试这个之前:
- 编辑
/etc/default/grub
。 - 寻找
quiet splash
- 添加溅水背景:
acpi_backlight=vendor
- 保存文件
- 跑步
sudo update-grub
根据这个答案它应该适合你:Xubuntu 18.04:使 Fn 亮度键与 /sys/class/backlight/nv_backlight/ 配合使用
韦兰
亮度在 Wayland 下不起作用。确保您没有使用它。请参阅:笔记本电脑屏幕的亮度无法通过按钮或滑块调整。编辑