Giter Site home page Giter Site logo

brightness_adjustment_fix's Introduction

Brightness Adjustment Fix for Linux (Mint)

Description

I am currently running Linux Mint 19.2 (Tina) on a Lenovo Thinkpad with a Ryzen 5 CPU and AMD Radeon Vega GPU. This particular system configuration seems to have issues with power management settings such as adjusting brightness or preventing turning off the display when idle, where all settings are ignored by the system.

There seem to be some fixes available online which mostly involve changing GRUB settings which appear to work for some users. Since the solution presented here is more of a quick fix/work around, you may want to try these first. However, neither of the proposed solutions has worked in my case, even after upgrading the kernel from the default 4.15 to 5.3.

Since I did not want to sink any more time in this issue I decided to adjust the brightness directly using the '/sys/class' interface in combination with a simple udev rule. This allows to adjust the brightness of the display, however, it does NOT prevent the system from turning off the display if idle for too long (which is not important to me).

Applying Fix

Check System

First get the device responsible for adjusting the brightness which is located at '/sys/class/backlight'

ls /sys/class/backlight/

On my system there are two entries 'amdgpu_bl0' and 'thinkpad_screen'. Both directories have an entry 'brightness' and 'max_brightness'. Calling cat on these files will give you their current values.
For example:

:~$ cat /sys/class/backlight/amdgpu_bl0/max_brightness

255

The value of brightness can be changed by echoing a value to the 'brightness' file. You might have to be root to be allowed to change the value (e.g. sudo su).
For example:

:~$ echo 30 > /sys/class/backlight/amdgpu_bl0/brightness

On my system only the 'amdgpu_bl0' seems to work whereas the entries at 'thinkpad_screen' result in-/output errors.

Change Device Permission

In order to change the brightness as non-root user, permissions of the device files have to be changed. A new group 'display' is created and all users who should have access to the brightness control are added to this group. The following example creates the group 'display' and adds the current user to it. Add more users as you see fit.

:~$ sudo groupadd display
:~$ usermod -a -G display $(whoami)

Reboot for the group setting to take effect.

Prepare Bash Script

Adjust the 'BACKLIGHT_LOC' path in the 'brightness_control' bash script contained in this repository to point to the device used for adjusting brightness on your machine (see Check System). Next, change the 'MIN' value to be less than what 'max_brightness' returned. 'RATE' may be changed to adjust the speed at which the brightness should be adjusted.

Check if you can increase the brightness with the following command:

:~$ bash brightness_control -up

and lower it with:

:~$ bash brightness_control

Copy 'brightness_control' to your preferred location (e.g. /usr/local/bin)

Note: If you have insufficient permissions to execute the script, try using the script as root user (e.g. sudo su). Alternatively change the group of the 'brightness' file and change permissions, assuming the current user is already a member of the group (see also Change Device Permission).
For example:

:~$ chgrp display /sys/class/backlight/amdgpu_bl0/brightness
:~$ chmod g+w /sys/class/backlight/amdgpu_bl0/brightness

Prepare UDEV Rule

Since the '/sys/class' devices are created during boot up, group and file permissions are not persistent. The '99-backlight.rules' udev rule of this repository automatically sets the correct group and file permissions when the device for controlling the backlight is added to the file system.

Confirm that the 'SUBSYSTEM' in '99-backlight.rules' matches the one of the display device. The subsystem of the device can be queried with the 'udevadm' command.
For example:

:~$ udevadm info --path=/sys/class/backlight/amdgpu_bl0

P: /devices/pci0000:00/0000:00:08.1/0000:05:00.0/backlight/amdgpu_bl0
E: DEVPATH=/devices/pci0000:00/0000:00:08.1/0000:05:00.0/backlight/amdgpu_bl0
E: ID_PATH=pci-0000:05:00.0
E: ID_PATH_TAG=pci-0000_05_00_0
E: SUBSYSTEM=backlight
E: SYSTEMD_WANTS=systemd-backlight@backlight:amdgpu_bl0.service
E: TAGS=:systemd:
E: USEC_INITIALIZED=3677164

Adjust the path of the display device in the 'PROGRAM' section of the '99-backlight.rules' udev script if necessary.

Copy '99-backlight.rules' to '/etc/udev/rules.d'.

Reboot in order for the udev rule to take effect.

Add Keybindings

In order to adjust the brightness using your keyboard, add keybindings to 'Control Center -> Keyboard Shortcuts'.
For example:

Name:		Brightness down
Command:	/bin/bash /usr/local/bin/brightness_control
Shortcut:	Ctrl + F5
Name:		Brightness up
Command:	/bin/bash /usr/local/bin/brightness_control -up
Shortcut:	Ctrl + F6

brightness_adjustment_fix's People

Contributors

alexzoe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.