Skip to content
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

Closed
wants to merge 5 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .config/sway/config.d/50-openSUSE.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Copy link
Collaborator

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.

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@mcepl mcepl Feb 5, 2024

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

Copy link
Contributor

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

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 )
Copy link
Collaborator

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 "


bindsym XF86AudioRaiseVolume exec pamixer --allow-boost -ui 2 && dc -e "[`pamixer --get-volume`]sM 100d `pamixer --get-volume`<Mp" > $SWAYSOCK.wob
bindsym XF86AudioLowerVolume exec pamixer --allow-boost -ud 2 && dc -e "[`pamixer --get-volume`]sM 100d `pamixer --get-volume`<Mp" > $SWAYSOCK.wob
Expand Down