1
0
awesomewm-config/external/bluetooth.lua
2023-06-04 15:59:49 +03:00

35 lines
719 B
Lua

local bluetooth = {}
local DEFAULT_SIGNAL = "bluetooth::value"
local blue = [[ bluetoothctl show | grep "Powered:" ]]
--- callback: function(stat)
function bluetooth.get(callback)
awful.spawn.easy_async_with_shell(blue, function(out)
if out == "" then
callback("no")
else
local val = gears.string.split(out, " ")
callback(val[2])
end
end)
end
function bluetooth.emit(name)
bluetooth.get(function(...)
awesome.emit_signal(name or DEFAULT_SIGNAL, ...)
end)
end
function bluetooth.register_signal(signal_name, update_interval)
gears.timer {
timeout = update_interval or 5,
call_now = true,
autostart = true,
callback = function() bluetooth.emit(signal_name) end
}
end
return bluetooth