From c563603a2ecd0f8084604b439828c0d5151aa97a Mon Sep 17 00:00:00 2001 From: Calvin Timmer Date: Thu, 2 Feb 2017 14:47:42 +0100 Subject: [PATCH] Easy switching between default sink or source in pulseaudio widget --- widgets/pulseaudio.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/widgets/pulseaudio.lua b/widgets/pulseaudio.lua index 8a48f76..9cd2ba6 100644 --- a/widgets/pulseaudio.lua +++ b/widgets/pulseaudio.lua @@ -19,11 +19,12 @@ local string = { gmatch = string.gmatch, local function factory(args) local pulseaudio = {} local args = args or {} + local devicetype = args.devicetype or "sink" local timeout = args.timeout or 5 local settings = args.settings or function() end local scallback = args.scallback - pulseaudio.cmd = args.cmd or "pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" + pulseaudio.cmd = args.cmd or "pacmd list-" .. devicetype .. "s | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p' -e '/device\\.string/p'" pulseaudio.widget = wibox.widget.textbox() @@ -33,8 +34,9 @@ local function factory(args) helpers.async({ shell, "-c", pulseaudio.cmd }, function(s) volume_now = { index = string.match(s, "index: (%S+)") or "N/A", - sink = string.match(s, "device.string = \"(%S+)\"") or "N/A", - muted = string.match(s, "muted: (%S+)") or "N/A" + device = string.match(s, "device.string = \"(%S+)\"") or "N/A", + sink = device, -- legacy API + muted = string.match(s, "muted: (%S+)") or "N/A" } local ch = 1