通过软件控制外接显示器亮度

rem*_*emi 11 brightness external-monitor

你好 Ubuntu 社区,

我可以通过以下命令控制与 DisplayPort 连接的 DELL U2713HM 的亮度:

ddccontrol -p -r 0x10 -w 53
Run Code Online (Sandbox Code Playgroud)

在此示例中,数字 53 表示亮度级别(范围 0 到 100)。但我不知道如何将命令链接到我键盘上的亮度键。

我已经搜索过,但刚刚找到了集成笔记本电脑屏幕的答案。In/sys/class/backlightacpi_video0包含一些子文件夹和文件的文件夹。文件 actual_brightness 包含一个从 0 到 20 的数字,当我按下亮度键时,这个数字会发生变化。

如何将我的外接显示器列为 /sys/class/backlight 中的设备?

PS:我正在运行带有集成显卡 Intel HD4000 的全新 Ubuntu 12.10 安装。

Ger*_*ger 6

我认为您想要的外接显示器的解决方案/sys/class/backlight行不通,但好消息是您可以拥有漂亮的亮度动画!

尝试

notify-send " " -i notification-display-brightness-low -h int:value:50 -h string:x-canonical-private-synchronous:brightness &
Run Code Online (Sandbox Code Playgroud)

现在我们可以制作一个脚本来模拟 Ubuntu 的亮度调节器:

#!/bin/bash
#get current brightness
presbright=$(ddccontrol -p | grep -A1 0x10 | tr -d '\n\t' | sed 's/.*value=\([^a-zA-Z]*\),.*/\1/')
#stepsize for the brightness change
stepsize=10

case "$1" in
        up)
          newbright=$(( ${presbright}+${stepsize} ))
          newbright=$(echo $newbright | awk '{if($1 < 100){if($1 > 0) print $1; else print 0;} else print 100;}')

          notify-send " " -i notification-display-brightness-low -h int:value:$newbright -h string:x-canonical-private-synchronous:brightness &
          ddccontrol -p -r 0x10 -w $newbright
        ;;
        down)
          newbright=$(( ${presbright}-${stepsize} ))
          newbright=$(echo $newbright | awk '{if($1 < 100){if($1 > 0) print $1; else print 0;} else print 100;}')

          notify-send " " -i notification-display-brightness-low -h int:value:$newbright -h string:x-canonical-private-synchronous:brightness &
          ddccontrol -p -r 0x10 -w $newbright            
        ;;
        status)
          echo $presbright
        ;;
        *)
          echo "Accepted arguments are: up, down, status."
        ;;
esac

exit 0
Run Code Online (Sandbox Code Playgroud)

如您所见,它将值限制在 0 到 100 之间。现在您可以使用System Settings > Keyboard > Shortcuts将脚本的updown调用绑定到您选择的某些键盘快捷,就像 fotomonster 建议的那样。


注意:
我不知道需要多少时间ddccontrol -p,如果时间太长,您还sync可以在脚本中添加一个选项,将显示器的亮度值保存到文件中。然后,而不是从ddccontrol您那里获取当前亮度,只需从您的文件中获取它,这应该会快得多。当然,您需要更新updown调用以将新亮度写入文件...


脚本灵感来自archlinux 上这篇文章