On 19/10/2012 02:42, Juan Antonio Zuloaga Mellino wrote:
> I can't remember if I made it, stole it or both, but this is my ugly
> workaround for pulse audio
>
> calling paMuteToggle() doest what you'd expect.
> With no parameters changes all the sinks to the opposite state of the
> first sink.
> You can use a sink as an argument.
>
> HOW TO USE IT:
>
> require("pamute")
> [...]
> awful.key({ }, "XF86AudioMute",function () paMuteToggle() end ),
>
>
> pamute.lua attached.
> I write a little program to control the sound volume of pulseaudio: https://github.com/cdemoulins/pamixer % pamixer --help Allowed options: -h [ --help ] help message -s [ --sink ] arg choose a different sink than the default --source arg choose a different source than the default --default-source select the default source --get-volume get the current volume --set-volume arg set the volume --increase arg increase the volume --decrease arg decrease the volume --toggle-mute switch between mute and unmute --mute set mute --unmute unset mute --get-mute display true if the volume is mute, false otherwise --list-sinks list the sinks --list-sources list the sources Using this program i create a widget to display the current volume and add some keybinding to control the volume. My module “pulseaudio.lua” is for the git version only. Clément -- Clef GPG : 0xDD51E028
local awful = require("awful")
local wibox = require("wibox")
local naughty = require("naughty")
local util = require("util")
local pulseaudio = {}
local label = wibox.widget.textbox()
local widget = wibox.widget.textbox()
pulseaudio.widget = wibox.layout.fixed.horizontal()
pulseaudio.widget:add(label)
pulseaudio.widget:add(widget)
local volume = 0
local muted = false
local notification_id = nil
local muted_notification_id = nil
local pamixer = "pamixer"
local sink = 0
local timer = timer
local muted_icon = "/home/clement/.config/awesome/current_theme/icons/audio-volume-muted.png"
local off_icon = "/home/clement/.config/awesome/current_theme/icons/audio-volume-off.png"
local low_icon = "/home/clement/.config/awesome/current_theme/icons/audio-volume-low.png"
local medium_icon = "/home/clement/.config/awesome/current_theme/icons/audio-volume-medium.png"
local high_icon = "/home/clement/.config/awesome/current_theme/icons/audio-volume-high.png"
local function update()
local icon = "<span font='15'>ð</span> " -- speaker character
if muted then
icon = "<span font='10'>ð</span> " -- mute speaker character
end
local volume_text = util.textcolor(string.format("%02d%%", volume), util.gradient("#44FF44", "#FF4444", 30, 120, volume))
label:set_markup(icon)
widget:set_markup(volume_text)
end
local function notify()
local volume_icon = high_icon
if volume == 0 then
volume_icon = off_icon
elseif volume <= 30 then
volume_icon = low_icon
elseif volume <= 60 then
volume_icon = medium_icon
end
notification_id = naughty.notify({ text="Volume "..volume.."%", title="Volume", icon=volume_icon, replaces_id=notification_id }).id
end
local volume_timer = timer { timeout=3 }
volume_timer:connect_signal("timeout", function()
pulseaudio:update()
end)
function pulseaudio:register()
volume_timer:start()
end
function pulseaudio:update()
volume = tonumber(awful.util.pread(pamixer.." -s "..sink.." --get-volume") or 0)
muted = awful.util.pread(pamixer.." -s "..sink.." --get-mute") == "true"
update()
end
function pulseaudio:volume_up()
volume = tonumber(awful.util.pread(pamixer.." -s "..sink.." --increase 5 --get-volume") or 0)
if volume > 150 then
volume = tonumber(awful.util.pread(pamixer.." -s "..sink.." --set-volume 150 --get-volume") or 0)
end
update()
notify()
end
function pulseaudio:volume_down()
volume = tonumber(awful.util.pread(pamixer.." -s "..sink.." --decrease 5 --get-volume") or 0)
update()
notify()
end
function pulseaudio:toggle_mute()
muted = awful.util.pread(pamixer.." -s "..sink.." --toggle-mute --get-mute") == "false"
update()
if muted == true then
muted_notification_id = naughty.notify({ text="Muted", title="Volume", icon=muted_icon, replaces_id=muted_notification_id }).id
else
muted_notification_id = naughty.notify({ text="Unmuted", title="Volume", icon=high_icon, replaces_id=muted_notification_id }).id
notify()
end
end
--pulseaudio.widget:connect_signal("button::press", function()
--naughty.notify({text="Test", title="Titre"})
--pulseaudio.toggle_mute()
--end)
pulseaudio.widget:buttons(awful.util.table.join(
awful.button({ }, 1, pulseaudio.toggle_mute),
awful.button({ }, 4, pulseaudio.volume_up),
awful.button({ }, 5, pulseaudio.volume_down)
))
return pulseaudio
signature.asc
Description: OpenPGP digital signature
