summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-11-01 08:15:41 +0100
committerAnton Khirnov <anton@khirnov.net>2021-11-01 08:15:41 +0100
commitc4e0e03552bf09a54046b5a9ce72375f9cd72bb6 (patch)
tree16ecceffabf78367a0e69427290d70c20761c692
parent5f2d4fb9b21aab9ba8d893fec8eae8874737c16c (diff)
utils: show a notification on changing audio volume
-rw-r--r--bindings.lua4
-rw-r--r--utils.lua19
2 files changed, 18 insertions, 5 deletions
diff --git a/bindings.lua b/bindings.lua
index ed45435..7dffbe1 100644
--- a/bindings.lua
+++ b/bindings.lua
@@ -32,8 +32,8 @@ function M.create(workspace)
awful.key({ modkey, }, "Escape", function () utils.spawn_current(commondefs.terminal .. " -e htop") end),
-- 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 }, "Prior", function () utils.vol_control(workspace, 1) end),
+ awful.key({ modkey }, "Next", function () utils.vol_control(workspace, -1) end),
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),
diff --git a/utils.lua b/utils.lua
index 5a32c55..4e3bb90 100644
--- a/utils.lua
+++ b/utils.lua
@@ -31,9 +31,22 @@ function M.screen_focus_physical(n)
end
-- audio control functions
-function M.vol_control(n)
- local cmd = string.format("amixer -q set Master %d%%", math.abs(n)) .. (n < 0 and "-" or "+")
- awful.spawn(cmd)
+function M.vol_control(wsp, n)
+ local cmd = string.format("amixer set Master %d%%", math.abs(n)) .. (n < 0 and "-" or "+")
+ awful.spawn.easy_async(cmd,
+ function(stdout, stderr, exitreason, exitcode)
+ if exitcode ~= 0 then
+ naughty.notify({ preset = naughty.config.presets.warn,
+ title = "Error changing the audio volume",
+ text = stderr })
+ return
+ end
+
+ local volume = string.match(stdout, '%[(%d+%%)%]')
+ local muted = string.match(stdout, '%[off%]') and ' (Muted)' or ''
+ M.notify_singleton(wsp, 'volume',
+ { title = "Audio volume", text = volume .. muted})
+ end)
end
function M.vol_mute_toggle(wsp)