Only emit microphone info of the currently active source

This commit is contained in:
elenapan 2020-09-27 00:51:53 +03:00
parent 2e143eff4f
commit ce387838d0

View file

@ -3,18 +3,19 @@
-- muted (boolean)
local awful = require("awful")
local muted_old = -1
local function emit_microphone_info()
-- Use tail to grab the last line of the output (which refers to the microphone)
awful.spawn.easy_async_with_shell("pacmd list-sources | grep muted | tail -1 | awk '{print $2}'",
function(stdout)
-- Remove trailing whitespace
muted = stdout:gsub('^%s*(.-)%s*$', '%1')
awesome.emit_signal("evil::microphone", muted == "yes")
-- See evil/volume.lua for the reason why we print the +7 and +11 lines after '* index'
awful.spawn.easy_async_with_shell("pacmd list-sources | awk '/\\* index: /{nr[NR+7];nr[NR+11]}; NR in nr'", function(stdout)
local muted = stdout:match('muted:(%s+)[yes]')
local muted_int = muted and 1 or 0
if not (muted_int == muted_old) then
awesome.emit_signal("evil::microphone", muted)
muted_old = muted_int
end
)
end)
end
-- Run once to initialize widgets
emit_microphone_info()