Introduce helpers.setasyncall which simplifies calling of async wtype

Also add note about potential breakage on changing default symbol in volume_linux
This commit is contained in:
Nguyễn Gia Phong 2019-05-15 16:01:49 +07:00
parent e643de1375
commit 6ba97712f5
3 changed files with 30 additions and 18 deletions

View File

@ -1,12 +1,22 @@
Feature:
IMPORTANT:
- Add `spawn.lua` as a fallback for `awful.spawn` in case Vicious is used as
- `volume_linux` now uses 🔉 and 🔈 instead of ♫ and ♩ to show mute state.
This BREAKS backward compatibility if users substitute custom symbols
from these default.
Added:
- `spawn` as a fallback for `awful.spawn` in case Vicious is used as
a stand-alone library. This wrapper, however, does NOT provide the facilities
to asynchronously spawn new processes. It also lacks a few features such as
parsing `stderr` and returning PID.
- `helpers.setasyncall` to avoid writing redundant workers for asynchronous
widget types. Note that these workers are only needed in case Vicious is used
as a stand-alone library.
Fixes:
Fixed:
- [volume_linux] 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)

View File

@ -13,10 +13,7 @@ local rawget = rawget
local require = require
local tonumber = tonumber
local tostring = tostring
local io = {
open = io.open,
popen = io.popen
}
local io = { open = io.open, popen = io.popen }
local setmetatable = setmetatable
local getmetatable = getmetatable
local string = {
@ -78,7 +75,7 @@ function helpers.wrequire(table, key)
ret = value
break
end
not_found_msg = "module '"..name.."' not found"
local not_found_msg = "module '"..name.."' not found"
-- ugly but there is afaik no other way to check if a module exists
if value:sub(1, #not_found_msg) ~= not_found_msg then
@ -93,6 +90,19 @@ function helpers.wrequire(table, key)
end
-- }}}
-- {{{ Set __call metamethod to widget type table having async key
function helpers.setasyncall(wtype)
local function worker(format, warg)
local ret
wtype.async(format, warg, function (data) ret = data end)
while ret == nil do end
return ret
end
local metatable = { __call = function (_, ...) return worker(...) end }
return setmetatable(wtype, metatable)
end
-- }}}
-- {{{ Expose path as a Lua table
function helpers.pathtotable(dir)
return setmetatable({ _path = dir },

View File

@ -5,7 +5,6 @@
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local string = { match = string.match }
local table = { concat = table.concat }
@ -25,7 +24,7 @@ local function parse(stdout, stderr, exitreason, exitcode)
-- Capture mixer control state, e.g. [ 42 % ] [ on ]
local volume, state = string.match(stdout, "%[([%d]+)%%%].*%[([%l]*)%]")
-- Handle mixers without data
if volume == nil then return { 0, STATE.off } end
if volume == nil then return {} end
if state == "" and volume == "0" -- handle mixers without mute
or state == "off" then -- handle muted mixers
@ -41,13 +40,6 @@ function volume_linux.async(format, warg, callback)
spawn.easy_async("amixer -M get " .. table.concat(warg, " "),
function (...) callback(parse(...)) end)
end
local function worker(format, warg)
local ret
volume_linux.async(format, warg, function (volume) ret = volume end)
while ret == nil do end
return ret
end
-- }}}
return setmetatable(volume_linux, { __call = function(_, ...) return worker(...) end })
return helpers.setasyncall(volume_linux)