elenapan/config/awesome/evil/volume.lua
elenapan c738169ca5 New theme: ephemeral, anti-aliased corners, app drawer, lock screen,
evil daemon system, dependency list update, README improvements.


Former-commit-id: db310f8e49
Former-commit-id: 4f25f9200c3ac9f9385daca5a68378249ff0329e
Former-commit-id: 69fa3954e5738446a59b409b7e326233e7c3ef55
Former-commit-id: 673176f7857e39f3455f4ccb426eef2789c0e891
2019-08-01 02:17:59 +03:00

74 lines
2.2 KiB
Lua

-- Provides:
-- evil::volume
-- volume percentage (integer)
-- muted (boolean)
-- evil::microphone
-- muted (boolean)
local awful = require("awful")
local function emit_volume_info()
-- Get volume info
awful.spawn.easy_async("pactl list sinks",
function(stdout)
local volume = stdout:match('(%d+)%% /')
local muted = stdout:match('Mute:(%s+)[yes]')
if muted ~= nil then
awesome.emit_signal("evil::volume", tonumber(volume), true)
else
awesome.emit_signal("evil::volume", tonumber(volume), false)
end
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')
if muted == "yes" then
awesome.emit_signal("evil::microphone", true)
else
awesome.emit_signal("evil::microphone", false)
end
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 = [[
bash -c '
pactl subscribe 2> /dev/null | grep --line-buffered "sink"
']]
-- 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
awful.spawn.with_line_callback(volume_script, {
stdout = function(line)
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)