]> git.madduck.net Git - etc/awesome.git/blobdiff - widget/bat.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

util.quake: revert previous commit; closes #415
[etc/awesome.git] / widget / bat.lua
index 9d5b9ae4655f675d43dae8ddc20e36be2a34d784..5a301b50a266c1680e4d2540ef43d6da2b1525d6 100644 (file)
@@ -6,47 +6,47 @@
 
 --]]
 
 
 --]]
 
-local helpers    = require("lain.helpers")
-local fs         = require("gears.filesystem")
-local naughty    = require("naughty")
-local wibox      = require("wibox")
-local math       = math
-local string     = string
-local ipairs     = ipairs
-local tonumber   = tonumber
+local helpers  = require("lain.helpers")
+local fs       = require("gears.filesystem")
+local naughty  = require("naughty")
+local wibox    = require("wibox")
+local math     = math
+local string   = string
+local ipairs   = ipairs
+local tonumber = tonumber
 
 -- Battery infos
 -- lain.widget.bat
 
 local function factory(args)
 
 -- Battery infos
 -- lain.widget.bat
 
 local function factory(args)
-    local bat       = { widget = wibox.widget.textbox() }
-    local args      = args or {}
-    local timeout   = args.timeout or 30
-    local notify    = args.notify or "on"
-    local n_perc    = args.n_perc or { 5, 15 }
-    local pspath    = args.pspath or "/sys/class/power_supply/"
-    local settings  = args.settings or function() end
+    local pspath = args.pspath or "/sys/class/power_supply/"
 
     if not fs.is_dir(pspath) then
         naughty.notify { text = "lain.widget.bat: invalid power supply path", timeout = 0 }
         return
     end
 
 
     if not fs.is_dir(pspath) then
         naughty.notify { text = "lain.widget.bat: invalid power supply path", timeout = 0 }
         return
     end
 
-    bat.batteries = args.batteries or (args.battery and {args.battery}) or {}
-    bat.ac        = args.ac
+    local bat       = { widget = wibox.widget.textbox() }
+    local args      = args or {}
+    local timeout   = args.timeout or 30
+    local notify    = args.notify or "on"
+    local n_perc    = args.n_perc or { 5, 15 }
+    local batteries = args.batteries or (args.battery and {args.battery}) or {}
+    local ac        = args.ac or "AC0"
+    local settings  = args.settings or function() end
 
     function bat.get_batteries()
         helpers.line_callback("ls -1 " .. pspath, function(line)
             local bstr =  string.match(line, "BAT%w+")
             if bstr then
 
     function bat.get_batteries()
         helpers.line_callback("ls -1 " .. pspath, function(line)
             local bstr =  string.match(line, "BAT%w+")
             if bstr then
-                bat.batteries[#bat.batteries + 1] = bstr
+                batteries[#batteries + 1] = bstr
             else
             else
-                bat.ac = string.match(line, "AC%w+") or "AC0"
+                ac = string.match(line, "A%w+") or "AC0"
             end
         end)
     end
 
             end
         end)
     end
 
-    if #bat.batteries == 0 then bat.get_batteries() end
+    if #batteries == 0 then bat.get_batteries() end
 
     bat_notification_critical_preset = {
         title   = "Battery exhausted",
 
     bat_notification_critical_preset = {
         title   = "Battery exhausted",
@@ -82,7 +82,7 @@ local function factory(args)
 
     bat_now.n_status = {}
     bat_now.n_perc   = {}
 
     bat_now.n_status = {}
     bat_now.n_perc   = {}
-    for i = 1, #bat.batteries do
+    for i = 1, #batteries do
         bat_now.n_status[i] = "N/A"
         bat_now.n_perc[i] = 0
     end
         bat_now.n_status[i] = "N/A"
         bat_now.n_perc[i] = 0
     end
@@ -98,7 +98,7 @@ local function factory(args)
         local sum_energy_now   = 0
         local sum_energy_full  = 0
 
         local sum_energy_now   = 0
         local sum_energy_full  = 0
 
-        for i, battery in ipairs(bat.batteries) do
+        for i, battery in ipairs(batteries) do
             local bstr    = pspath .. battery
             local present = helpers.first_line(bstr .. "/present")
 
             local bstr    = pspath .. battery
             local present = helpers.first_line(bstr .. "/present")
 
@@ -109,12 +109,12 @@ local function factory(args)
                 local rate_power   = tonumber(helpers.first_line(bstr .. "/power_now"))
 
                 -- energy_now(P)[uWh], charge_now(I)[uAh]
                 local rate_power   = tonumber(helpers.first_line(bstr .. "/power_now"))
 
                 -- energy_now(P)[uWh], charge_now(I)[uAh]
-                local energy_now        = tonumber(helpers.first_line(bstr .. "/energy_now") or
-                                          helpers.first_line(bstr .. "/charge_now"))
+                local energy_now = tonumber(helpers.first_line(bstr .. "/energy_now") or
+                                   helpers.first_line(bstr .. "/charge_now"))
 
                 -- energy_full(P)[uWh], charge_full(I)[uAh]
 
                 -- energy_full(P)[uWh], charge_full(I)[uAh]
-                local energy_full       = tonumber(helpers.first_line(bstr .. "/energy_full") or
-                                          helpers.first_line(bstr .. "/charge_full"))
+                local energy_full = tonumber(helpers.first_line(bstr .. "/energy_full") or
+                                    helpers.first_line(bstr .. "/charge_full"))
 
                 local energy_percentage = tonumber(helpers.first_line(bstr .. "/capacity")) or
                                           math.floor((energy_now / energy_full) * 100)
 
                 local energy_percentage = tonumber(helpers.first_line(bstr .. "/capacity")) or
                                           math.floor((energy_now / energy_full) * 100)