diff --git a/default_config.lua b/default_config.lua index c840cba..651699d 100644 --- a/default_config.lua +++ b/default_config.lua @@ -135,6 +135,15 @@ config.keys.custom_keys = { }; +-- +-- Audio +-- +config.audio = { + card = '-D pulse', + device = 'Master', +}; + + -- -- Widgets -- diff --git a/simple/media_control.lua b/simple/media_control.lua index 8bc3e1d..52e0d84 100644 --- a/simple/media_control.lua +++ b/simple/media_control.lua @@ -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 -- }}}