[volume_freebsd] Use spawn.easy_async instead of io.popen
NOTE: Similar to volume_linux, the default mute symbol has also been changed.
This commit is contained in:
parent
92a2138296
commit
6f002577b9
|
@ -1,6 +1,6 @@
|
||||||
IMPORTANT:
|
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
|
This BREAKS backward compatibility if users substitute custom symbols
|
||||||
from these default.
|
from these default.
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ Added:
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|
||||||
- [volume_linux] Deprecate `io.popen`
|
- [volume] Deprecate `io.popen`
|
||||||
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
- [mpd] Lua 5.3 compatibility (for real this time); also correct a typo
|
||||||
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
- [pkg,weather,contrib/btc] Allow function call without Awesome
|
||||||
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
- [pkg] Use more updated front-ends for Debian/Ubuntu (apt) and Fedora (dnf)
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local io = { popen = io.popen }
|
|
||||||
local setmetatable = setmetatable
|
|
||||||
local string = { match = string.match }
|
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
|
-- {{{ Volume widget type
|
||||||
local function worker(format, warg)
|
local STATE = { on = '🔉', off = '🔈' }
|
||||||
if not warg then return end
|
|
||||||
|
|
||||||
local mixer_state = { "♫", "♩" }
|
local function parse(stdout, stderr, exitreason, exitcode)
|
||||||
|
-- Capture mixer control state, e.g. 42 : 42
|
||||||
-- Get mixer control contents
|
local voll, volr = string.match(stdout, "([%d]+):([%d]+)$")
|
||||||
f = io.popen("mixer -s " .. helpers.shellquote(warg))
|
if voll == "0" and volr == "0" then return { 0, 0, STATE.off } end
|
||||||
local mixer = f:read()
|
return { tonumber(voll), tonumber(volr), STATE.on }
|
||||||
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
|
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
|
end
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
||||||
return setmetatable(volume_freebsd, { __call = function(_, ...) return worker(...) end })
|
return helpers.setasyncall(volume_freebsd)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
---------------------------------------------------
|
---------------------------------------------------
|
||||||
|
|
||||||
-- {{{ Grab environment
|
-- {{{ Grab environment
|
||||||
|
local type = type
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
local string = { match = string.match }
|
local string = { match = string.match }
|
||||||
local table = { concat = table.concat }
|
local table = { concat = table.concat }
|
||||||
|
|
Loading…
Reference in New Issue