diff --git a/config/awesome/evil/init.lua b/config/awesome/evil/init.lua index 00f48d2..498f3fe 100644 --- a/config/awesome/evil/init.lua +++ b/config/awesome/evil/init.lua @@ -7,6 +7,7 @@ require("evil.disk") -- User controlled require("evil.volume") +require("evil.microphone") require("evil.mpd") require("evil.brightness") -- require("evil.spotify") diff --git a/config/awesome/evil/microphone.lua b/config/awesome/evil/microphone.lua new file mode 100644 index 0000000..519fb27 --- /dev/null +++ b/config/awesome/evil/microphone.lua @@ -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) diff --git a/config/awesome/evil/volume.lua b/config/awesome/evil/volume.lua index 8330849..b545478 100644 --- a/config/awesome/evil/volume.lua +++ b/config/awesome/evil/volume.lua @@ -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)