Update volume widget for awesome 3.5

This commit is contained in:
Guillaume Dott 2013-01-12 19:00:15 +01:00
parent 145074b38c
commit e975b5cfff

View File

@ -1,10 +1,10 @@
local awful = awful local awful = require("awful")
local beautiful = beautiful local wibox = require("wibox")
local widget = widget local beautiful = require("beautiful")
local timer = timer local timer = timer
local string = string local string = string
local tonumber = tonumber local tonumber = tonumber
local image = image
local os = { local os = {
getenv = os.getenv, getenv = os.getenv,
execute = os.execute execute = os.execute
@ -16,11 +16,10 @@ local io = {
local table = { local table = {
insert = table.insert insert = table.insert
} }
module("iniquitous.volume") local volume_widget = {}
local img = widget({ type = "imagebox" }) local img = nil
local tb = widget({ type = "textbox" }) local tb = nil
tb.text = "N/A%"
local initialized = false local initialized = false
@ -37,7 +36,10 @@ local value = nil
local vol = 0 local vol = 0
function init(a_mode, a_channel) function volume_widget.init(a_mode, a_channel)
img = wibox.widget.imagebox()
tb = wibox.widget.textbox("N/A%")
mode = a_mode mode = a_mode
channel = a_channel channel = a_channel
@ -59,23 +61,23 @@ function init(a_mode, a_channel)
initialized = true initialized = true
end end
volume(display) volume_widget.volume(display)
local but = awful.util.table.join( local but = awful.util.table.join(
awful.button({ }, 3, function () volume("mute") end), awful.button({ }, 3, function () volume_widget.volume("mute") end),
awful.button({ }, 4, function () volume("up") end), awful.button({ }, 4, function () volume_widget.volume("up") end),
awful.button({ }, 5, function () volume("down") end) awful.button({ }, 5, function () volume_widget.volume("down") end)
) )
tb:buttons(but) tb:buttons(but)
img:buttons(but) img:buttons(but)
local timer = timer { timeout = 7 } local timer = timer { timeout = 7 }
timer:add_signal("timeout", function() volume("display") end) timer:connect_signal("timeout", function() volume_widget.volume("display") end)
timer:start() timer:start()
end end
function volume(mode) function volume_widget.volume(mode)
if mode == "up" then if mode == "up" then
os.execute(up .. " >/dev/null") os.execute(up .. " >/dev/null")
elseif mode == "down" then elseif mode == "down" then
@ -113,13 +115,15 @@ function display(volume)
else else
vol_lvl = "high" vol_lvl = "high"
end end
img.image = image(beautiful["vol_" .. vol_lvl]) img:set_image(beautiful["vol_" .. vol_lvl])
tb.text = volume .."%" tb:set_text(volume .."%")
end end
function textbox() function volume_widget.textbox()
return tb return tb
end end
function imagebox() function volume_widget.imagebox()
return img return img
end end
return volume_widget