From 64041db6c44cfc98cc40fbc6eb4598a8186802d7 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Thu, 25 Jul 2019 16:26:23 +0200 Subject: [PATCH] Enable support for mute media key --- media_control.lua | 15 ++++++++++++++- rc.lua | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/media_control.lua b/media_control.lua index e938534..1ca44dd 100644 --- a/media_control.lua +++ b/media_control.lua @@ -28,11 +28,18 @@ end -- Volume control function getVolume() + if isMuted() then return 0 end local handle = io.popen("amixer -D pulse sget Master | awk -F\"[][]\" '/%/ { print $2 }' | head -n 1", "r") local volume = string.gsub(handle:read("*a"), "[\n%%]+", "") / 100 handle:close() return volume end +function isMuted() + local handle = io.popen("amixer -D pulse sget Master | awk -F\"[][]\" '/[onf]{2,3}/ { print $4 }' | head -n -1", "r") + local muted = string.gsub(handle:read("*a"), "[\n]+", "") == "off" + handle:close() + return muted +end function getVolumeImage(volume) local path = beautiful.volume_osd_icon_3 @@ -161,6 +168,11 @@ local lowerVolume = function() os.execute("amixer -D pulse set Master 5%-") displayVolume() end +local toggleMute = function() + local muted = isMuted() + os.execute("amixer -D pulse set Master " .. (muted and 'on' or 'off')) + displayVolume() +end -- }}} return { @@ -168,5 +180,6 @@ return { nextTrack = nextTrack, previousTrack = previousTrack, raiseVolume = raiseVolume, - lowerVolume = lowerVolume + lowerVolume = lowerVolume, + toggleMute = toggleMute } \ No newline at end of file diff --git a/rc.lua b/rc.lua index 8a5004c..9d5718a 100644 --- a/rc.lua +++ b/rc.lua @@ -441,7 +441,9 @@ globalkeys = gears.table.join( awful.key({}, "XF86AudioRaiseVolume", media_control.raiseVolume, {description = "Raise volume", group="media control"}), awful.key({}, "XF86AudioLowerVolume", media_control.lowerVolume, - {description = "Lower volume", group="media control"}) + {description = "Lower volume", group="media control"}), + awful.key({}, "XF86AudioMute", media_control.toggleMute, + {description = "Toggle mute audio", group="media control"}) ) clientkeys = gears.table.join(