fix and complete pull #286

This commit is contained in:
copycat-killer 2017-01-24 21:33:16 +01:00
parent fc5974a9c2
commit 03fdf984e9
2 changed files with 9 additions and 5 deletions

View File

@ -23,19 +23,21 @@ local function worker(args)
local timeout = args.timeout or 5 local timeout = args.timeout or 5
local settings = args.settings or function() end local settings = args.settings or function() end
alsa.cmd = args.cmd or "amixer"
alsa.channel = args.channel or "Master" alsa.channel = args.channel or "Master"
alsa.cmd = args.cmd or "amixer sget " .. alsa.channel
alsa.togglechannel = args.togglechannel alsa.togglechannel = args.togglechannel
local format_cmd = string.format("%s get %s", alsa.cmd, alsa.channel)
if alsa.togglechannel then if alsa.togglechannel then
alsa.cmd = { shell, "-c", string.format("%s get %s; %s get %s", format_cmd = { shell, "-c", string.format("%s get %s; %s get %s",
alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) } alsa.cmd, alsa.channel, alsa.cmd, alsa.togglechannel) }
end end
alsa.last = {} alsa.last = {}
function alsa.update() function alsa.update()
helpers.async(alsa.cmd, function(mixer) helpers.async(format_cmd, function(mixer)
local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)") local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
if alsa.last.level ~= l or alsa.last.status ~= s then if alsa.last.level ~= l or alsa.last.status ~= s then
volume_now = { level = l, status = s } volume_now = { level = l, status = s }

View File

@ -54,8 +54,10 @@ local function worker(args)
alsabar.notification_preset.font = "Monospace 11" alsabar.notification_preset.font = "Monospace 11"
end end
local format_cmd = string.format("%s get %s", alsabar.cmd, alsabar.channel)
if alsabar.togglechannel then if alsabar.togglechannel then
alsabar.cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s", format_cmd = { awful.util.shell, "-c", string.format("%s get %s; %s get %s",
alsabar.cmd, alsabar.channel, alsabar.cmd, alsabar.togglechannel) } alsabar.cmd, alsabar.channel, alsabar.cmd, alsabar.togglechannel) }
end end
@ -75,7 +77,7 @@ local function worker(args)
alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } }) alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
function alsabar.update(callback) function alsabar.update(callback)
helpers.async(alsabar.cmd, function(mixer) helpers.async(format_cmd, function(mixer)
local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)") local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted) then
alsabar._current_level = tonumber(volu) or alsabar._current_level alsabar._current_level = tonumber(volu) or alsabar._current_level