Add option to use custom message in warning

This commit is contained in:
Stefano Mazzucco 2019-12-16 21:30:26 +00:00
parent d149972d2e
commit 402ad1bddf
2 changed files with 11 additions and 5 deletions

View File

@ -89,8 +89,12 @@ It **must** contain the following properties:
- `preset`: a [naughty preset - `preset`: a [naughty preset
table](https://awesomewm.org/doc/api/libraries/naughty.html#config.presets) table](https://awesomewm.org/doc/api/libraries/naughty.html#config.presets)
For example, one could ad a warning with a black foreground color and yellow Optionally, it can also have the `message` property that should be a string
background color once the battery discharges below 15% as follows: with a custom warning message.
For example, one could add a warning with a custom message, a black foreground
color and yellow background color once the battery discharges below 15% as
follows:
``` lua ``` lua
widget.warning_config = { widget.warning_config = {
@ -99,6 +103,7 @@ widget.warning_config = {
bg = "#FFFF00", bg = "#FFFF00",
fg = "#000000", fg = "#000000",
}, },
message = "The battery is getting low",
} }
``` ```

View File

@ -69,12 +69,12 @@ local function update_icon(widget)
end end
end end
local function maybe_warn(widget, warning_condition, notification_preset) local function maybe_warn(widget, warning_condition, notification_preset, message)
local warning_level = device.warninglevel or "None" local warning_level = device.warninglevel or "None"
local percentage = get_percentage() local percentage = get_percentage()
if warning_condition then if warning_condition then
local msg = (warning_level.name == "None" and "Low" or warning_level.name) .. " battery!" local msg = message or (warning_level.name == "None" and "Low" or warning_level.name) .. " battery!"
if notification then if notification then
naughty.destroy( naughty.destroy(
@ -158,7 +158,8 @@ local function update(widget)
maybe_warn( maybe_warn(
widget, widget,
get_percentage() <= widget.warning_config.percentage, get_percentage() <= widget.warning_config.percentage,
widget.warning_config.preset widget.warning_config.preset,
widget.warning_config.message
) )
end end