aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
committerclarkzjw <[email protected]>2022-11-17 10:56:25 -0800
commitd2d735742ca61b211c9b48a2209d36395daebcf4 (patch)
treebda27729a1bbac3ab354a1f10d4885899cdbf967 /dot_config/i3/scripts/executable_volume
parenta6d2e5e6fb9adc84c32e86630b4846b1765c7d77 (diff)
downloaddotfiles-d2d735742ca61b211c9b48a2209d36395daebcf4.tar.gz
+ add existing config
Diffstat (limited to 'dot_config/i3/scripts/executable_volume')
-rw-r--r--dot_config/i3/scripts/executable_volume93
1 files changed, 93 insertions, 0 deletions
diff --git a/dot_config/i3/scripts/executable_volume b/dot_config/i3/scripts/executable_volume
new file mode 100644
index 0000000..39618e1
--- /dev/null
+++ b/dot_config/i3/scripts/executable_volume
@@ -0,0 +1,93 @@
1#!/usr/bin/env bash
2# Copyright (C) 2014 Julien Bonjean <[email protected]>
3# Copyright (C) 2014 Alexander Keller <[email protected]>
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18# original source: https://github.com/vivien/i3blocks-contrib/tree/master/volume
19# check the readme: https://github.com/vivien/i3blocks-contrib/blob/master/volume/README.md
20#------------------------------------------------------------------------
21
22# The second parameter overrides the mixer selection
23# For PulseAudio users, eventually use "pulse"
24# For Jack/Jack2 users, use "jackplug"
25# For ALSA users, you may use "default" for your primary card
26# or you may use hw:# where # is the number of the card desired
27if [[ -z "$MIXER" ]] ; then
28 MIXER="default"
29 if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then
30 # pulseaudio is running, but not all installations use "pulse"
31 if amixer -D pulse info >/dev/null 2>&1 ; then
32 MIXER="pulse"
33 fi
34 fi
35 [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug"
36 MIXER="${2:-$MIXER}"
37fi
38
39# The instance option sets the control to report and configure
40# This defaults to the first control of your selected mixer
41# For a list of the available, use `amixer -D $Your_Mixer scontrols`
42if [[ -z "$SCONTROL" ]] ; then
43 SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols |
44 sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" |
45 head -n1
46 )}"
47fi
48
49# The first parameter sets the step to change the volume by (and units to display)
50# This may be in in % or dB (eg. 5% or 3dB)
51if [[ -z "$STEP" ]] ; then
52 STEP="${1:-5%}"
53fi
54
55# AMIXER(1):
56# "Use the mapped volume for evaluating the percentage representation like alsamixer, to be
57# more natural for human ear."
58NATURAL_MAPPING=${NATURAL_MAPPING:-0}
59if [[ "$NATURAL_MAPPING" != "0" ]] ; then
60 AMIXER_PARAMS="-M"
61fi
62
63#------------------------------------------------------------------------
64
65capability() { # Return "Capture" if the device is a capture device
66 amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL |
67 sed -n "s/ Capabilities:.*cvolume.*/Capture/p"
68}
69
70volume() {
71 amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability)
72}
73
74format() {
75
76 perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)'
77 perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "'
78 # If dB was selected, print that instead
79 perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1')
80 perl_filter+='"; exit}'
81 output=$(perl -ne "$perl_filter")
82 echo "$LABEL$output"
83}
84
85#------------------------------------------------------------------------
86
87case $BLOCK_BUTTON in
88 3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute
89 4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase
90 5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease
91esac
92
93volume | format
Powered by cgit v1.2.3 (git 2.41.0)