Fjo*_*rin 6 xrandr display laptop brightness alienware
所以我有一个带有 OLED 显示屏的 Alienware 13 R3,并且我第一次能够使用 xrandr 命令更改亮度。问题是 OLED 显示器没有背光,所以我无法用键盘或任何其他方式改变亮度。所以现在我知道我可以改变它,我想放置一个键绑定来改变亮度,比如 0.1。我用这个命令来改变亮度:
xrandr --output eDP-1-1 --brightness .5
Run Code Online (Sandbox Code Playgroud)
有谁知道使用什么命令不设置亮度,而是将其增加或减少某个值,以便我可以将宏绑定到它。提前致谢!
PS我对Linux完全陌生,所以请不要对我太苛刻:P
将下面的 bash 脚本复制到一个名为 bright
然后将其标记为可执行文件 chmod a+x bright
#!/bin/bash
MON="DP-1-1" # Discover monitor name with: xrandr | grep " connected"
STEP=5 # Step Up/Down brightnes by: 5 = ".05", 10 = ".10", etc.
CurrBright=$( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )
CurrBright="${CurrBright##* }" # Get brightness level with decimal place
Left=${CurrBright%%"."*} # Extract left of decimal point
Right=${CurrBright#*"."} # Extract right of decimal point
MathBright="0"
[[ "$Left" != 0 && "$STEP" -lt 10 ]] && STEP=10 # > 1.0, only .1 works
[[ "$Left" != 0 ]] && MathBright="$Left"00 # 1.0 becomes "100"
[[ "${#Right}" -eq 1 ]] && Right="$Right"0 # 0.5 becomes "50"
MathBright=$(( MathBright + Right ))
[[ "$1" == "Up" || "$1" == "+" ]] && MathBright=$(( MathBright + STEP ))
[[ "$1" == "Down" || "$1" == "-" ]] && MathBright=$(( MathBright - STEP ))
[[ "${MathBright:0:1}" == "-" ]] && MathBright=0 # Negative not allowed
[[ "$MathBright" -gt 999 ]] && MathBright=999 # Can't go over 9.99
if [[ "${#MathBright}" -eq 3 ]] ; then
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright="${MathBright:0:1}.${MathBright:1:2}"
else
MathBright="$MathBright"000 # Pad with lots of zeros
CurrBright=".${MathBright:0:2}"
fi
xrandr --output "$MON" --brightness "$CurrBright" # Set new brightness
# Display current brightness
printf "Monitor $MON "
echo $( xrandr --verbose --current | grep ^"$MON" -A5 | tail -n1 )
Run Code Online (Sandbox Code Playgroud)
MON="DP-1-1"
为您的监视器名称,即MON="HDMI-1"
xrandr | grep " connected"
STEP=5
您的步长值,例如STEP=2
不太明显调用脚本:
bright Up
或bright +
逐步增加亮度bright Down
或bright -
按步长值降低亮度bright
(无参数)获取当前亮度级别希望 bash / shell 命令可以很容易地通过谷歌搜索进行教育,但如果有任何问题,请不要犹豫,问:)
发布答案 8 分钟后,我突然想到我本可以用于bc
浮点数学并节省了大约 10 行代码以及 1.5 小时的大量时间来写它耸耸肩。
归档时间: |
|
查看次数: |
3916 次 |
最近记录: |