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
9 local awful = require("awful")
10 local beautiful = require("beautiful")
11 local naughty = require("naughty")
14 local math = { modf = math.modf }
15 local string = { match = string.match,
17 local tonumber = tonumber
19 local setmetatable = setmetatable
22 -- lain.widgets.alsabar
30 background = beautiful.bg_normal,
35 mixer = terminal .. " -e alsamixer",
39 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
41 bar_size = 18 -- Awesome default
48 function alsabar:notify()
51 title = "", text = "",
53 font = alsabar.notifications.font .. " " .. alsabar.notifications.font_size,
54 fg = beautiful.fg_focus
57 if alsabar._muted then
58 preset.title = alsabar.channel .. " - Muted"
60 preset.title = alsabar.channel .. " - " .. alsabar._current_level * 100 .. "%"
63 local int = math.modf(alsabar._current_level * alsabar.notifications.bar_size)
64 preset.text = "[" .. string.rep("|", int)
65 .. string.rep(" ", alsabar.notifications.bar_size - int) .. "]"
67 if alsabar._notify ~= nil then
68 alsabar._notify = naughty.notify ({ replaces_id = alsabar._notify.id,
71 alsabar._notify = naughty.notify ({ preset = preset })
76 local args = args or {}
77 local width = args.width or 63
78 local height = args.heigth or 1
79 local ticks = args.ticks or true
80 local ticks_size = args.ticks_size or 7
81 local vertical = args.vertical or false
82 alsabar.channel = args.channel or alsabar.channel
83 alsabar.step = args.step or alsabar.step
84 alsabar.colors = args.colors or alsabar.colors
85 alsabar.notifications = args.notifications or alsabar.notifications
87 alsabar.bar = awful.widget.progressbar()
88 alsabar.bar:set_background_color(alsabar.colors.background)
89 alsabar.bar:set_color(alsabar.colors.unmute)
90 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
91 alsabar.bar:set_width(width)
92 alsabar.bar:set_height(height)
93 alsabar.bar:set_ticks(ticks)
94 alsabar.bar:set_ticks_size(ticks_size)
97 alsabar.bar:set_vertical(true)
100 local myvolumebarupdate = function()
101 -- Get mixer control contents
102 local f = io.popen("amixer get " .. alsabar.channel)
103 local mixer = f:read("*all")
106 -- Capture mixer control state: [5%] ... ... [on]
107 local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
108 -- Handle mixers without data
114 alsabar._current_level = tonumber(volu) / 100
115 alsabar.bar:set_value(alsabar._current_level)
117 if mute == "" and volu == "0" or mute == "off"
119 alsabar._muted = true
120 alsabar.tooltip:set_text (" [Muted] ")
121 alsabar.bar:set_color(alsabar.colors.mute)
123 alsabar._muted = false
124 alsabar.tooltip:set_text(" " .. alsabar.channel .. ": " .. volu .. "% ")
125 alsabar.bar:set_color(alsabar.colors.unmute)
129 local myvolumebartimer = timer({ timeout = 5 })
130 myvolumebartimer:connect_signal("timeout", myvolumebarupdate)
131 myvolumebartimer:start()
132 myvolumebartimer:emit_signal("timeout")
134 alsabar.bar:buttons (awful.util.table.join (
135 awful.button ({}, 1, function()
136 awful.util.spawn(alsabar.mixer)
138 awful.button ({}, 3, function()
139 awful.util.spawn("amixer sset " .. alsabar.channel .. " toggle")
142 awful.button ({}, 4, function()
143 awful.util.spawn("amixer sset " .. alsabar.channel .. " "
144 .. alsabar.step .. "+")
147 awful.button ({}, 5, function()
148 awful.util.spawn("amixer sset " .. alsabar.channel .. " "
149 .. alsabar.step .. "-")
154 return { widget = alsabar.bar,
155 channel = alsabar.channel,
164 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })