From 7b68a1d0c626876afe2c572dff5683a0e5b23bc4 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Tue, 26 Dec 2017 23:52:11 +0100 Subject: [PATCH] Add volume script, update i3 volume hotkeys --- .config/i3/blocks | 18 +++++------- .config/i3/config | 19 +++++++----- .config/i3/scripts/brightness.sh | 26 +++++++---------- .config/i3/scripts/volume.sh | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 33 deletions(-) create mode 100755 .config/i3/scripts/volume.sh diff --git a/.config/i3/blocks b/.config/i3/blocks index 1fed681..7230e6e 100644 --- a/.config/i3/blocks +++ b/.config/i3/blocks @@ -30,21 +30,19 @@ markup=none # Volume indicator # -# The first parameter sets the step (and units to display) -# The second parameter overrides the mixer selection -# See the script for details. [volume] -#label=VOL -#label=♪ -label= +command=$HOME/.config/i3/scripts/volume.sh +markup=pango instance=Master -#instance=PCM -interval=1 -signal=10 +interval=once +signal=1 +# Brightness indicator +# [brightness] command=$HOME/.config/i3/scripts/brightness.sh -interval=1 +interval=once +signal=2 # Network interface monitoring # diff --git a/.config/i3/config b/.config/i3/config index 8a8ea18..a4a36b6 100644 --- a/.config/i3/config +++ b/.config/i3/config @@ -189,14 +189,17 @@ client.urgent $bg-color-urgent $bg-color-urgent $text-color #00FF00 # Keybindings bindsym $mod+Mod1+l exec $HOME/.config/i3/scripts/lock.sh -bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% # Increase sound volume; Pulse Audio -bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5% # Decrease sound volume -bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle # Mute sound -bindsym $mod+F3 exec xbacklight -inc 10 # Increase screen brightness -bindsym $mod+F2 exec xbacklight -dec 10 # Decrease screen brightness -bindsym --release Print exec scrot -e "mv \$f $HOME/Pictures/screen_captures/" # Fullscreen screenshot -bindsym --release Shift+Print exec scrot -s -e "mv \$f $HOME/Pictures/screen_captures/" # Selection screenshot -bindsym --release $mod+Print exec scrot -u -e "mv \$f $HOME/Pictures/screen_captures/" # Focused window screenshot +# Volume +bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -q -D pulse sset Master 5%+ unmute && pkill -RTMIN+1 i3blocks +bindsym XF86AudioLowerVolume exec --no-startup-id amixer -q -D pulse sset Master 5%- unmute && pkill -RTMIN+1 i3blocks +bindsym XF86AudioMute exec --no-startup-id amixer -q -D pulse sset Master toggle && pkill -RTMIN+1 i3blocks +# Screen brightness +bindsym $mod+F3 exec xbacklight -inc 10 && pkill -RTMIN+2 i3blocks +bindsym $mod+F2 exec xbacklight -dec 10 && pkill -RTMIN+2 i3blocks +# Screenshot +bindsym --release Print exec scrot -e "mv \$f $HOME/Pictures/screen_captures/" # Fullscreen +bindsym --release Shift+Print exec scrot -s -e "mv \$f $HOME/Pictures/screen_captures/" # Selection +bindsym --release $mod+Print exec scrot -u -e "mv \$f $HOME/Pictures/screen_captures/" # Focused window # Window appearance smart_gaps on diff --git a/.config/i3/scripts/brightness.sh b/.config/i3/scripts/brightness.sh index e0a9080..5ccc1ac 100755 --- a/.config/i3/scripts/brightness.sh +++ b/.config/i3/scripts/brightness.sh @@ -1,24 +1,20 @@ #!/bin/bash case $BLOCK_BUTTON in - # right click - 3) xbacklight -set 30;; - - # scroll up - 4) xbacklight -inc 10 ;; - - # scroll down - 5) xbacklight -dec 10 ;; + 3) xbacklight -set 30 ;; # right click + 4) xbacklight -inc 10 ;; # scroll up + 5) xbacklight -dec 10 ;; # scroll down esac -percentage=$(printf "%.0f" "$(xbacklight)") +PERCENTAGE=$(printf "%.0f" "$(xbacklight)") -if (( $percentage >= 75 )); then - icon="" -elif (( $percentage >= 25 )); then - icon="" +if (( $PERCENTAGE >= 75 )); then + ICON="" +elif (( $PERCENTAGE >= 25 )); then + ICON="" else - icon="" + ICON="" fi -echo $icon $percentage% +echo $ICON $PERCENTAGE% + diff --git a/.config/i3/scripts/volume.sh b/.config/i3/scripts/volume.sh new file mode 100755 index 0000000..9a63b55 --- /dev/null +++ b/.config/i3/scripts/volume.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# default (ALSA), pulse, jack +MIXER="pulse" +INSTANCE=${BLOCK_INSTANCE:-"Master"} +STEP="5%" + +case $BLOCK_BUTTON in + 1) pavucontrol ;; # left click, start sound settings + 2) amixer -q -D $MIXER sset $INSTANCE 0 unmute ;; # scroll click, set 0 + 3) amixer -q -D $MIXER sset $INSTANCE toggle ;; # right click, mute/unmute + 4) amixer -q -D $MIXER sset $INSTANCE ${STEP}+ unmute ;; # scroll up, increase + 5) amixer -q -D $MIXER sset $INSTANCE ${STEP}- unmute ;; # scroll down, decrease +esac + +INFO=$(amixer -D $MIXER get $INSTANCE) + +volume() { + VOLUME=$(echo $INFO | sed -nr 's/.*\[([0-9]*)%\].*/\1/p' | head -n 1) +} + +symbol() { + + if [ "$VOLUME" -ge "50" ]; then + SYMBOL="" + elif [ "$VOLUME" -ge "25" ]; then + SYMBOL="" + else + SYMBOL="" + fi +} + +setOutput() { + # If sound is not muted + if [ -n "$(echo $INFO | sed -nr 's/(\[on\])/\1/p')" ]; then + COLOR="#FFF" + volume + symbol + VOLUME="$VOLUME%" + else + COLOR="#676E7D" + VOLUME="MUTE" + SYMBOL="" + fi +} + +setOutput + +echo "$SYMBOL $VOLUME" +