2013-03-12 00:32:44 +04:00
|
|
|
|
local awful = require("awful")
|
|
|
|
|
local wibox = require("wibox")
|
|
|
|
|
local beautiful = require("beautiful")
|
|
|
|
|
local vicious = require("vicious")
|
|
|
|
|
local naughty = require("naughty")
|
|
|
|
|
|
2014-08-15 22:08:09 +04:00
|
|
|
|
----< Battery >-------------------------------------------------------
|
|
|
|
|
--
|
2013-03-12 00:32:44 +04:00
|
|
|
|
local bat_state = ""
|
|
|
|
|
local bat_charge = 0
|
|
|
|
|
local bat_time = 0
|
|
|
|
|
local blink = true
|
|
|
|
|
baticon = wibox.widget.imagebox()
|
|
|
|
|
baticon:set_image(beautiful.widget_batfull)
|
|
|
|
|
|
|
|
|
|
-- Charge %
|
|
|
|
|
batpct = wibox.widget.textbox()
|
|
|
|
|
vicious.register(batpct, vicious.widgets.bat, function(widget, args)
|
|
|
|
|
bat_state = args[1]
|
|
|
|
|
bat_charge = args[2]
|
|
|
|
|
bat_time = args[3]
|
|
|
|
|
|
2015-07-24 20:12:00 +03:00
|
|
|
|
if args[1] == "−" then
|
2013-03-12 00:32:44 +04:00
|
|
|
|
if bat_charge > 70 then
|
|
|
|
|
baticon:set_image(beautiful.widget_batfull)
|
|
|
|
|
elseif bat_charge > 30 then
|
|
|
|
|
baticon:set_image(beautiful.widget_batmed)
|
|
|
|
|
elseif bat_charge > 10 then
|
|
|
|
|
baticon:set_image(beautiful.widget_batlow)
|
|
|
|
|
else
|
|
|
|
|
baticon:set_image(beautiful.widget_batempty)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
baticon:set_image(beautiful.widget_ac)
|
|
|
|
|
if args[1] == "+" then
|
|
|
|
|
blink = not blink
|
|
|
|
|
if blink then
|
|
|
|
|
baticon:set_image(beautiful.widget_acblink)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return args[2] .. "% "
|
|
|
|
|
end, nil, "BAT0")
|
|
|
|
|
|
|
|
|
|
function popup_bat()
|
|
|
|
|
local state = ""
|
|
|
|
|
if bat_state == "↯" then
|
|
|
|
|
state = "Full"
|
|
|
|
|
elseif bat_state == "↯" then
|
|
|
|
|
state = "Charged"
|
|
|
|
|
elseif bat_state == "+" then
|
|
|
|
|
state = "Charging"
|
|
|
|
|
elseif bat_state == "-" then
|
|
|
|
|
state = "Discharging"
|
|
|
|
|
elseif bat_state == "⌁" then
|
|
|
|
|
state = "Not charging"
|
|
|
|
|
else
|
|
|
|
|
state = "Unknown"
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
naughty.notify { text = "Charge : " .. bat_charge .. "%\nState : " .. state ..
|
|
|
|
|
" (" .. bat_time .. ")", timeout = 5, hover_timeout = 0.5 }
|
|
|
|
|
end
|
2017-02-20 13:09:11 +03:00
|
|
|
|
function show_powertop ()
|
|
|
|
|
os.execute ("pgrep powertop || urxvt -e sudo powertop &")
|
|
|
|
|
end
|
|
|
|
|
batpct:buttons(awful.util.table.join(awful.button({ }, 1, popup_bat), awful.button({ }, 3, show_powertop)))
|
2013-03-12 00:32:44 +04:00
|
|
|
|
baticon:buttons(batpct:buttons())
|