AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 739654
Accepted
misha
misha
Asked: 2016-02-27 22:56:03 +0800 CST2016-02-27 22:56:03 +0800 CST 2016-02-27 22:56:03 +0800 CST

让 Ubuntu 在没有 xbacklight 的情况下记住屏幕亮度级别

  • 772

问题是 Ubuntu 在每次重新启动后总是将亮度级别重置为最大值。我安装了该xbacklight实用程序,但类似xbacklight -get或xbacklight -set XX不起作用的命令。我没有得到任何输出。

实际上,我想让我的 Ubuntu 记住上次使用的亮度级别。我该怎么做?这里有一些信息:

ls -l /sys/class/backlight/
total 0
lrwxrwxrwx 1 root root 0 Feb 27 09:43 radeon_bl0 -> ../../devices/pci0000:00/0000:00:01.0/drm/card0/card0-LVDS-1/radeon_bl0


ls -l /sys/class/backlight/radeon_bl0/
total 0
-r--r--r-- 1 root root 4096 Feb 27 09:54 actual_brightness
-rw-r--r-- 1 root root 4096 Feb 27 09:54 bl_power
-rw-r--r-- 1 root root 4096 Feb 27 09:47 brightness
lrwxrwxrwx 1 root root    0 Feb 27 09:54 device -> ../../card0-LVDS-1
-r--r--r-- 1 root root 4096 Feb 27 09:43 max_brightness
drwxr-xr-x 2 root root    0 Feb 27 09:54 power
lrwxrwxrwx 1 root root    0 Feb 27 09:54 subsystem -> ../../../../../../../class/backlight
-r--r--r-- 1 root root 4096 Feb 27 09:43 type
-rw-r--r-- 1 root root 4096 Feb 27 09:42 uevent

uname -r
4.2.0-30-generic
scripts
  • 5 5 个回答
  • 7682 Views

5 个回答

  • Voted
  1. Best Answer
    Sergiy Kolodyazhnyy
    2016-03-08T09:24:35+08:002016-03-08T09:24:35+08:00

    实际上,我想让我的 Ubuntu 记住上次使用的亮度级别。我该怎么做?这里有一些信息:

    介绍

    下面的脚本解决了 OP 存储和恢复上次使用的屏幕亮度的需要。它与the lightdmgreeter 一起工作并由lightdm. 不需要使用lightdm,所以如果你更喜欢使用 cron 作业,你可以这样做。

    基本思路:

    1. 将脚本存储在某个地方(通过此处获取或通过 github 获取)
    2. /etc/lightdm/lightdm.conf使用sudo权限创建。
    3. 确保该文件有 3 行:[SeatDefaults]、display-setup-script和display-stopped script. 详情请看下文。脚本头也给出了概述。

    脚本源

    #!/usr/bin/env bash
    #
    ###########################################################
    # Author: Serg Kolo , contact: [email protected] 
    # Date: March 7th, 2016
    # Purpose: Script that will remember screen brightness
    #          Must be used in conjunction with lightdm
    #          Place the following 5 lines into /etc/lightdm/lightdm.conf
    #
    #           [SeatDefaults]
    #           #display-setup-script = Script to run when starting a greeter session (runs as root)
    #           display-setup-script = /home/USER/bin/sergrep/brightness.sh restore
    #           #display-stopped-script = Script to run after stopping the display server (runs as root)
    #           display-stopped-script = /home/USER/bin/sergrep/brightness.sh store
    #
    #           Basic idea is that you must give full path and either store or restore as an option 
    # Written for: http://askubuntu.com/q/739654/295286
    # Tested on:  Ubuntu 14.04 LTS
    # Version: 1.2 , added brightness limit, file creation
    ###########################################################
    # Copyright: Serg Kolo , 2016
    #    
    #     Permission to use, copy, modify, and distribute this software is hereby granted
    #     without fee, provided that  the copyright notice above and this permission statement
    #     appear in all copies.
    #
    #     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    #     IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    #     FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
    #     THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    #     LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    #     FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    #     DEALINGS IN THE SOFTWARE.
    ARGV0=$0
    ARGC=$#
    
    
    
    store()
    {
       cat "$SYSDIR"/*/actual_brightness > "$1"
    }
    #----------
    
    # This function restores brightness. We avoid 
    # setting brightness to complete 0, hence
    # minimum is 10% that can be restored.
    
    restore()
    {
      MAX=$(cat "$SYSDIR"/*/max_brightness  )
      LIMIT=$((MAX/10)) # get approx 10 percent value
      VAL=$(cat "$1" )
      if [ "$VAL" -lt "$LIMIT"  ] ;
      then
           # avoid going bellow 10% of brightness
           # we don't want user's screen to be completely dark
           echo "$LIMIT" > "$SYSDIR"/*/brightness
      else
           echo "$VAL" > "$SYSDIR"/*/brightness
      fi
    }
    #------------
    
    # This function works for initial run of the script; the script cannot set
    # brightness unless datafile exists first, so here we create the file
    # Initial value there will be whatever the current brightness on first
    # reboot was
    
    create_datafile()
    {
      cat "$SYSDIR"/*/actual_brightness > "$1" 
    }
    
    puke(){
        printf "%s\n" "$@" > /dev/stderr
        exit 1
    }
    
    main()
    {
      local DATAFILE="/opt/.last_brightness"
      local SYSDIR="/sys/class/backlight" # sysfs location of all the data
    
      # Check pre-conditions for running the script
      if [ "$ARGC" -ne 1  ];then
         puke "Script requires 1 argument"
      fi
    
      if [ $(id -u) -ne 0 ]   ; then
         puke "Script has to run as root"
      fi
    
      # ensure datafile exists
      [ -f "$DATAFILE"  ] || create_datafile "$DATAFILE"
    
      # perform storing or restoring function
      case "$1" in
         'restore') restore  $DATAFILE ;;
         'store') store $DATAFILE ;;
         *) puke "Unknown argument";;
      esac
    
    }
    
    main "$@"
    

    获取和设置脚本

    您可以直接复制脚本或从命令行执行这些步骤(要打开命令行,请按CtrlAltT )

    sudo apt-get install git
    cd /opt
    sudo git clone https://github.com/SergKolo/sergrep.git
    

    该脚本将位于 中/opt/sergrep/brightness.sh,因此我们执行以下操作:

    sudo chmod +x /opt/sergrep/brightness.sh
    

    使其可执行。接下来,我们需要将其设置为与 lightdm 一起使用。/etc/lightdm/lightdm.conf通过使用命令行nano文本编辑器(命令是sudo nano /etc/lightdm/lightdm.conf)或图形gedit(pkexec gedit /etc/lightdm/lightdm.conf)打开文件来创建文件

    将以下行写入该文件:

    [SeatDefaults]
    #display-setup-script = Script to run when starting a greeter session (runs as root)
    display-setup-script = /opt/sergrep/brightness.sh restore
    #display-stopped-script = Script to run after stopping the display server (runs as root)
    display-stopped-script = /opt/sergrep/brightness.sh store
    

    保存并退出

    深入概述

    您已经发现可以/sys/class/backlight/*/brightness直接写入文件,也可以读取这些值。问题是这/sys是一个虚拟文件系统,所以一旦你重新启动,该文件系统中的所有文件都会消失。

    因此,您可以/sys/class/backlight/*/actual_brightness在每次重新启动时将值存储到永久文件中。问题是如何 - 通过 cron 作业、通过 lightdm 或通过其他方式。就个人而言,我选择了这lightdm条路线。

    基本上,我们利用了 lightdm 的特性——能够在欢迎程序开始之前和会话退出之后运行脚本。/opt/.last_brightness每次脚本启动时,亮度都会记录到文件并读取。我们本质上是使用相同的脚本执行两个操作,只是通过传递不同的参数。

    • 6
  2. Jay T.
    2016-03-04T12:17:00+08:002016-03-04T12:17:00+08:00

    你有没有试过这个:

    1. sudo nano /etc/rc.local
    2. 将此行添加到文件中(将 X 替换为所需的亮度级别):

      echo X > /sys/class/backlight/intel_backlight/brightness
      
    • 1
  3. misha
    2016-03-05T05:46:57+08:002016-03-05T05:46:57+08:00

    好吧。我将回答我自己的问题,以供将来参考。就我而言,我所做的是在之前添加以下几行(实际上只是一行带有一堆评论来提醒我为什么以及我在那里做了什么/etc/rc.local)exit 0:

    # The following line should solve the problem of Ubuntu resetting
    # the brightness level back to maximum after every reboot.
    
    echo 50 > /sys/class/backlight/radeon_bl0/brightness
    

    这是整个文件现在的样子:

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    # The following line should solve the problem of Ubuntu resetting
    # the brightness level back to maximum after every reboot.
    echo 50 > /sys/class/backlight/radeon_bl0/brightness
    
    exit 0
    

    虽然我不能百分百确定这是否是最好的方法,但现在一切似乎对我来说都很好。

    • 0
  4. Rahul Mukherji
    2016-03-05T10:37:37+08:002016-03-05T10:37:37+08:00

    如果您能够使用命令设置亮度,那么在启动时将亮度级别更改为特定值很容易。请执行下列操作:

    • 按 Super/Windows 键打开 Dash
    • 输入“启动应用程序”并按回车
    • 点击“添加”
    • 输入名称(无关)和命令
    • 点击“添加”

    这应该在启动时执行该命令。我不确定如何让它记住以前的亮度,但我希望这会有所帮助。

    • 0
  5. Rohith Saradhy
    2017-06-16T13:23:50+08:002017-06-16T13:23:50+08:00

    只需使用光...否则修复它会很麻烦,特别是如果您将英特尔和 nvidia 显卡放在一起!

    这适用于 Ubuntu 16.04 ......并在 Alienware M14XR2 上进行了测试

    结帐-> https://github.com/haikarainen/light

    • 0

相关问题

  • 如何在 Nautilus 中管理保存的完整网页及其目录(例如 n.html 和 n_files)

  • 如何每 5 秒运行一次脚本?

  • 如何将必须从其自己的目录中运行的程序添加到面板或主菜单?

  • 如何编写 shell 脚本来安装应用程序列表?

  • Mac OS X Automator 的替代品?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve