Merge pull request #329 from augustogunsch/master

Add option 'percentage' for brightness widget
This commit is contained in:
streetturtle 2022-02-12 16:50:44 -05:00 committed by GitHub
commit b138b2480a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@ It is possible to customize widget by providing a table with all or some of the
| `font` | `Play 9` | Font | | `font` | `Play 9` | Font |
| `timeout` | 1 | How often in seconds the widget refreshes. Check the note below | | `timeout` | 1 | How often in seconds the widget refreshes. Check the note below |
| `tooltip` | false | Display brightness level in a tooltip when the mouse cursor hovers the widget | | `tooltip` | false | Display brightness level in a tooltip when the mouse cursor hovers the widget |
| `percentage` | false | Display a '%' character after the brightness level |
_Note:_ If brightness is controlled only by the widget (either by a mouse, or by a shortcut, then the `timeout` could be quite big, as there is no reason to synchronize the brightness level). _Note:_ If brightness is controlled only by the widget (either by a mouse, or by a shortcut, then the `timeout` could be quite big, as there is no reason to synchronize the brightness level).

View File

@ -43,6 +43,7 @@ local function worker(user_args)
local base = args.base or 20 local base = args.base or 20
local current_level = 0 -- current brightness value local current_level = 0 -- current brightness value
local tooltip = args.tooltip or false local tooltip = args.tooltip or false
local percentage = args.percentage or false
if program == 'light' then if program == 'light' then
get_brightness_cmd = 'light -G' get_brightness_cmd = 'light -G'
set_brightness_cmd = 'light -S %d' -- <level> set_brightness_cmd = 'light -S %d' -- <level>
@ -82,7 +83,11 @@ local function worker(user_args)
spacing = 4, spacing = 4,
layout = wibox.layout.fixed.horizontal, layout = wibox.layout.fixed.horizontal,
set_value = function(self, level) set_value = function(self, level)
self:get_children_by_id('txt')[1]:set_text(level .. '%') local display_level = level
if percentage then
display_level = display_level .. '%'
end
self:get_children_by_id('txt')[1]:set_text(display_level)
end end
} }
elseif type == 'arc' then elseif type == 'arc' then