How to make the screen brightness keys work again in KDE
How to make button for screen brightness work on your laptop in KDE
When I started using a newer kernel in openSUSE 13.2, I noticed the buttons for screen brightness were no longer functioning on my laptop. This is verry annoying, so I decided to do something about it. I am using KDE. I will try to write the instructions as generic as possible, so that it will hopefully work in your situation too. This is a HP ELitebook 8570p.
First, we have to find the screen device, which is located somewhere in the /sys/devices/pci0000:00 directory.
Somewhere in this directory is a file located with the name 'brightness'. Let's find it. So, as root:
# find /sys/devices/pci0000:00 -name "brightness" /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness /sys/devices/pci0000:00/0000:00:1c.2/0000:24:00.1/leds/mmc0::/brightness /sys/devices/pci0000:00/0000:00:1c.3/0000:25:00.0/leds/phy0-led/brightness
Remember, your output is probably different from what I got here.
I have a radeon card, so the first line contains the device we will be working with.
When you read the content of the 'file', you get the current brightness level:
# cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness 235
The value lies somewhere between 0 and 255, it's a one byte value.
You can test if this work for you by writing (still as root) a different value to that file: (remember to substitute the file for your graphics card)
# echo 200 > /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness
If this works, you should see the brightness change, and you can go to the next step.
edit: for samsung rv720: "echo 8 > /sys/class/backlight/samsung/brightness" to restore the brightness. edit2: newer kernel uses this: echo 100 > /sys/class/backlight/nv_backlight/brightness
I created a simple QAD(quick and Dirty) 3 line script to read that value and increase it.
I put the script in my home user's bin directory:
user> vi ~/bin/brp
br=$(cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness) br=$((br+10)) echo $br > /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness
I called it 'brp' which is nice and short and stands for 'brightness plus' Note that I increase the value by 10 otherwise it would not change enough. You can vary that value of course to get finer control or get faster adjustment.
I created a similar script called brm which decreases the value:
user> vi ~/bin/brm
And paste the content
br=$(cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness) br=$((br-10)) echo $br > /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness
# chmod +x brm brp
Now, the problem is that this file /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness may only be written by root. Notice that all commands manipulating the file so far have been executed as root. But you should have created the 2 script files brp and brm as your normal user account.
To make the file world writeable:
# chmod 777 /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness
This will make the 2 scripts which are executed as your useraccount able to write to this file.
Then, lastly, redefine the keys on your laptop for screen brightness to point to your script:
- go to KDE - configure desktop
- shortcuts and gestures
- custom shortcuts
- edit - new - global shortcut - command/URL
- name: br-down
- tab trigger: Shortcut - click on 'None'
- press the brightness down key on your keyboard. It should appear in the button.
- tab action: browse and point to your brm file
- click apply
Repeat this for the brightness up script file, so you end up with 2 shortcuts.
And that's it. This should work. Happy screening!
Oh, and after a reboot, the chmod 777 of the brightness file is needed again. So I did a dirty hack and added this to my crontab:
*/3 * * * * root chmod 777 /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/drm/card0/card0-LVDS-1/radeon_bl0/brightness