liblxqt icon indicating copy to clipboard operation
liblxqt copied to clipboard

lxqt-backlight: Discrepancy in reading and writing of brightness

Open hch12907 opened this issue 5 years ago • 6 comments

lxqt-backlight gets the brightness value from /sys/class/backlight/*/actual_brightness instead of /sys/class/backlight/*/brightness and then proceeds to write the processed actual_brightness into brightness. (Not like you have the permission to write into actual_brightness anyway...)

This is fine actually, but amdgpu_bl0 returns the raw brightness value (0-65536) for actual_brightness while brightness accepts only values between zero to max_brightness which is 255. When lxqt-backlight writes the processed actual_brightness to brightness, the brightness gets ramped up to 100% as the processed raw values are often in the range of 10000 to 20000, which get clamped to 255 when written to brightness.

Interestingly, this behaviour is not observed when one sets a brightness value directly - it only occurs when one increases or decreases the brightness through lxqt-config-brightness -i/-d. lxqt-config-brightness -s 20 and pkexec lxqt-backlight_backend 20 % does what one would expect: setting the brightness value to 20% of the maximum. This is because both of them do level / 100 * max_brightness instead of actual_brightness and hence is not affected by the bug.

Expected Behavior

The brightness value should be obtained from /sys/class/backlight/*/brightness.

Current Behavior

The brightness value is obtained from /sys/class/backlight/*/actual_brightness.

Possible Solution

For raw drivers, read from brightness instead of actual_brightness. I'm not sure about the other driver types.

Steps to Reproduce (for bugs)

1. Have a laptop with an integrated AMD GPU. Raven Ridge (Vega 7) in my case. 2a. Attempt to increase/decrease the brightness value, and blind your eyes. (lxqt-config-brightness) 2b. Attempt to increase/decrease the brightness value, and nothing happens. (lxqt-backlight_backend) (lxqt-backlight_backend includes a check for value < max_value before writing to brightness)

System Information
  • Distribution & Version: Arch Linux (rolling)
  • Kernel: 5.7.8
  • Qt Version: 5.15.0-4
  • libqtxdg Version: 3.5.0
  • lxqt-build-tools Version: N/A
  • liblxqt version: 0.15.1-1

hch12907 avatar Jul 18 '20 08:07 hch12907

Thank you for raising this issue and authoring a PR for a fix. I hope it can be merged. I am running a HP Victus 16 with Ryzen 5600H / Radeon 5500M with Debian 12 / LXQT and wondered why even at max brightness the screen was quite dim. Testing lxqt-config-brightness -s 100 and lxqt-backlight_backend 100 % instead of the increment and decrement flags showed me that it can actually get very bright.

porschemad911 avatar Mar 22 '25 14:03 porschemad911

I can't reproduce this, as both /sys/class/backlight/amdgpu_bl1/actual_brightness and /sys/class/backlight/amdgpu_bl1/brightness have always the same value here with Picasso/Raven 2 [Radeon Vega Series / Radeon Mobile Series] and amdgpu.

Will test the patch though.

stefonarch avatar Mar 22 '25 14:03 stefonarch

I will double-check the sysfs values on my Victus.

porschemad911 avatar Mar 22 '25 22:03 porschemad911

They are different for me on Cezanne / Raven Ridge, with firmware-amd-graphics/stable-backports,stable-backports,now 20241210-1~bpo12+1 all [installed]

$ pkexec lxqt-backlight_backend 10 %
$ cat /sys/class/backlight/amdgpu_bl1/brightness /sys/class/backlight/amdgpu_bl1/actual_brightness
25
14

$ pkexec lxqt-backlight_backend 20 %
$ cat /sys/class/backlight/amdgpu_bl1/brightness /sys/class/backlight/amdgpu_bl1/actual_brightness
51
37

$ pkexec lxqt-backlight_backend 30 %
$ cat /sys/class/backlight/amdgpu_bl1/brightness /sys/class/backlight/amdgpu_bl1/actual_brightness
76
52

$ pkexec lxqt-backlight_backend 40 %
$ cat /sys/class/backlight/amdgpu_bl1/brightness /sys/class/backlight/amdgpu_bl1/actual_brightness
102
72

porschemad911 avatar Mar 23 '25 04:03 porschemad911

I am using this script as a workaround for now:

#!/bin/bash

increment=5
backlight=($(lxqt-backlight_backend --show))
max=${backlight[1]}
current=${backlight[2]}
current_percentage=$(( $current * 100 / $max ))
current_percentage_mod_increment=$(( $current_percentage % $increment ))
[ $current_percentage_mod_increment -gt 0 ] && current_percentage=$(( $current_percentage + ( $increment - $current_percentage_mod_increment ) ))

case $1 in
	"show")
		echo "current_percentage=${current_percentage}"		
		;;
	"up")
		new_percentage=$(( $current_percentage + $increment ))
		[ $new_percentage -gt 100 ] && new_percentage=100
		pkexec lxqt-backlight_backend $new_percentage %
		;;	
	"down")
		new_percentage=$(( $current_percentage - $increment ))
		[ $new_percentage -lt 0 ] && new_percentage=0
		pkexec lxqt-backlight_backend $new_percentage %
		;;
	*)
		echo "error - usage is brightness <up / down / show>"
		;;
esac

porschemad911 avatar Mar 26 '25 22:03 porschemad911

The patch works fine here, but we would need more tests on different hardware.

stefonarch avatar Mar 27 '25 06:03 stefonarch