我正在使用 Ubuntu Trusty tahr,我注意到没有亮度控制(如滑块),在 Windows 中,我将使用英特尔的图形媒体加速器来降低亮度,但在这里看起来不可能。
我会在深夜使用我的电脑来学习,而我的显示器的硬件按钮坏了,所以任何帮助都会受到赞赏。
不久前,我在这个网站上发现了某人提供的一个不错的脚本。这不是我的!

从那时起,我就在我的上网本上使用它,运行它Xubuntu,它似乎可以在任何东西上运行。
由于不发布仅链接答案的原因,这里是:
#!/usr/bin/env python
from gi.repository import Gtk
import subprocess
class BrightnessScale:
def __init__(self):
# get active monitor and current brightness
self.monitor = self.getActiveMonitor()
self.currB = self.getCurrentBrightness()
def initUI(self):
# initliaze and configure window
window = Gtk.Window()
window.set_title('Brightness Scale')
window.set_default_size(250, 50)
window.set_position(Gtk.WindowPosition.CENTER)
window.set_border_width(10)
# slider configuration
self.adjustment = Gtk.Adjustment(self.currB, 0, 100, 1, 10, 0)
self.scale = Gtk.HScale()
self.scale.set_adjustment(self.adjustment)
self.scale.set_digits(0)
# close Gtk thread on closing window
window.connect("destroy", lambda w: Gtk.main_quit())
# setup event handler on value-changed
self.scale.connect("value-changed", self.scale_moved)
# add the scale to window
window.add(self.scale)
# show all components in window
window.show_all()
# close window on pressing escape key
accGroup = Gtk.AccelGroup()
key, modifier = Gtk.accelerator_parse('Escape')
accGroup.connect(key, modifier, Gtk.AccelFlags.VISIBLE, Gtk.main_quit)
window.add_accel_group(accGroup)
def showErrDialog(self):
self.errDialog = Gtk.MessageDialog(None,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
"Unable to detect active monitor, run 'xrandr --verbose' on command-line for more info")
self.errDialog.set_title("brightness control error")
self.errDialog.run()
self.errDialog.destroy()
def initStatus(self):
if(self.monitor == "" or self.currB == ""):
return False
return True
def getActiveMonitor(self):
#Find display monitor
monitor = subprocess.check_output("xrandr -q | grep ' connected' | cut -d ' ' -f1", shell=True)
if(monitor != ""):
monitor = monitor.split('\n')[0]
return monitor
def getCurrentBrightness(self):
#Find current brightness
currB = subprocess.check_output("xrandr --verbose | grep -i brightness | cut -f2 -d ' '", shell=True)
if(currB != ""):
currB = currB.split('\n')[0]
currB = int(float(currB) * 100)
else:
currB = ""
return currB
def scale_moved(self, event):
#Change brightness
newBrightness = float(self.scale.get_value())/100
cmd = "xrandr --output %s --brightness %.2f" % (self.monitor, newBrightness)
cmdStatus = subprocess.check_output(cmd, shell=True)
if __name__ == "__main__":
# new instance of BrightnessScale
brcontrol = BrightnessScale()
if(brcontrol.initStatus()):
# if everything ok, invoke UI and start Gtk thread loop
brcontrol.initUI()
Gtk.main()
else:
# show error dialog
brcontrol.showErrDialog()
Run Code Online (Sandbox Code Playgroud)
将脚本粘贴到一个空文件中,将其保存为brightness_set(~/bin您可能必须创建目录)。使其可执行
添加到快捷键:选择:系统设置>“键盘”>“快捷键”>“自定义快捷键”。单击“+”并添加命令:
brightness_set
Run Code Online (Sandbox Code Playgroud)注销并重新登录,它应该可以工作
为了做出一个漂亮的设置,您可以通过在 Dash、启动器或任何其他应用程序菜单中添加一个.desktop文件来使滑块可用~/.local/share/applications

[Desktop Entry]
Type=Application
Name=Brightness Scale
Icon=/path/to/set_brightness.png
Exec=brightness_set
OnlyShowIn=Unity;
Run Code Online (Sandbox Code Playgroud)
在该Icon=行中,设置图标的路径。Yopu可以选择自己的图标,或者将下面的图标另存为set_brightness.png:

Exec=行中,假设脚本位于$PATH(包括~/binUbuntu 上)并且可执行| 归档时间: |
|
| 查看次数: |
3861 次 |
| 最近记录: |