From c6a2d6241151f95d4bedff2e05aceefe9b9ec278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Tue, 2 Jul 2019 12:51:01 -0500 Subject: [PATCH] Multiples fixes: * [volume: Use '/usr/bin/env bash' as shebang](https://github.com/vivien/i3blocks-contrib/commit/cd182fd4f2e6d7e100e2aaae06c67d9905e46457#diff-210ab9e731c9c36c2c38db15c28a8d1c) On some systems (e.g. NixOS, openBSD) Bash isn't located or symlinked at `/bin/bash`. This change ensures that the correct path is used across different operating systems. * [volume: add LABEL support](https://github.com/vivien/i3blocks-contrib/commit/be3f4ae715f7a76cc54653543775a1aea6c65fff#diff-210ab9e731c9c36c2c38db15c28a8d1c) * [volume: use injected properties](https://github.com/vivien/i3blocks-contrib/commit/50b2b6ee539cc636a303a00450909733d13dca14#diff-210ab9e731c9c36c2c38db15c28a8d1c) See #132 * [volume: pulse-detection: explicitly try the "pulse" device](https://github.com/vivien/i3blocks-contrib/commit/777a056cce442dd4611cad9ff82ed3c21fa73ffd#diff-210ab9e731c9c36c2c38db15c28a8d1c) Because it's available on some systems (for which pulse is the right option), but not the default, so `amixer info` will not give the right result. When this command succeeds, there is no more need to check the output. Additionally removed a wrong test bracket (not neccessary and not working for all bash versions). * [volume: don't check for pulse via lsmod but command](https://github.com/vivien/i3blocks-contrib/commit/67dba4fca91b6dcdc3deb00c74ed4cab1da22598#diff-210ab9e731c9c36c2c38db15c28a8d1c) - check if command `pulseaudio` exists - check if pulse is running - in the case that pulse is detected, still check if the mixer name "pulse" exists - instruction for manual setting in README Fixes vivien/i3blocks#236 Fixes vivien/i3blocks#201 Fixes: vivien/i3blocks#281 * [volume: allow device names to include numbers](https://github.com/vivien/i3blocks-contrib/commit/1b3efc6e44ca2a01da2fb23ac60dbfc49bdec33c#diff-210ab9e731c9c36c2c38db15c28a8d1c): Fixes: vivien/i3blocks#281 --- config | 7 ++++--- i3blocks.conf | 5 +++-- scripts/i3blocks/volume | 37 +++++++++++++++++++++++++------------ 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/config b/config index 4ae6379..60803fc 100644 --- a/config +++ b/config @@ -225,9 +225,10 @@ exec --no-startup-id conky # exec --no-startup-id aarchup # Pulse Audio controls -bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -q -D pulse sset Master 5%+; exec pkill -SIGRTMIN+10 i3blocks #increase sound volume -bindsym XF86AudioLowerVolume exec --no-startup-id amixer -q -D pulse sset Master 5%-; exec pkill -SIGRTMIN+10 i3blocks #decrease sound volume -bindsym XF86AudioMute exec --no-startup-id amixer -q -D pulse sset Master toggle; exec pkill -SIGRTMIN+10 i3blocks # mute sound +exec --no-startup-id pulseaudio --start +bindsym XF86AudioRaiseVolume exec --no-startup-id amixer -q -D pulse sset Master 5%+ && pkill -SIGRTMIN+10 i3blocks #increase sound volume +bindsym XF86AudioLowerVolume exec --no-startup-id amixer -q -D pulse sset Master 5%- && pkill -SIGRTMIN+10 i3blocks #decrease sound volume +bindsym XF86AudioMute exec --no-startup-id amixer -q -D pulse sset Master toggle && pkill -SIGRTMIN+10 i3blocks # mute sound # Enable devices USB # bindsym $mod+m exec --no-startup-id "udisksctl mount -b /dev/sdb1" diff --git a/i3blocks.conf b/i3blocks.conf index bcbe309..d5a4d0e 100644 --- a/i3blocks.conf +++ b/i3blocks.conf @@ -47,11 +47,12 @@ signal=10 [volume] #label=VOL label=♪ -instance=Master -# instance=PCM # interval=once interval=5 signal=10 +#STEP=5% +#MIXER=[determined automatically] +#SCONTROL=[determined automatically] # Memory usage # diff --git a/scripts/i3blocks/volume b/scripts/i3blocks/volume index a55db88..3b2a7f4 100755 --- a/scripts/i3blocks/volume +++ b/scripts/i3blocks/volume @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (C) 2014 Julien Bonjean # Copyright (C) 2014 Alexander Keller @@ -18,26 +18,37 @@ #------------------------------------------------------------------------ # The second parameter overrides the mixer selection -# For PulseAudio users, use "pulse" +# For PulseAudio users, eventually 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}" +if [[ -z "$MIXER" ]] ; then + MIXER="default" + if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then + # pulseaudio is running, but not all installations use "pulse" + if amixer -D pulse info >/dev/null 2>&1 ; then + MIXER="pulse" + fi + fi + [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug" + MIXER="${2:-$MIXER}" +fi # 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 - )}" +if [[ -z "$SCONTROL" ]] ; then + SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols | + sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | + head -n1 + )}" +fi # 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%}" +if [[ -z "$STEP" ]] ; then + STEP="${1:-5%}" +fi #------------------------------------------------------------------------ @@ -51,12 +62,14 @@ volume() { } 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" + output=$(perl -ne "$perl_filter") + echo "$LABEL$output" } #------------------------------------------------------------------------