Increase support for audio controls and add config for soundcard and parameter choice

This commit is contained in:
Alice Gaudon 2020-03-28 19:48:04 +01:00
parent 6198fa4148
commit f56403f0bf
2 changed files with 15 additions and 6 deletions

View File

@ -135,6 +135,15 @@ config.keys.custom_keys = {
};
--
-- Audio
--
config.audio = {
card = '-D pulse',
device = 'Master',
};
--
-- Widgets
--

View File

@ -35,15 +35,15 @@ end
-- Volume control
function getVolume()
if isMuted() then return 0 end
local handle = io.popen("amixer -D pulse sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n 1", "r")
local handle = io.popen("amixer " .. config.audio.card .. " sget '" .. config.audio.device .. "' -M | awk -F\"[][]\" '/%/ { print $2 }' | head -n 1", "r")
local volume = string.gsub(handle:read("*a"), "[\n%%]+", "") / 100
handle:close()
return volume
end
function isMuted()
local handle = io.popen("amixer -D pulse sget Master | awk -F\"[][]\" '/[onf]{2,3}/ { print $4 }' | head -n -1", "r")
local muted = string.gsub(handle:read("*a"), "[\n]+", "") == "off"
local handle = io.popen("amixer " .. config.audio.card .. " sget '" .. config.audio.device .. "' | egrep 'Playback.*?\\[o' | egrep -o '\\[o.+\\]'", "r")
local muted = string.gsub(handle:read("*a"), "[\n]+", "") == "[off]"
handle:close()
return muted
end
@ -178,16 +178,16 @@ local displayVolume = function()
timer:start()
end
local raiseVolume = function()
os.execute("amixer -D pulse set Master 5%+")
os.execute("amixer " .. config.audio.card .. " set '" .. config.audio.device .. "' 5%+ -M")
displayVolume()
end
local lowerVolume = function()
os.execute("amixer -D pulse set Master 5%-")
os.execute("amixer " .. config.audio.card .. " set '" .. config.audio.device .. "' 5%- -M")
displayVolume()
end
local toggleMute = function()
local muted = isMuted()
os.execute("amixer -D pulse set Master " .. (muted and 'on' or 'off'))
os.execute("amixer " .. config.audio.card .. " set '" .. config.audio.device .. "' " .. (muted and 'on' or 'off'))
displayVolume()
end
-- }}}