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
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
background color once the battery discharges below 15% as follows:
Optionally, it can also have the `message` property that should be a string
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
widget.warning_config = {
@ -99,6 +103,7 @@ widget.warning_config = {
bg = "#FFFF00",
fg = "#000000",
},
message = "The battery is getting low",
}
```

View File

@ -69,12 +69,12 @@ local function update_icon(widget)
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 percentage = get_percentage()
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
naughty.destroy(
@ -158,7 +158,8 @@ local function update(widget)
maybe_warn(
widget,
get_percentage() <= widget.warning_config.percentage,
widget.warning_config.preset
widget.warning_config.preset,
widget.warning_config.message
)
end