All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
4 Licensed under GNU General Public License v2
5 * (c) 2013, Luke Bonham
10 local newtimer = require("lain.helpers").newtimer
11 local read_pipe = require("lain.helpers").read_pipe
13 local awful = require("awful")
14 local beautiful = require("beautiful")
15 local naughty = require("naughty")
17 local math = { modf = math.modf }
19 local string = { format = string.format,
22 local tonumber = tonumber
24 local setmetatable = setmetatable
27 -- lain.widgets.pulsebar
32 background = beautiful.bg_normal,
37 mixer = "pavucontrol",
40 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
42 color = beautiful.fg_normal,
51 function pulsebar.notify()
58 screen = pulsebar.notifications.screen,
59 font = pulsebar.notifications.font .. " " ..
60 pulsebar.notifications.font_size,
61 fg = pulsebar.notifications.color
66 preset.title = "Sink " .. pulsebar.sink .. " - Muted"
68 preset.title = "Sink " .. pulsebar.sink .. " - " .. pulsebar._current_level .. "%"
71 int = math.modf((pulsebar._current_level / 100) * pulsebar.notifications.bar_size)
73 .. string.rep("|", int)
74 .. string.rep(" ", pulsebar.notifications.bar_size - int)
77 if pulsebar.followmouse then
78 preset.screen = mouse.screen
81 if pulsebar._notify ~= nil then
82 pulsebar._notify = naughty.notify ({
83 replaces_id = pulsebar._notify.id,
87 pulsebar._notify = naughty.notify ({
93 local function worker(args)
94 local args = args or {}
95 local timeout = args.timeout or 5
96 local settings = args.settings or function() end
97 local width = args.width or 63
98 local height = args.heigth or 1
99 local ticks = args.ticks or false
100 local ticks_size = args.ticks_size or 7
101 local vertical = args.vertical or false
102 local scallback = args.scallback
104 pulsebar.cmd = args.cmd or string.format("pacmd list-sinks | sed -n -e '0,/*/d' -e '/base volume/d' -e '/volume:/p' -e '/muted:/p'")
105 pulsebar.colors = args.colors or pulsebar.colors
106 pulsebar.notifications = args.notifications or pulsebar.notifications
107 pulsebar.sink = args.sink or 0
108 pulsebar.followmouse = args.followmouse or false
110 pulsebar.bar = awful.widget.progressbar()
112 pulsebar.bar:set_background_color(pulsebar.colors.background)
113 pulsebar.bar:set_color(pulsebar.colors.unmute)
114 pulsebar.tooltip = awful.tooltip({ objects = { pulsebar.bar } })
115 pulsebar.bar:set_width(width)
116 pulsebar.bar:set_height(height)
117 pulsebar.bar:set_ticks(ticks)
118 pulsebar.bar:set_ticks_size(ticks_size)
119 pulsebar.bar:set_vertical(vertical)
121 function pulsebar.update()
122 if scallback then pulseaudio.cmd = scallback() end
123 local s = read_pipe(pulsebar.cmd)
126 volume_now.left = tonumber(string.match(s, ":.-(%d+)%%"))
127 volume_now.right = tonumber(string.match(s, ":.-(%d+)%%"))
128 volume_now.muted = string.match(s, "muted: (%S+)")
130 local volu = volume_now.left
131 local mute = volume_now.muted
133 if (volu and volu ~= pulsebar._current_level) or (mute and mute ~= pulsebar._muted)
135 pulsebar._current_level = volu
136 pulsebar.bar:set_value(pulsebar._current_level / 100)
137 if not mute and volu == 0 or mute == "no"
139 pulsebar._muted = true
140 pulsebar.tooltip:set_text (" [Muted] ")
141 pulsebar.bar:set_color(pulsebar.colors.mute)
143 pulsebar._muted = false
144 pulsebar.tooltip:set_text(string.format(" %s:%s ", pulsebar.sink, volu))
145 pulsebar.bar:set_color(pulsebar.colors.unmute)
151 pulsebar.bar:buttons (awful.util.table.join (
152 awful.button ({}, 1, function()
153 awful.util.spawn(pulsebar.mixer)
157 timer_id = string.format("pulsebar-%s", pulsebar.sink)
159 newtimer(timer_id, timeout, pulsebar.update)
164 return setmetatable(pulsebar, { __call = function(_, ...) return worker(...) end })