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 newtimer = require("lain.helpers").newtimer
11 local awful = require("awful")
12 local beautiful = require("beautiful")
13 local naughty = require("naughty")
16 local math = { modf = math.modf }
17 local string = { match = string.match,
19 local tonumber = tonumber
21 local setmetatable = setmetatable
24 -- lain.widgets.alsabar
32 background = beautiful.bg_normal,
37 terminal = terminal or "xterm",
38 mixer = terminal .. " -e alsamixer",
42 font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
44 color = beautiful.fg_focus,
45 bar_size = 18 -- Awesome default
52 function alsabar:notify()
55 title = "", text = "",
57 font = alsabar.notifications.font .. " " .. alsabar.notifications.font_size,
58 fg = alsabar.notifications.color
61 if alsabar._muted then
62 preset.title = alsabar.channel .. " - Muted"
64 preset.title = alsabar.channel .. " - " .. alsabar._current_level * 100 .. "%"
67 local int = math.modf(alsabar._current_level * alsabar.notifications.bar_size)
68 preset.text = "[" .. string.rep("|", int)
69 .. string.rep(" ", alsabar.notifications.bar_size - int) .. "]"
71 if alsabar._notify ~= nil then
72 alsabar._notify = naughty.notify ({ replaces_id = alsabar._notify.id,
75 alsabar._notify = naughty.notify ({ preset = preset })
79 local function worker(args)
80 local args = args or {}
81 local width = args.width or 63
82 local height = args.heigth or 1
83 local ticks = args.ticks or true
84 local ticks_size = args.ticks_size or 7
85 local vertical = args.vertical or false
86 alsabar.channel = args.channel or alsabar.channel
87 alsabar.step = args.step or alsabar.step
88 alsabar.colors = args.colors or alsabar.colors
89 alsabar.notifications = args.notifications or alsabar.notifications
91 alsabar.bar = awful.widget.progressbar()
93 alsabar.bar:set_background_color(alsabar.colors.background)
94 alsabar.bar:set_color(alsabar.colors.unmute)
95 alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
96 alsabar.bar:set_width(width)
97 alsabar.bar:set_height(height)
98 alsabar.bar:set_ticks(ticks)
99 alsabar.bar:set_ticks_size(ticks_size)
102 alsabar.bar:set_vertical(true)
106 -- Get mixer control contents
107 local f = io.popen("amixer get " .. alsabar.channel)
108 local mixer = f:read("*all")
111 -- Capture mixer control state: [5%] ... ... [on]
112 local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
119 alsabar._current_level = tonumber(volu) / 100
120 alsabar.bar:set_value(alsabar._current_level)
122 if mute == "" and volu == "0" or mute == "off"
124 alsabar._muted = true
125 alsabar.tooltip:set_text (" [Muted] ")
126 alsabar.bar:set_color(alsabar.colors.mute)
128 alsabar._muted = false
129 alsabar.tooltip:set_text(" " .. alsabar.channel .. ": " .. volu .. "% ")
130 alsabar.bar:set_color(alsabar.colors.unmute)
134 newtimer("alsabar", 5, update)
136 alsabar.bar:buttons (awful.util.table.join (
137 awful.button ({}, 1, function()
138 awful.util.spawn(alsabar.mixer)
140 awful.button ({}, 3, function()
141 awful.util.spawn("amixer sset " .. alsabar.channel .. " toggle")
144 awful.button ({}, 4, function()
145 awful.util.spawn("amixer sset " .. alsabar.channel .. " "
146 .. alsabar.step .. "+")
149 awful.button ({}, 5, function()
150 awful.util.spawn("amixer sset " .. alsabar.channel .. " "
151 .. alsabar.step .. "-")
157 widget = alsabar.bar,
158 channel = alsabar.channel,
167 return setmetatable(alsabar, { __call = function(_, ...) return worker(...) end })