June 1, 2010 by Tomás Solar Castro
comments (0)
- Visitas: 2985
awesome, vicious, widget, icon, battery
I have "repaired" the previous code, now using the args given by the widget itself.
Commented the tooltip, and using a vicious batwidget instead obvious.battery, showing up acpi information when the cursor gets over it.
baticon = widget({ type = "imagebox" })
--baticon_t = awful.tooltip({ objects = { baticon }, })
--baticon.image = image(beautiful.baticon_bat1)
vicious.register(baticon, vicious.widgets.bat, function (widget, args)
-- baticon_t:set_text(args[1] .." ".. args[2].."% " .. args[3] )
local battery_status = ""
battery_status = args[1]
if not battery_status then
baticon.image = image(beautiful.widget_baticon_ac)
elseif args[1] == "-" then --battery_status == "discharging" thenif args[2] > 95 and args[2] <= 100 then
baticon.image = image(beautiful.widget_baticon_bat1)
elseif args[2] > 90 and args[2] < 95 then
baticon.image = image(beautiful.widget_baticon_bat2)
elseif args[2] >= 80 and args[2] < 90 then
baticon.image = image(beautiful.widget_baticon_bat3)
elseif args[2] >= 70 and args[2] < 80 then
baticon.image = image(beautiful.widget_baticon_bat3)
elseif args[2] >= 60 and args[2] < 70 then
baticon.image = image(beautiful.widget_baticon_bat4)
elseif args[2] >= 50 and args[2] < 60 then
baticon.image = image(beautiful.widget_baticon_bat5)
elseif args[2] >= 40 and args[2] < 50 then
baticon.image = image(beautiful.widget_baticon_bat6)
elseif args[2] >= 30 and args[2] < 40 then
baticon.image = image(beautiful.widget_baticon_bat7)
elseif args[2] >= 20 and args[2] < 30 then
baticon.image = image(beautiful.widget_baticon_bat8)
elseif args[2] >= 10 and args[2] < 20 then
baticon.image = image(beautiful.widget_baticon_bat9)
elseif args[2] > 5 and args[2] < 10 then
baticon.image = image(beautiful.widget_baticon_bat10)elseif args[2] <= 5 then
baticon.image = image(beautiful.widget_baticon_bat11)
endelseif args[1] == "+" then--battery_status == "charging" then
if args[2] > 95 and args[2] <= 100 then
baticon.image = image(beautiful.widget_baticon_char1)
elseif args[2] > 90 and args[2] < 95 then
baticon.image = image(beautiful.widget_baticon_char2)
elseif args[2] >= 80 and args[2] < 90 then
baticon.image = image(beautiful.widget_baticon_char3)
elseif args[2] >= 70 and args[2] < 80 then
baticon.image = image(beautiful.widget_baticon_char3)
elseif args[2] >= 60 and args[2] < 70 then
baticon.image = image(beautiful.widget_baticon_char4)
elseif args[2] >= 50 and args[2] < 60 then
baticon.image = image(beautiful.widget_baticon_char5)
elseif args[2] >= 40 and args[2] < 50 then
baticon.image = image(beautiful.widget_baticon_char6)
elseif args[2] >= 30 and args[2] < 40 then
baticon.image = image(beautiful.widget_baticon_char7)
elseif args[2] >= 20 and args[2] < 30 then
baticon.image = image(beautiful.widget_baticon_char8)
elseif args[2] >= 10 and args[2] < 20 then
baticon.image = image(beautiful.widget_baticon_char9)
elseif args[2] > 5 and args[2] < 10 then
baticon.image = image(beautiful.widget_baticon_char10)elseif args[2] <= 5 then
baticon.image = image(beautiful.widget_baticon_char10)
end
elseif args[1] == "↯" then
baticon.image = image(beautiful.widget_baticon_ac)end
if args[1] == "⌁" then --battery_present == '0' then
baticon.image = image(beautiful.widget_baticon_ac)
end
end,
1, "BAT0")batwidget = widget({ type = "textbox" })
vicious.register(batwidget, vicious.widgets.bat, "$2% $3", 61, "BAT0")
batwidget:add_signal('mouse::enter', function()
local fd = nil
fd = io.popen("acpi -btai")
local d = fd:read("*all"):gsub("\n+$", "")
fd:close()
batinfo = {
naughty.notify({
text = d
, timeout = 0
, position = "bottom_right"
})
}
end)batwidget:add_signal('mouse::leave', function () naughty.destroy(batinfo[1]) end)
Hope this help.
Happy Hacking!
