我正在尝试为运行 Ubuntu 18.04 的 Thinkpad X250 设置最大屏幕亮度限制。
一些背景信息: 我把原来的屏幕换成了新的(在安装 Ubuntu 之前),亮度控制工作正常,但我注意到,亮度超过 55-60% 时,人眼几乎察觉不到变化,但它会消耗更多电池,并且开始变得非常热。我打算把这台电脑送给家里的年轻和没有经验的用户,所以我想设置一个限制,不需要用户在每次启动时采取行动,并且可以适用于所有用户,而不必担心通过软件管理器进行更新会删除设置。
我尝试过: 我尝试直接编辑/sys/class/背光/intel_backlight/max_brightness但它拒绝编辑(即使使用 chmod 更改权限)。我看到一些答案告诉我要添加如下命令“回显 MAX_VALUE > /sys/class/backlight/intel_backlight/max_brightness”在/etc/rc.local,但我没有这个文件。请注意,我没有 *acpi_** 文件或文件夹/sys/class/背光/。
设置所有用户永久亮度限制的正确方法是什么?
答案1
我编写了一个脚本来监视/sys/class/backlight/*/brightness
并重定向它:如何在 `/sys/class/backlight` 中切换选项来解决亮度问题?。
只需添加三行即可快速修改以满足您的需要:
# Modification for: https://askubuntu.com/questions/1051171/lowering-screen-max-brightness-with-ubuntu-18-04
# If brightness > 50, set to 50
[[ WatchPer -gt 50 ]] && WatchPer=50
修改后的redirected-brightness
脚本
#!/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
# Modification for: https://askubuntu.com/questions/1051171/lowering-screen-max-brightness-with-ubuntu-18-04
# If brightness > 50, set to 50
[[ WatchPer -gt 50 ]] && WatchPer=50
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
答案2
由于这是一个 Linux 内核只读值,因此无法按照您想要的方式完成此操作:
没有代码可以读取该值max_brightness
并对其采取行动:内核只是发布硬件的最大值。
如果您尝试强制内核仍然接受写入,它将抛出一个Input/output error
。
也许有一种方法可以:
- 拦截单独的按键,然后拒绝更高,但这意味着发布新问题并在这里再次说明为什么要这么做。
- 要求 Linus Torvalds 本人处理你的错误,但他近期解决这个问题的可能性很小......;-)