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
13 local read_pipe = require("lain.helpers").read_pipe
14 >>>>>>> upstream/master
16 local awful = require("awful")
17 local beautiful = require("beautiful")
18 local naughty = require("naughty")
21 local io = { popen = io.popen }
22 local math = { modf = math.modf }
24 local math = { modf = math.modf }
26 >>>>>>> upstream/master
27 local string = { format = string.format,
30 local tonumber = tonumber
32 local setmetatable = setmetatable
35 -- lain.widgets.alsabar
40 >>>>>>> upstream/master
45 background = beautiful.bg_normal,
50 terminal = terminal or "xterm",
51 mixer = terminal .. " -e alsamixer",
54 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
56 color = beautiful.fg_normal,
65 function alsabar.notify()
72 screen = alsabar.notifications.screen,
73 font = alsabar.notifications.font .. " " ..
74 alsabar.notifications.font_size,
75 fg = alsabar.notifications.color
80 preset.title = alsabar.channel .. " - Muted"
82 preset.title = alsabar.channel .. " - " .. alsabar._current_level .. "%"
85 int = math.modf((alsabar._current_level / 100) * alsabar.notifications.bar_size)
87 .. string.rep("|", int)
88 .. string.rep(" ", alsabar.notifications.bar_size - int)
93 if alsabar.followmouse then
94 preset.screen = mouse.screen
97 >>>>>>> upstream/master
98 if alsabar._notify ~= nil then
99 alsabar._notify = naughty.notify ({
100 replaces_id = alsabar._notify.id,
104 alsabar._notify = naughty.notify ({
110 local function worker(args)
111 local args = args or {}
112 local timeout = args.timeout or 5
113 local settings = args.settings or function() end
114 local width = args.width or 63
115 local height = args.heigth or 1
116 local ticks = args.ticks or false
117 local ticks_size = args.ticks_size or 7
118 local vertical = args.vertical or false
120 alsabar.cmd = args.cmd or "amixer"
121 alsabar.channel = args.channel or alsabar.channel
122 alsabar.step = args.step or alsabar.step
123 alsabar.colors = args.colors or alsabar.colors
124 alsabar.notifications = args.notifications or alsabar.notifications
127 alsabar.followmouse = args.followmouse or false
128 >>>>>>> upstream/master
130 alsabar.bar = awful.widget.progressbar()
132 alsabar.bar:set_background_color(alsabar.colors.background)
133 alsabar.bar:set_color(alsabar.colors.unmute)
134 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
135 alsabar.bar:set_width(width)
136 alsabar.bar:set_height(height)
137 alsabar.bar:set_ticks(ticks)
138 alsabar.bar:set_ticks_size(ticks_size)
139 alsabar.bar:set_vertical(vertical)
141 function alsabar.update()
142 -- Get mixer control contents
144 local f = assert(io.popen(string.format("%s get %s", alsabar.cmd, alsabar.channel)))
145 local mixer = f:read("*a")
148 local mixer = read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.channel))
149 >>>>>>> upstream/master
151 -- Capture mixer control state: [5%] ... ... [on]
152 local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
159 alsabar._current_level = tonumber(volu)
160 alsabar.bar:set_value(alsabar._current_level / 100)
161 if not mute and tonumber(volu) == 0 or mute == "off"
163 alsabar._muted = true
164 alsabar.tooltip:set_text (" [Muted] ")
165 alsabar.bar:set_color(alsabar.colors.mute)
167 alsabar._muted = false
168 alsabar.tooltip:set_text(string.format(" %s:%s ", alsabar.channel, volu))
169 alsabar.bar:set_color(alsabar.colors.unmute)
173 volume_now.level = tonumber(volu)
174 volume_now.status = mute
178 alsabar.bar:buttons (awful.util.table.join (
179 awful.button ({}, 1, function()
180 awful.util.spawn(alsabar.mixer)
182 awful.button ({}, 3, function()
184 awful.util.spawn(string.format("amixer -c %s set %s toggle", alsabar.card, alsabar.channel))
187 awful.button ({}, 4, function()
188 awful.util.spawn(string.format("amixer -c %s set %s %s+", alsabar.card, alsabar.channel, alsabar.step))
191 awful.button ({}, 5, function()
192 awful.util.spawn(string.format("amixer -c %s set %s %s-", alsabar.card, alsabar.channel, alsabar.step))
194 awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.channel))
197 awful.button ({}, 4, function()
198 awful.util.spawn(string.format("%s set %s %s+", alsabar.cmd, alsabar.channel, alsabar.step))
201 awful.button ({}, 5, function()
202 awful.util.spawn(string.format("%s set %s %s-", alsabar.cmd, alsabar.channel, alsabar.step))
203 >>>>>>> upstream/master
208 timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
210 newtimer(timer_id, timeout, alsabar.update)
215 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })