diff --git a/config/awesome/evil/microphone.lua b/config/awesome/evil/microphone.lua index 519fb27..3206a6b 100644 --- a/config/awesome/evil/microphone.lua +++ b/config/awesome/evil/microphone.lua @@ -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()