From debca082af822d8af614311a65b102708afe182a Mon Sep 17 00:00:00 2001 From: Sebastian Gehaxelt Date: Sun, 23 Jul 2017 19:00:35 +0200 Subject: [PATCH 1/2] Added mute microphone functionality --- pulseaudio.lua | 35 ++++++++++++++++++++++++++++++++++- widget.lua | 9 +++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/pulseaudio.lua b/pulseaudio.lua index 38857d2..a1d6b7c 100644 --- a/pulseaudio.lua +++ b/pulseaudio.lua @@ -22,6 +22,7 @@ local pulseaudio = {} local cmd = "pacmd" local default_sink = "" +local default_source = "" function pulseaudio:Create() o = {} @@ -29,7 +30,8 @@ function pulseaudio:Create() self.__index = self o.Volume = 0 -- volume of default sink - o.Mute = false -- state of the mute flag of the default sink + o.Mute = true -- state of the mute flag of the default sink + o.MuteMic = true -- retreive current state from Pulseaudio pulseaudio.UpdateState(o) @@ -56,6 +58,14 @@ function pulseaudio:UpdateState() return false end + -- get the default source + default_source = string.match(out, "set%-default%-source ([^\n]+)") + + if default_source == nil then + default_source = "" + return false + end + -- retreive volume of default sink for sink, value in string.gmatch(out, "set%-sink%-volume ([^%s]+) (0x%x+)") do if sink == default_sink then @@ -72,6 +82,17 @@ function pulseaudio:UpdateState() end self.Mute = m == "yes" + + -- retreive mute state of default sink + local m + for source, value in string.gmatch(out, "set%-source%-mute ([^%s]+) (%a+)") do + if source == default_source then + m = value + end + end + + self.MuteMic = m == "yes" + end -- Run process and wait for it to end @@ -112,6 +133,18 @@ function pulseaudio:ToggleMute() self:UpdateState() end +-- Toggles the mute flag of the default default_source. +function pulseaudio:ToggleMuteMic() + if self.MuteMic then + run(cmd .. " set-source-mute " .. default_source .. " 0") + else + run(cmd .. " set-source-mute " .. default_source .. " 1") + end + + -- …and update values. + self:UpdateState() +end + return pulseaudio diff --git a/widget.lua b/widget.lua index ad8c994..1219112 100644 --- a/widget.lua +++ b/widget.lua @@ -116,8 +116,13 @@ end function pulseWidget.ToggleMute() - p:ToggleMute() - _update() + p:ToggleMute() + _update() +end + +function pulseWidget.ToggleMuteMic() + p:ToggleMuteMic() + _update() end function pulseWidget.Update() From 7b8f5ca91e564721b9563678598d11a3f634877e Mon Sep 17 00:00:00 2001 From: Sebastian Gehaxelt Date: Sun, 23 Jul 2017 19:00:50 +0200 Subject: [PATCH 2/2] Adjusted README --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 18cc0f1..86c5e40 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ Note, that… ----------- -…this project is not developed any longer. It still works, though. I do not use it any more, nor do I use awesome. I am willing to merge bug fixes and improvements that do not alter the appearance or behaviour. Breaking changes in this sense, I will not merge. -You are welcome to fork this and I will add a link to it in the README. -Currently known, feature adding forks: -* [seniorivn/apw](https://github.com/seniorivn/apw) +This is a fork from [Mokasin's APW repo](https://github.com/mokasin/apw). Functionality to mute the default microphone was added. + +My experiences show that it's also compatible with Awesome 4.0+. Awesome Pulseaudio Widget =========================