Skip to content
lua function to get a formatted string with the current battery status. Can be used to fill a text widget in the awesome window manager.
Branch: master
Clone or download
koenwtje
koenwtje Merge pull request #12 from yejingchen/close-fh
Fix "too many open files" bug on awesome 4.0
Latest commit 08ed22a Feb 18, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.mkd Add required parameter "BAT0" to batteryInfo call in example. Jun 7, 2015
battery.lua Fix "too many open files" bug on awesome 4.0 Feb 18, 2017

README.mkd

awesome-batteryInfo

This is a small lua function that returns a formatted string with the current battery status. It can be used to populate a text widget in the awesome window manager. Based on the "Gigamo Battery Widget" found in the wiki at awesome.naquadah.org

Usage

Place the battery.lua file in the same directory as your main config file (e.g. rc.lua), and require it:

awesome < 3.5

  require("battery")

awesome >= 3.5

  local battery = require("battery")

Add a textbox to your wibox that will contain your battery status:

awesome < 3.5

  batterywidget = widget({type = "textbox", name = "batterywidget", align = "right" })
  (...)
  mytextclock,
  batterywidget,
  s == 1 and mysystray or nil,
  (...)

awesome >= 3.5

  batterywidget = wibox.widget.textbox()
  (...)
  local right_layout = wibox.layout.fixed.horizontal()
  right_layout:add(batterywidget)
  if s == 1 then right_layout:add(wibox.widget.systray()) end
  (...)

Add a hook that will update the widget every so often:

awesome < 3.5

  awful.hooks.timer.register(60, function()
    batterywidget.text = batteryInfo("BAT0")
  end)

awesome >= 3.5

  batterywidget_timer = timer({timeout = 1})
  batterywidget_timer:connect_signal("timeout", function()
    batterywidget:set_text(batteryInfo("BAT0"))
  end)
  batterywidget_timer:start()

If you don't want to wait for the battery status to appear until the function gets called by the hook, add the following somewhere after the declaration of the batterywidget.

awesome < 3.5

  batterywidget.text = batteryInfo("BAT0")

awesome >= 3.5

  batterywidget:set_text(batteryInfo("BAT0"))
You can’t perform that action at this time.