Increase support for audio controls and add config for soundcard and parameter choice
This commit is contained in:
parent
6198fa4148
commit
f56403f0bf
@ -135,6 +135,15 @@ config.keys.custom_keys = {
|
||||
};
|
||||
|
||||
|
||||
--
|
||||
-- Audio
|
||||
--
|
||||
config.audio = {
|
||||
card = '-D pulse',
|
||||
device = 'Master',
|
||||
};
|
||||
|
||||
|
||||
--
|
||||
-- Widgets
|
||||
--
|
||||
|
@ -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
|
||||
-- }}}
|
||||
|
Loading…
Reference in New Issue
Block a user