summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-10-26 21:41:20 +0200
committerAnton Khirnov <anton@khirnov.net>2021-10-26 21:41:20 +0200
commitccb848c94d41fe71a9a98ad03ae7b393c91b6cfe (patch)
treea75274c330c427e12b63e61f0d74b76adf413fe1
parentfc297a92ca20d8697d503ff8f409a57803dbea43 (diff)
utils: show a notification on mute/unmute
-rw-r--r--bindings.lua2
-rw-r--r--utils.lua17
2 files changed, 16 insertions, 3 deletions
diff --git a/bindings.lua b/bindings.lua
index 2ffba5b..ed45435 100644
--- a/bindings.lua
+++ b/bindings.lua
@@ -34,7 +34,7 @@ function M.create(workspace)
-- audio control
awful.key({ modkey }, "Prior", function () utils.vol_control(1) end),
awful.key({ modkey }, "Next", function () utils.vol_control(-1) end),
- awful.key({ modkey }, "End", utils.vol_mute_toggle),
+ awful.key({ modkey }, "End", function () utils.vol_mute_toggle(workspace) end),
awful.key({ modkey }, "Delete", function () utils.auto_mute_toggle(workspace) end),
awful.key({ modkey }, "grave", function () awful.spawn("mpc toggle") end),
awful.key({ modkey }, "b", function () awful.spawn("mpc next") end),
diff --git a/utils.lua b/utils.lua
index 5b40dbb..5a32c55 100644
--- a/utils.lua
+++ b/utils.lua
@@ -36,8 +36,21 @@ function M.vol_control(n)
awful.spawn(cmd)
end
-function M.vol_mute_toggle()
- awful.spawn("amixer -q set Master toggle")
+function M.vol_mute_toggle(wsp)
+ local control = 'Master'
+ awful.spawn.easy_async("amixer sset " .. control .. " toggle",
+ function(stdout, stderr, exitreason, exitcode)
+ if exitcode ~= 0 then
+ naughty.notify({ preset = naughty.config.presets.warn,
+ title = "Error toggling the " .. control .. " control",
+ text = stderr })
+ return
+ end
+
+ local text = string.match(stdout, '%[on%]') and 'Unmuted' or 'Muted'
+ M.notify_singleton(wsp, 'mute',
+ { title = "Audio", text = text })
+ end)
end
function M.auto_mute_toggle(wsp)