-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support fractional values #127
base: master
Are you sure you want to change the base?
Conversation
@@ -325,10 +328,9 @@ bool parse_value(struct value *val, char *str) { | |||
val->d_type = DELTA; | |||
str++; | |||
} | |||
n = strtol(str, &buf, 10); | |||
n = strtod(str, &buf); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: I would either convert all the float handling to double
or use strtof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I conciously made it double, in case some display maker decides that their brightness scale goes to higher than 16.777.216 (it's 15360 on my laptop, which freaked me out when I noticed it first)
brightnessctl.1
Outdated
@@ -96,6 +96,12 @@ Specify device class. | |||
Print version and exit. | |||
.RE | |||
|
|||
.sp | |||
\fB\-V, \-\-frac\fP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the -V
part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
char *format = p.mach ? "%s,%s,%d,%.4g%%,%d\n" : | ||
"Device '%s' of class '%s':\n\tCurrent brightness: %d (%.4g%%)\n\tMax brightness: %d\n\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at #51 (comment) wouldn't the --frac
incompatible with the -m
option ? should this be documented or handled in some way ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, I checked, we don't setlocale, so it always uses the dot
Can you elaborate, @Hummer12007? #118 is not fixed by this. I don't mean to come off as dismissive here, but are fractional percentages actually useful? It feels like more trouble than it's worth. At least on my system, a +/-1% change is already almost imperceptible. With such a low max brightness, setting a fractional brightness isn't accurate anyway. If precision is truly what a user needs, setting the brightness in device units is always going to be as precise and accurate as possible. $ ./brightnessctl -m --frac s 50%
amdgpu_bl1,backlight,128,50.2%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,154,60.39%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,129,50.59%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,155,60.78%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,130,50.98%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,156,61.18%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,131,51.37%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,157,61.57%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,132,51.76%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,158,61.96%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,133,52.16%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,159,62.35%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,134,52.55%,255
$ ./brightnessctl -m --frac s 10%+
amdgpu_bl1,backlight,160,62.75%,255
$ ./brightnessctl -m --frac s 10%-
amdgpu_bl1,backlight,135,52.94%,255 |
I don't really remember tbh, but 7b607b3 fixed a bug, and was more correct than the previous behavior. Most likely in the case with an exponent set. Something along the following lines may fix your use case: |
@andeston does this work for you? |
@Hummer12007 a5a9a95 didn't work. Does #128 work for you? |
Supersedes #51
Fixes #50
first one adds parsing fractional percentages, unconditionally, and alters the calculations to account for it
second one adds
--frac
to print percentages as floats. I'm not sure if it warrants a short option (-f and -F may be useful for other stuff).I'll sit on it for some time and think about it.
If anyone is interested @bbarenblat @Atemu, please test it (there might be some regressions in calculations).