Browse Source

Setup volume i3block (#56)

red-hat-laptop
Kevin Mok 6 years ago
parent
commit
564575ee5d
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 2
      aliases/zsh_aliases
  2. 14
      configs/i3/config
  3. 272
      configs/i3blocks-scripts/volume
  4. 12
      configs/i3blocks/i3blocks.conf
  5. 4
      configs/sam-i3blocks/sam-i3blocks.conf
  6. 1
      txt/key_dirs.txt
  7. 14
      txt/pacman-pkgs/nzxt-pkgs.txt

2
aliases/zsh_aliases

@ -204,7 +204,7 @@ alias psi="pass insert -m"
alias psg="pass generate -c"
alias yh="echo 'kevin.mok@live.ca' | xclip -selection clipboard"
alias yg="xclip -selection clipboard ~/.password-store/social/gmail"
alias yu="echo 'kevin.mok@mai.utoronto.ca' | xclip -selection clipboard"
alias yu="echo 'kevin.mok@mail.utoronto.ca' | xclip -selection clipboard"
# python related {{{ #
function grpy() { grep $1 *.py ; }

14
configs/i3/config

@ -3,8 +3,8 @@ set $browser "chromium"
set $def_term "urxvt"
# set $runelite "java -jar ~/Downloads/RuneLite.jar"
set $swex "sudo ~/Downloads/swex.appimage"
# exec redshift -O 2000
exec redshift -O 3000
exec redshift -O 2000
# exec redshift -O 3000
# random bg
exec compton
exec wal -i "$HOME/Pictures/Backgrounds/dim"
@ -327,7 +327,7 @@ bindsym $mod+control+l resize shrink width 3 px or 3 ppt
# remove window titlebars
for_window [class="^.*"] border pixel 3
# for_window [class="^.*"] border pixel 1
set $inner_gaps 35
set $inner_gaps 40
set $outer_gaps 0
gaps inner $inner_gaps
@ -471,11 +471,9 @@ bindsym control+d exec ~/linux-config/scripts/change-sink dac
bindsym control+shift+d exec ~/linux-config/scripts/change-sink dac2
bindsym control+o exec ~/linux-config/scripts/change-sink line-out
bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -c 0 sset Master 3+
bindsym XF86AudioLowerVolume exec --no-startup-id amixer -c 0 sset Master 3-
bindsym control+$mod+plus exec --no-startup-id amixer -c 2 sset PCM 3+
bindsym control+$mod+minus exec --no-startup-id amixer -c 2 sset PCM 3-
bindsym XF86AudioMute exec --no-startup-id amixer -D pulse set Master 0+ toggle
bindsym XF86AudioRaiseVolume exec amixer -q -D pulse sset Master 5%+ && pkill -RTMIN+1 i3blocks
bindsym XF86AudioLowerVolume exec amixer -q -D pulse sset Master 5%- && pkill -RTMIN+1 i3blocks
bindsym XF86AudioMute exec amixer -q -D pulse sset Master toggle && pkill -RTMIN+1 i3blocks
# Media player controls
bindsym XF86AudioPlay exec "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"

272
configs/i3blocks-scripts/volume

@ -1,70 +1,220 @@
#!/bin/bash
# Copyright (C) 2014 Julien Bonjean <julien@bonjean.info>
# Copyright (C) 2014 Alexander Keller <github@nycroth.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#------------------------------------------------------------------------
# The second parameter overrides the mixer selection
# For PulseAudio users, use "pulse"
# For Jack/Jack2 users, use "jackplug"
# For ALSA users, you may use "default" for your primary card
# or you may use hw:# where # is the number of the card desired
MIXER="default"
[ -n "$(lsmod | grep pulse)" ] && MIXER="pulse"
[ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
MIXER="${2:-$MIXER}"
# The instance option sets the control to report and configure
# This defaults to the first control of your selected mixer
# For a list of the available, use `amixer -D $Your_Mixer scontrols`
SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
sed -n "s/Simple mixer control '\([A-Za-z ]*\)',0/\1/p" |
head -n1
)}"
# The first parameter sets the step to change the volume by (and units to display)
# This may be in in % or dB (eg. 5% or 3dB)
STEP="${1:-5%}"
#------------------------------------------------------------------------
capability() { # Return "Capture" if the device is a capture device
amixer -D $MIXER get $SCONTROL |
sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
}
# Displays the default device, volume, and mute status for i3blocks
# default vars {{{ #
set -a
SINK_SYMB=""
AUDIO_HIGH_SYMBOL=${AUDIO_HIGH_SYMBOL:-''}
AUDIO_MED_THRESH=${AUDIO_MED_THRESH:-50}
AUDIO_MED_SYMBOL=${AUDIO_MED_SYMBOL:-''}
AUDIO_LOW_THRESH=${AUDIO_LOW_THRESH:-0}
AUDIO_LOW_SYMBOL=${AUDIO_LOW_SYMBOL:-''}
AUDIO_MUTED_SYMBOL=${AUDIO_MUTED_SYMBOL:-''}
AUDIO_DELTA=${AUDIO_DELTA:-5}
. "/home/kevin/.cache/wal/colors.sh"
# DEFAULT_COLOR=${DEFAULT_COLOR:-"#ffffff"}
DEFAULT_COLOR="$color7"
MUTED_COLOR=${MUTED_COLOR:-"#a0a0a0"}
USE_ALSA_NAME=${USE_ALSA_NAME:-0}
USE_DESCRIPTION=${USE_DESCRIPTION:-0}
SUBSCRIBE=${SUBSCRIBE:-0}
MIXER=${MIXER:-""}
SCONTROL=${SCONTROL:-""}
# }}} default vars #
# LONG_FORMAT=${LONG_FORMAT:-'${SYMB} ${VOL}% [${INDEX}:${NAME}]'}
LONG_FORMAT=${SHORT_FORMAT:-'${SINK_SYMB} ${VOL}%'}
# SHORT_FORMAT=${SHORT_FORMAT:-'${SYMB} ${VOL}%[${INDEX}]'}
SHORT_FORMAT=${SHORT_FORMAT:-'${SINK_SYMB} ${VOL}%[${INDEX}]'}
# flags {{{ #
while getopts F:Sf:adH:M:L:X:T:t:C:c:i:m:s:h opt; do
case "$opt" in
S) SUBSCRIBE=1 ;;
F) LONG_FORMAT="$OPTARG" ;;
f) SHORT_FORMAT="$OPTARG" ;;
a) USE_ALSA_NAME=1 ;;
d) USE_DESCRIPTION=1 ;;
H) AUDIO_HIGH_SYMBOL="$OPTARG" ;;
M) AUDIO_MED_SYMBOL="$OPTARG" ;;
L) AUDIO_LOW_SYMBOL="$OPTARG" ;;
X) AUDIO_MUTED_SYMBOL="$OPTARG" ;;
T) AUDIO_MED_THRESH="$OPTARG" ;;
t) AUDIO_LOW_THRESH="$OPTARG" ;;
C) DEFAULT_COLOR="$OPTARG" ;;
c) MUTED_COLOR="$OPTARG" ;;
i) AUDIO_INTERVAL="$OPTARG" ;;
m) MIXER="$OPTARG" ;;
s) SCONTROL="$OPTARG" ;;
h) printf \
"Usage: volume-pulseaudio [-S] [-F format] [-f format] [-p] [-a|-d] [-H symb] [-M symb]
[-L symb] [-X symb] [-T thresh] [-t thresh] [-C color] [-c color] [-i inter]
[-m mixer] [-s scontrol] [-h]
Options:
-F, -f\tOutput format (-F long format, -f short format) to use, with exposed variables:
\${SYMB}, \${VOL}, \${INDEX}, \${NAME}
-S\tSubscribe to volume events (requires persistent block, always uses long format)
-a\tUse ALSA name if possible
-d\tUse device description instead of name if possible
-H\tSymbol to use when audio level is high. Default: '$AUDIO_HIGH_SYMBOL'
-M\tSymbol to use when audio level is medium. Default: '$AUDIO_MED_SYMBOL'
-L\tSymbol to use when audio level is low. Default: '$AUDIO_LOW_SYMBOL'
-X\tSymbol to use when audio is muted. Default: '$AUDIO_MUTED_SYMBOL'
-T\tThreshold for medium audio level. Default: $AUDIO_MED_THRESH
-t\tThreshold for low audio level. Default: $AUDIO_LOW_THRESH
-C\tColor for non-muted audio. Default: $DEFAULT_COLOR
-c\tColor for muted audio. Default: $MUTED_COLOR
-i\tInterval size of volume increase/decrease. Default: $AUDIO_DELTA
-m\tUse the given mixer.
-s\tUse the given scontrol.
-h\tShow this help text
" && exit 0;;
esac
done
# }}} flags #
# functions {{{ #
volume() {
amixer -D $MIXER get $SCONTROL $(capability)
if [[ -z "$MIXER" ]] ; then
MIXER="default"
if amixer -D pulse info >/dev/null 2>&1 ; then
MIXER="pulse"
fi
fi
if [[ -z "$SCONTROL" ]] ; then
SCONTROL=$(amixer -D "$MIXER" scontrols | sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | head -n1)
fi
CAPABILITY=$(amixer -D $MIXER get $SCONTROL | sed -n "s/ Capabilities:.*cvolume.*/Capture/p")
function move_sinks_to_new_default {
DEFAULT_SINK=$1
pacmd list-sink-inputs | grep index: | grep -o '[0-9]\+' | while read SINK
do
pacmd move-sink-input $SINK $DEFAULT_SINK
done
}
format() {
perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
# If dB was selected, print that instead
perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
perl_filter+='"; exit}'
perl -ne "$perl_filter"
function set_default_playback_device_next {
inc=${1:-1}
num_devices=$(pacmd list-sinks | grep -c index:)
sink_arr=($(pacmd list-sinks | grep index: | grep -o '[0-9]\+'))
default_sink_index=$(( $(pacmd list-sinks | grep index: | grep -no '*' | grep -o '^[0-9]\+') - 1 ))
default_sink_index=$(( ($default_sink_index + $num_devices + $inc) % $num_devices ))
default_sink=${sink_arr[$default_sink_index]}
pacmd set-default-sink $default_sink
move_sinks_to_new_default $default_sink
}
#------------------------------------------------------------------------
# }}} functions #
# triggers {{{ #
case $BLOCK_BUTTON in
3) amixer -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
4) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
5) amixer -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
case "$BLOCK_BUTTON" in
1) set_default_playback_device_next ;;
2) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY toggle ;;
3) set_default_playback_device_next -1 ;;
4) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_DELTA%+ ;;
5) amixer -q -D $MIXER sset $SCONTROL $CAPABILITY $AUDIO_DELTA%- ;;
esac
volume | format
# }}} triggers #
# print_format {{{ #
function print_format {
# echo $NAME
case $NAME in
*"FiiO"*)
SINK_SYMB=""
;;
*"hdmi"*)
SINK_SYMB=""
;;
*"pci"*)
SINK_SYMB=""
;;
esac
# echo "$1" | envsubst '${SYMB}${VOL}${INDEX}${NAME}'
echo "$1" | envsubst '${SINK_SYMB}${VOL}${INDEX}${NAME}'
}
# }}} print_format #
# print_block {{{ #
function print_block {
for name in INDEX NAME VOL MUTED; do
read $name
done < <(pacmd list-sinks | grep "index:\|name:\|volume: front\|muted:" | grep -A3 '*')
INDEX=$(echo "$INDEX" | grep -o '[0-9]\+')
VOL=$(echo "$VOL" | grep -o "[0-9]*%" | head -1 )
VOL="${VOL%?}"
NAME=$(echo "$NAME")
# NAME=$(echo "$NAME" | sed \
# 's/.*<.*\.\(.*\)>.*/\1/; t;'\
# 's/.*<\(.*\)>.*/\1/; t;'\
# 's/.*/unknown/')
# NAME=$(echo "$NAME" | sed \
# 's/.*<.*\.\(.*\)\..*>.*/\1/; t;')
if [[ $USE_ALSA_NAME == 1 ]] ; then
ALSA_NAME=$(pacmd list-sinks |\
awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\
grep "alsa.name\|alsa.mixer_name" |\
head -n1 |\
sed 's/.*= "\(.*\)".*/\1/')
NAME=${ALSA_NAME:-$NAME}
elif [[ $USE_DESCRIPTION == 1 ]] ; then
DESCRIPTION=$(pacmd list-sinks |\
awk '/^\s*\*/{f=1}/^\s*index:/{f=0}f' |\
grep "device.description" |\
head -n1 |\
sed 's/.*= "\(.*\)".*/\1/')
NAME=${DESCRIPTION:-$NAME}
fi
if [[ $MUTED =~ "no" ]] ; then
SYMB=$AUDIO_HIGH_SYMBOL
[[ $VOL -le $AUDIO_MED_THRESH ]] && SYMB=$AUDIO_MED_SYMBOL
[[ $VOL -le $AUDIO_LOW_THRESH ]] && SYMB=$AUDIO_LOW_SYMBOL
COLOR=$DEFAULT_COLOR
else
SYMB=$AUDIO_MUTED_SYMBOL
COLOR=$MUTED_COLOR
fi
if [[ $SUBSCRIBE == 1 ]] ; then
print_format "$LONG_FORMAT"
else
print_format "$LONG_FORMAT"
print_format "$SHORT_FORMAT"
echo "$COLOR"
fi
}
# }}} print_block #
print_block
if [[ $SUBSCRIBE == 1 ]] ; then
while read -r EVENT; do
print_block
done < <(pactl subscribe | stdbuf -oL grep change)
fi

12
configs/i3blocks/i3blocks.conf

@ -52,18 +52,6 @@ label=
interval=30
# unused blocks {{{ #
# 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=♪
# instance=Master
# #instance=PCM
# interval=once
# signal=10
# [memory]
# label=SWAP

4
configs/sam-i3blocks/sam-i3blocks.conf

@ -20,6 +20,10 @@ label=
# color=#2d7272
interval=10
[volume]
interval=once
signal=1
[time_short]
# label=🕓
# command=echo "$(date '+%H:%M')"

1
txt/key_dirs.txt

@ -33,5 +33,6 @@ wo /home/kevin/Documents/workout-logs/11
sc /home/kevin/school
st /home/kevin/school/sta
2 /home/kevin/school/236
lt /home/kevin/school/latex-notes
# }}} sch *

14
txt/pacman-pkgs/nzxt-pkgs.txt

@ -5,9 +5,11 @@ bash
bc
bison
broadcom-wl
browserpass
bzip2
chromium
chromium-widevine
cliqz
cloc
cmake
cmatrix
@ -22,7 +24,9 @@ diffutils
discord
dmenu
e2fsprogs
electrum
evince
evolution
fakeroot
feh
file
@ -69,6 +73,7 @@ man-pages
mdadm
nano
neofetch
neomutt
neovim
netctl
noto-fonts
@ -82,8 +87,10 @@ pciutils
pcmanfm
pdfgrep
perl
pgadmin4
pipes.sh
pkgconf
postgresql
procps-ng
psmisc
pulseaudio
@ -102,7 +109,9 @@ sed
shadow
shellcheck
spotify
spotify-now-git
st
steam
sudo
sysfsutils
sysstat
@ -122,6 +131,9 @@ texlive-local-tkz-base
texlive-local-tkz-euclide
texlive-localmanager-git
the_silver_searcher
tor
tor-browser
transmission-gtk
trizen
ttf-dejavu
ttf-emojione
@ -133,7 +145,9 @@ vi
w3m
which
wireless_tools
wpa_actiond
wpa_supplicant
xboxdrv
xclip
xf86-input-evdev
xf86-input-keyboard

Loading…
Cancel
Save