Go to file
Aire-One bbb82ae80a Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00
doc Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00
.gitignore Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00
README.md Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00
config.ld Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00
init.lua Add ldoc config to generate API documentation. 2020-01-23 11:42:44 +01:00

README.md

UPower Battery Widget

This is my re-implementation of the awesome-upower-battery by berlam. This widget has a lot of potencial for the Awesome WM and I wanted to hack it a bit for my personal use.

UPower is an abstraction for power devices. You can use it to access advanced statistics about your power devices. UPowerGlib is a Glib interface to access data exposed by UPower. The Awesome WM uses LGI as an interpolation layer for Glib with Lua. So, you can access the UPowerGlib interface directly from your lua code.

Thanks to this, we can write battery widget relaying on realtime data pushed from the UPower daemon itself. So the battery widget as no charge on the system (no need to pull data every X seconds) and provides more accurate data to the user.

Usage

When creating an instance of this widget, you can specify the widget_template you want to use and how the widget updates. It gives you the control on how the widget should display the battery status.

You can generate the API documentation with ldoc.

ldoc -c config.ld init.lua

Here is an example of implementation using a wibox.widget.textbox widget to display the battery percentage:

-- Load the module:
local battery_widget = require 'battery_widget'

-- Create the battery widget:
local my_battery_widget = battery_widget {
    screen = screen,
    use_display_device = true,
    widget_template = wibox.widget.textbox
}

-- When UPower updates the battery status, the widget is notified
-- and calls a signal you need to connect to:
my_battery_widget:connect_signal('upower::update', function (widget, device)
    widget.text = string.format('%3d', device.percentage) .. '%'
end)

Using different devices

With the parameter use_display_device = true, the battery widget will automatically monitor the display device.

If you want to manually set which device to monitor, you can use the device_path parameter.

local my_battery_widget = battery_widget{
    screen = s,
    device_path = '/org/freedesktop/UPower/devices/battery_BAT0',
    widget_template = wibox.widget.textbox
}

You can check the API documentation to read more about statics function to help you to identify your devices.

Dependencies

Acknowledgment

Thanks a lot to berlam for the initial code and the idea to use the UPowerGlib interface 🚀.