brightnessctl icon indicating copy to clipboard operation
brightnessctl copied to clipboard

Graduated transition when setting brightness

Open akiva opened this issue 6 years ago • 6 comments

Would it be possible to implement an option to transition the fade when setting, ie. brightnessctl set 5%-, so that it's more aesthetically pleasing and feels less clunky as it steps up or down?

akiva avatar Nov 26 '18 22:11 akiva

Sure! It's an awesome idea. I'll definitely merge a PR.

If you're up to it, I'd be glad to discuss the implementation with you.

Hummer12007 avatar Nov 26 '18 23:11 Hummer12007

I would be happy to try and help with this—it would be my first c-based PR. Would you care to provide any implementation tips here or in e-mail? Cheers!

akiva avatar Dec 17 '18 23:12 akiva

Great! You will roughly need to do the following:

  • Add an option for transition duration (0 by default)
  • An example of a way to implement smooth transition would be: when the transition duration is non-zero, you can split the duration into equal chunks (|d->curr_brightness - new| chunks to be precise, https://github.com/Hummer12007/brightnessctl/blob/master/brightnessctl.c#L325) , and increment/decrement the brightness, writing the new value on each chunk.

I'd also like you to consider what would happen if a user executes multiple instances of smooth transition concurrently, and how/whether we'd need to handle that.

Hummer12007 avatar Dec 17 '18 23:12 Hummer12007

FWIW my project brillo implements this feature. Most of the functionality to enable it is concentrated in this file (note: this is 0BSD now).

Some tips from my experience:

  • You need to decide on a sleep interval at which to write to the brightness file, and if it is too rapid udevd will eat up a lot of resources. I used 100 writes per second; you may not need this many.
  • You will need to write at each interval, then flush the write data (if applicable), then sleep the remaining time in the interval.
  • You will need to check the clock before and after each write. The write may take some time, so you will need to subtract the difference from the sleep interval duration.

Best of luck!

CameronNemo avatar Dec 29 '18 20:12 CameronNemo

This would be a really nice feature. Unfortunately my C skills are very limited, so I can not provide a PR. However, I wrote this short BASH script that does the job:

I=0
while [ $I -lt 10 ]; do
    brightnessctl -c backlight -q s 2%-
    sleep 0.05
    ((I = I + 1));
done

Adjust the values to fit your needs.

dirdi avatar Feb 01 '20 20:02 dirdi

There's some work-in-progress code in the anim branch, I think there are a few concurrency left to be resolved.

Hummer12007 avatar Feb 02 '20 13:02 Hummer12007