BIN
awesome/widgets/volume/1.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
awesome/widgets/volume/2.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
BIN
awesome/widgets/volume/3.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
awesome/widgets/volume/audio-0.png
Normal file
|
After Width: | Height: | Size: 1015 B |
BIN
awesome/widgets/volume/audio-1.png
Normal file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
awesome/widgets/volume/audio-2.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
awesome/widgets/volume/audio-3.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
awesome/widgets/volume/audio-muted.png
Normal file
|
After Width: | Height: | Size: 872 B |
52
awesome/widgets/volume/pa-vol.sh
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
# Copyright 2015 Alexander Tsepkov
|
||||
|
||||
|
||||
#SINK_NAME="alsa_output.pci-0000_00_1b.0.analog-stereo"
|
||||
#SINK_NAME="alsa_output.pci-0000_00_1b.0.hdmi-stereo"
|
||||
SOUND_DEVICE=`pacmd dump | grep -P "^set-card-profile" | grep stereo | cut -d: -f2 | cut -d+ -f1`
|
||||
SINK_NAME="alsa_output.pci-0000_00_1b.0.$SOUND_DEVICE"
|
||||
VOL_STEP="0x01000"
|
||||
|
||||
MUTE_STATE=`pacmd dump | grep -P "^set-sink-mute $SINK_NAME\s+" | perl -p -i -e 's/.+\s(yes|no)$/$1/'`
|
||||
VOL_NOW=`pacmd dump | grep -P "^set-sink-volume $SINK_NAME\s+" | perl -p -i -e 's/.+\s(.x.+)$/$1/'`
|
||||
VOL_MAX=$((0x10000))
|
||||
|
||||
case "$1" in
|
||||
plus)
|
||||
if [ $MUTE_STATE = yes ]; then
|
||||
echo "Muted"
|
||||
else
|
||||
VOL_NEW=$((VOL_NOW + VOL_STEP))
|
||||
if [ $VOL_NEW -gt $VOL_MAX ]
|
||||
then
|
||||
VOL_NEW=$VOL_MAX
|
||||
fi
|
||||
pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
|
||||
echo "$((100*VOL_NEW / VOL_MAX))%"
|
||||
fi
|
||||
|
||||
;;
|
||||
minus)
|
||||
if [ $MUTE_STATE = yes ]; then
|
||||
echo "Muted"
|
||||
else
|
||||
VOL_NEW=$((VOL_NOW - VOL_STEP))
|
||||
if [ $(($VOL_NEW)) -lt $((0x00000)) ]
|
||||
then
|
||||
VOL_NEW=$((0x00000))
|
||||
fi
|
||||
pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
|
||||
echo "$((100*VOL_NEW / VOL_MAX))%"
|
||||
fi
|
||||
|
||||
;;
|
||||
mute)
|
||||
if [ $MUTE_STATE = no ]; then
|
||||
pactl set-sink-mute $SINK_NAME 1
|
||||
echo "Muted"
|
||||
elif [ $MUTE_STATE = yes ]; then
|
||||
pactl set-sink-mute $SINK_NAME 0
|
||||
echo "$((100*VOL_NOW / VOL_MAX))%"
|
||||
fi
|
||||
esac
|
||||
52
awesome/widgets/volume/widget.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
-- Alexander Tsepkov, 2015
|
||||
--
|
||||
-- Minimalistic Volume Widget that works with multiple output sources
|
||||
-- dependency: FontAwesome
|
||||
|
||||
|
||||
local wibox = require("wibox")
|
||||
local naughty = require("naughty")
|
||||
|
||||
local last_id
|
||||
local vol_muted
|
||||
function mixercommand(command)
|
||||
local fd = io.popen(os.getenv("HOME") .. "/.config/awesome/pa-vol.sh " .. command)
|
||||
local status = fd:read("*all")
|
||||
fd:close()
|
||||
local pic = os.getenv("HOME") .. "/.config/awesome/widgets/volume/"
|
||||
local value
|
||||
if status == "Muted\n" then
|
||||
pic = pic .. "audio-muted.png"
|
||||
else
|
||||
-- dividing by 26 is a little cheat to prevent overflow on 100%
|
||||
value = math.floor(tonumber(string.sub(status:gsub("%s+$", ""), 0, -2)) / 26)
|
||||
pic = pic .. "audio-" .. value .. ".png"
|
||||
end
|
||||
last_id = naughty.notify({
|
||||
title = "Volume",
|
||||
text = status,
|
||||
replaces_id = last_id,
|
||||
icon = pic,
|
||||
}).id
|
||||
end
|
||||
function volumeup()
|
||||
mixercommand("plus")
|
||||
end
|
||||
|
||||
function volumedown()
|
||||
mixercommand("minus")
|
||||
end
|
||||
|
||||
function volumetoggle()
|
||||
mixercommand("mute")
|
||||
end
|
||||
|
||||
-- zenstate not applicable bescause there is no volume icon for this widget at all
|
||||
|
||||
-- this widget doesn't have an icon, I use volumeicon instead but I prefer the messages/control through this
|
||||
-- widget instead
|
||||
widget = {
|
||||
up = volumeup,
|
||||
down = volumedown,
|
||||
toggle = volumetoggle,
|
||||
}
|
||||