From: Samir Benmendil Date: Thu, 13 Jun 2013 01:40:16 +0000 (+0200) Subject: add battery widget X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/ea12a46a4ecb2168327dda544b2f212abdb5147e?hp=fb979e3bd94acecee103c9a6ff759bbee635691c add battery widget --- diff --git a/awesome/topbar.lua b/awesome/topbar.lua index 58c0195..c18303b 100644 --- a/awesome/topbar.lua +++ b/awesome/topbar.lua @@ -3,6 +3,7 @@ local wibox = require("wibox") -- my widgets local volume_widget = require("widgets/volume_widget") +local battery_widget = require("widgets/battery_widget") -- Create a textclock widget mytextclock = awful.widget.textclock() @@ -87,6 +88,7 @@ for s = 1, screen.count() do local right_layout = wibox.layout.fixed.horizontal() if s == 1 then right_layout:add(wibox.widget.systray()) end right_layout:add(volume_widget) + right_layout:add(battery_widget) right_layout:add(mytextclock) right_layout:add(mylayoutbox[s]) diff --git a/awesome/widgets/battery_widget.lua b/awesome/widgets/battery_widget.lua new file mode 100644 index 0000000..6215bab --- /dev/null +++ b/awesome/widgets/battery_widget.lua @@ -0,0 +1,66 @@ +local wibox = require("wibox") +local vicious = require("vicious") +local naughty = require("naughty") +local beautiful = require("beautiful") +local pairs = pairs + +module("battery_widget") + +-- Battery (based on https://bitbucket.org/skrattaren/awesome/src/) + +local limits = { {25, 5}, + {12, 3}, + { 7, 1}, + {0}} + +local function getnextlim (num) + for ind, pair in pairs(limits) do + lim = pair[1]; step = pair[2]; nextlim = limits[ind+1][1] or 0 + if num > nextlim then + repeat + lim = lim - step + until num > lim + if lim < nextlim then + lim = nextlim + end + return lim + end + end +end + +local function batclosure () + local nextlim = limits[1][1] + return function (_, args) + local prefix = "⚡" + local state, charge = args[1], args[2] + if not charge then return end + if state == "-" then + dirsign = "↓" + prefix = "Bat:" + if charge <= nextlim then + naughty.notify({title = "⚡ Warning! ⚡", + text = "Battery has leaked most of its power ( ⚡ " + ..charge.."%)!", + timeout = 7, + position = "bottom_right", + fg = beautiful.fg_focus, + bg = beautiful.bg_focus + }) + nextlim = getnextlim(charge) + end + elseif state == "+" then + dirsign = "↑" + nextlim = limits[1][1] + else + return " ⚡ " + end + if dir ~= 0 then charge = charge.."%" end + return " "..prefix.." "..dirsign..charge..dirsign.." " + end +end + +batterywidget = wibox.widget.textbox() +vicious.register(batterywidget, vicious.widgets.bat, batclosure(), + 31, "BAT0") + +return batterywidget