-
Notifications
You must be signed in to change notification settings - Fork 19
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
make brightness control via hotkeys exponential #113
Conversation
As brightness is perceived exponentially, it is more intuitive to make the brightness change exponentially as well.
the previous brightness calculation did not round to the nearest integer, this perl script does now do that
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.
Otherwise doesn't work for me:
May 22 11:52:37 stdlen sway[4702]: Execution of -e aborted due to compilation errors.
May 22 11:52:37 stdlen sway[4702]: syntax error at -e line 1, near "%.0"
May 22 11:52:37 stdlen sway[4702]: (Missing operator before f?)
May 22 11:52:37 stdlen sway[4702]: Bareword found where operator expected at -e line 1, near "0f"
May 22 11:52:37 stdlen sway[4702]: (Missing operator before 0?)
May 22 11:52:37 stdlen sway[4702]: Number found where operator expected at -e line 1, near "%.0"
@nova-r could you please check suggestions? |
Co-authored-by: Denys Kondratenko <[email protected]>
@FilippoBonazziSUSE could you please check this one. When I checked it last time, it didn't work for me. |
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.
The commands work for me (with the necessary '
to "
fix) in the sense that they succeed in changing brightness.
However, there are 3 things that I would like to see changed:
- The use of the Perl interpreter is not ideal, and I'd like to avoid it if at all possible. Any extra dependency must be carefully considered
- The brightness up and down commands are not symmetrical, i.e. increments on the way up are different from decrements on the way down. This makes brightness values not reproducible and arbitrary looking. For example, starting from 20%, going up to 100% takes N increments, but going back down N decrements arrives at 19%. This needs to be fixed before this can be merged.
- There is no progress on the discussion we had in make brightness control exponential #112 , and I'd like to see those points addressed too
bindsym XF86MonBrightnessDown exec brightnessctl -q set 5%- && ( echo $((`brightnessctl get` * 100 / `brightnessctl m`)) > $SWAYSOCK.wob ) | ||
bindsym XF86MonBrightnessUp exec brightnessctl -q set +5% && ( echo $((`brightnessctl get` * 100 / `brightnessctl m`)) > $SWAYSOCK.wob ) | ||
bindsym XF86MonBrightnessDown exec brightnessctl -q -e set 5%- && ( perl -e "use Math::Complex; printf \"%.0f\n\", 100 * ((`brightnessctl get` / `brightnessctl m`)**0.25)" > $SWAYSOCK.wob ) | ||
bindsym XF86MonBrightnessUp exec brightnessctl -q -e set +5% && ( perl -e 'use Math::Complex; printf \"%.0f\n\", 100 * ((`brightnessctl get` / `brightnessctl m`)**0.25)' > $SWAYSOCK.wob ) |
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.
Also here the '
string delimiter needs to be changed to "
@denisok This feature will take a bit more time, let's not wait for this for 0.16.0 |
@@ -37,8 +37,8 @@ bindsym --to-code { | |||
# Media keys | |||
bindsym XF86AudioMicMute exec pactl set-source-mute @DEFAULT_SOURCE@ toggle | |||
|
|||
bindsym XF86MonBrightnessDown exec brightnessctl -q set 5%- && ( echo $((`brightnessctl get` * 100 / `brightnessctl m`)) > $SWAYSOCK.wob ) | |||
bindsym XF86MonBrightnessUp exec brightnessctl -q set +5% && ( echo $((`brightnessctl get` * 100 / `brightnessctl m`)) > $SWAYSOCK.wob ) | |||
bindsym XF86MonBrightnessDown exec brightnessctl -q -e set 5%- && ( perl -e "use Math::Complex; printf \"%.0f\n\", 100 * ((`brightnessctl get` / `brightnessctl m`)**0.25)" > $SWAYSOCK.wob ) |
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.
Pulling in yet another programming language (Perl) is not a good idea. Look at #126 as well.
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.
Can we simply use awk for this task?
Consider the following, formatted across multiple lines for clarity:
brightness=$(brightnessctl get)
max_brightness=$(brightnessctl m)
percentage=$(awk -v br="$brightness" -v max="$max_brightness" 'BEGIN {printf "%.0f\n", 100 * ((br / max) ^ 0.25)}')
echo $percentage > $SWAYSOCK.wob
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.
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.
We could use just bc:
mitmanek~$ echo "scale=2 ; 100 * e(l("$(brightnessctl get)" / "$(brightnessctl m)") * 0.25)"|bc -l
78.00
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.
That's an additional dependency though
fixes #112
As brightness is perceived exponentially, it is more intuitive to make the brightness change exponentially as well.