Split microphone daemon from volume daemon

This commit is contained in:
elenapan 2020-09-26 23:27:37 +03:00
parent 2ee504bea9
commit fdbc9a4403
3 changed files with 36 additions and 28 deletions

View file

@ -7,6 +7,7 @@ require("evil.disk")
-- User controlled
require("evil.volume")
require("evil.microphone")
require("evil.mpd")
require("evil.brightness")
-- require("evil.spotify")

View file

@ -0,0 +1,35 @@
-- Provides:
-- evil::microphone
-- muted (boolean)
local awful = require("awful")
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")
end
)
end
-- Run once to initialize widgets
emit_microphone_info()
-- Sleeps until pactl detects an event (microphone volume up / down / (un)mute)
local microphone_script = [[
bash -c '
pactl subscribe 2> /dev/null | grep --line-buffered "source #"
']]
-- Kill old pactl subscribe processes
awful.spawn.easy_async_with_shell("ps x | grep \"pactl subscribe\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
-- Run emit_microphone_info() with each line printed
awful.spawn.with_line_callback(microphone_script, {
stdout = function(line)
emit_microphone_info()
end
})
end)

View file

@ -2,8 +2,6 @@
-- evil::volume
-- percentage (integer)
-- muted (boolean)
-- evil::microphone
-- muted (boolean)
local awful = require("awful")
local volume_old = -1
@ -33,21 +31,8 @@ local function emit_volume_info()
end)
end
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")
end
)
end
-- Run once to initialize widgets
emit_volume_info()
emit_microphone_info()
-- Sleeps until pactl detects an event (volume up/down/toggle mute)
local volume_script = [[
@ -56,12 +41,6 @@ local volume_script = [[
"]]
-- Sleeps until pactl detects an event (microphone volume up / down / (un)mute)
local microphone_script = [[
bash -c '
pactl subscribe 2> /dev/null | grep --line-buffered "source #"
']]
-- Kill old pactl subscribe processes
awful.spawn.easy_async_with_shell("ps x | grep \"pactl subscribe\" | grep -v grep | awk '{print $1}' | xargs kill", function ()
-- Run emit_volume_info() with each line printed
@ -70,13 +49,6 @@ awful.spawn.easy_async_with_shell("ps x | grep \"pactl subscribe\" | grep -v gre
emit_volume_info()
end
})
-- Run emit_microphone_info() with each line printed
awful.spawn.with_line_callback(microphone_script, {
stdout = function(line)
emit_microphone_info()
end
})
end)