Add a setting for critical battery level and default it to 5%

Some batteries do not set their levels, so we need a way to tell the widget to
display a "low battery" warning.
This commit is contained in:
Stefano Mazzucco 2018-07-03 07:10:50 +01:00
parent 388186cc28
commit 6844a9d3c0
3 changed files with 41 additions and 3 deletions

View File

@ -68,6 +68,9 @@ This can be done by changing the `gui_client` field of the widget. The default
is to have no client. For example, you could use the [XFCE4 Power Manager](http://goodies.xfce.org/projects/applications/xfce4-power-manager)
or the [GNOME one](https://projects.gnome.org/gnome-power-manager/).
You can set the critical battery percentage at which a warning will be
displayed using the `critical_percentage` property (defaults to `5`).
# Mouse controls
When the widget is focused:
@ -88,8 +91,10 @@ Require the module:
-- require *after* `beautiful.init` or the theme will be inconsistent!
local power = require("power_widget")
-- override the GUI client.
power:init()
power.gui_client = "xfce4-power-manager"
-- override the critical battery percentage
power.critical_percentage = 18
power:init()
```
Add the widget to your layout:

View File

@ -33,6 +33,7 @@ icon_theme_dirs = beautiful.upower_icon_theme_dirs or icon_theme_dirs
icon_theme_extensions = beautiful.upower_icon_theme_extension or icon_theme_extensions
local widget = wibox.widget.imagebox()
widget.critical_percentage = 5
local function build_icon_path(device)
if device.IconName then
@ -54,10 +55,15 @@ function widget:update()
self.tooltip:set_text(
percentage .. "%" .. " - " .. self.device.state.name)
if warning_level == WarningLevel.Low or warning_level == WarningLevel.Critical then
if (
percentage <= self.critical_percentage
or warning_level == WarningLevel.Low
or warning_level == WarningLevel.Critical
) then
local msg = (warning_level.name == "None" and "Low" or warning_level.name) .. " battery!"
naughty.notify({
preset = naughty.config.presets.critical,
title = warning_level.name .. " battery!",
title = msg,
text = percentage .. "% remaining"})
end
else

View File

@ -0,0 +1,27 @@
package = "power_widget"
version = "0.3.4-1"
source = {
url = "git://github.com/stefano-m/awesome-power_widget",
tag = "v0.3.4"
}
description = {
summary = "A Power widget for the Awesome Window Manager",
detailed = [[
Monitor your power devices in Awesome with UPower and DBus.
]],
homepage = "https://github.com/stefano-m/awesome-power_widget",
license = "GPL v3"
}
supported_platforms = {
"linux"
}
dependencies = {
"lua >= 5.1",
"upower_dbus >= 0.3.0, < 0.4"
}
build = {
type = "builtin",
modules = {
power_widget = "power_widget.lua"
}
}