![桌面显示器亮度调节](https://linux22.com/image/875955/%E6%A1%8C%E9%9D%A2%E6%98%BE%E7%A4%BA%E5%99%A8%E4%BA%AE%E5%BA%A6%E8%B0%83%E8%8A%82.png)
是否可以像笔记本电脑一样调整台式机显示器亮度?
是的,所有台式机显示器都有单独的菜单。
但是是否可以将其更改为 Winkey+(F1..F12) 之类的操作?
显示器通过 VGA 或 DVI 电缆连接。
- 操作系统:Ubuntu 14.04
- 桌面显示器
答案1
使用以下脚本,您可以将屏幕亮度设置为0.1
到1.0
,共 9 个步骤,任何“服从”的系统xrandr
。
只需使用参数“up”或“down”运行它即可将当前亮度增加/减少一步。
剧本
#!/usr/bin/env python3
import subprocess
import sys
arg = sys.argv[1]
# get the data on screens and current brightness, parsed from xrandr --verbose
current = [l.split() for l in subprocess.check_output(["xrandr", "--verbose"]).decode("utf-8").splitlines()]
# find the name(s) of the screen(s)
screens = [l[l.index("connected")-1] for l in current if "connected" in l]
# find the current brightness
currset = (round(float([l for l in current if "Brightness:" in l][0][1])*10))/10
# create a range of brightness settings (0.1 to 1.0)
sets = [n/10 for n in list(range(11))][1:]
# get the current brightness -step
step = len([n for n in sets if currset >= n])
if arg == "up":
if currset < 1.0:
# calculte the first value higher than the current brightness (rounded on 0.1)
nextbright = (step+1)/10
if arg == "down":
if currset > 0.1:
# calculte the first value lower than the current brightness (rounded on 0.1)
nextbright = (step-1)/10
try:
for scr in screens:
# set the new brightness
subprocess.Popen(["xrandr", "--output", scr, "--brightness", str(nextbright)])
except NameError:
pass
如何使用
- 将脚本复制到一个空文件中,另存为
set_brightness.py
通过以下命令测试运行:
python3 /path/to/set_brightness.py up
和
python3 /path/to/set_brightness.py down
如果一切正常,请将这两个命令添加到快捷键中:选择:系统设置 > “键盘” > “快捷键” > “自定义快捷键”。单击“+”,将上述两个命令添加到两个不同的快捷键中。
解释
代码的解释基本都在脚本里:)
笔记
事实上,脚本会为“主”屏幕和可能的附加屏幕设置相同的亮度。