diff --git a/Changes.md b/Changes.md index cb0f732..3ca064e 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,6 @@ IMPORTANT: -- `volume_linux` now uses 🔉 and 🔈 instead of ♫ and ♩ to show mute state. +- `volume` now uses 🔉 and 🔈 instead of ♫ and ♩ to show mute state. This BREAKS backward compatibility if users substitute custom symbols from these default. @@ -16,7 +16,7 @@ Added: Fixed: -- [volume_linux] Deprecate `io.popen` +- [volume] Deprecate `io.popen` - [mpd] Lua 5.3 compatibility (for real this time); also correct a typo - [pkg,weather,contrib/btc] Allow function call without Awesome - [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf) diff --git a/widgets/volume_freebsd.lua b/widgets/volume_freebsd.lua index 200f4b7..5927150 100644 --- a/widgets/volume_freebsd.lua +++ b/widgets/volume_freebsd.lua @@ -1,9 +1,8 @@ -- {{{ Grab environment local tonumber = tonumber -local io = { popen = io.popen } -local setmetatable = setmetatable local string = { match = string.match } -local helpers = require("vicious.helpers") +local helpers = require"vicious.helpers" +local spawn = require"vicious.spawn" -- }}} @@ -13,26 +12,20 @@ local volume_freebsd = {} -- {{{ Volume widget type -local function worker(format, warg) - if not warg then return end +local STATE = { on = '🔉', off = '🔈' } - local mixer_state = { "♫", "♩" } - - -- Get mixer control contents - f = io.popen("mixer -s " .. helpers.shellquote(warg)) - local mixer = f:read() - f:close() - - -- Capture mixer control state: [5%] ... ... [on] - local voll, volr = string.match(mixer, "([%d]+):([%d]+)$") - - if voll == "0" and volr == "0" then - return {0, 0, mixer_state[2]} - else - return {voll, volr, mixer_state[1]} - end +local function parse(stdout, stderr, exitreason, exitcode) + -- Capture mixer control state, e.g. 42 : 42 + local voll, volr = string.match(stdout, "([%d]+):([%d]+)$") + if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end + return { tonumber(voll), tonumber(volr), STATE.on } +end +function volume_freebsd.async(format, warg, callback) + if not warg then return callback{} end + spawn.easy_async("mixer -s " .. helpers.shellquote(warg), + function (...) callback(parse(...)) end) end -- }}} -return setmetatable(volume_freebsd, { __call = function(_, ...) return worker(...) end }) +return helpers.setasyncall(volume_freebsd) diff --git a/widgets/volume_linux.lua b/widgets/volume_linux.lua index 098017d..3c281af 100644 --- a/widgets/volume_linux.lua +++ b/widgets/volume_linux.lua @@ -4,6 +4,7 @@ --------------------------------------------------- -- {{{ Grab environment +local type = type local tonumber = tonumber local string = { match = string.match } local table = { concat = table.concat }