Enable support for mute media key

This commit is contained in:
Alice Gaudon 2019-07-25 16:26:23 +02:00
parent a57fc53a27
commit 64041db6c4
2 changed files with 17 additions and 2 deletions

View File

@ -28,11 +28,18 @@ end
-- Volume control -- Volume control
function getVolume() 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 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 local volume = string.gsub(handle:read("*a"), "[\n%%]+", "") / 100
handle:close() handle:close()
return volume return volume
end 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) function getVolumeImage(volume)
local path = beautiful.volume_osd_icon_3 local path = beautiful.volume_osd_icon_3
@ -161,6 +168,11 @@ local lowerVolume = function()
os.execute("amixer -D pulse set Master 5%-") os.execute("amixer -D pulse set Master 5%-")
displayVolume() displayVolume()
end end
local toggleMute = function()
local muted = isMuted()
os.execute("amixer -D pulse set Master " .. (muted and 'on' or 'off'))
displayVolume()
end
-- }}} -- }}}
return { return {
@ -168,5 +180,6 @@ return {
nextTrack = nextTrack, nextTrack = nextTrack,
previousTrack = previousTrack, previousTrack = previousTrack,
raiseVolume = raiseVolume, raiseVolume = raiseVolume,
lowerVolume = lowerVolume lowerVolume = lowerVolume,
toggleMute = toggleMute
} }

4
rc.lua
View File

@ -441,7 +441,9 @@ globalkeys = gears.table.join(
awful.key({}, "XF86AudioRaiseVolume", media_control.raiseVolume, awful.key({}, "XF86AudioRaiseVolume", media_control.raiseVolume,
{description = "Raise volume", group="media control"}), {description = "Raise volume", group="media control"}),
awful.key({}, "XF86AudioLowerVolume", media_control.lowerVolume, 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( clientkeys = gears.table.join(