Created
December 14, 2019 12:53
-
-
Save debxp/42a0badcec2069beec7f72c3a7a32386 to your computer and use it in GitHub Desktop.
Minhas modificações no módulo original
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright (C) 2014 Julien Bonjean <[email protected]> | |
# Copyright (C) 2014 Alexander Keller <[email protected]> | |
# 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" | |
} | |
volume() { | |
amixer -D $MIXER get $SCONTROL $(capability) | |
} | |
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" | |
} | |
#------------------------------------------------------------------------ | |
case $BLOCK_BUTTON in | |
1) pavucontrol ;; | |
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 | |
esac | |
#------------------------------------------------------------------------ | |
pv="$(volume | format)" | |
nv="${pv::-1}" | |
mute_color="#BF616A" | |
head_icon="" | |
# Testa se o headphone está plugado e define os ícones ------------------ | |
pacmd list-sinks | egrep 'headphones.*available: yes' &> /dev/null | |
[[ $? -eq 0 ]] && { | |
mute_icon=$head_icon | |
smin_icon=$head_icon | |
smax_icon=$head_icon | |
} || { | |
mute_icon="" | |
smin_icon="" | |
smax_icon="" | |
} | |
#------------------------------------------------------------------------ | |
if [[ "$pv" = "MUTE" ]]; then | |
icon="<span font='Font Awesome' color='$mute_color'>$mute_icon</span>" | |
pv="<span color='$mute_color'>×</span>" | |
else | |
if [[ $nv -gt 39 ]]; then | |
icon="<span font='Font Awesome'>$smax_icon</span>" | |
else | |
if [[ $nv -gt 0 ]]; then | |
icon="<span font='Font Awesome'>$smin_icon</span>" | |
else | |
icon="<span font='Font Awesome'>$mute_icon</span>" | |
fi | |
fi | |
fi | |
echo "$icon $pv" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment