diff options
author | wiltonloch <wilton.loch@gmail.com> | 2022-09-17 11:44:26 +0200 |
---|---|---|
committer | zachir <zachir@librem.one> | 2023-10-19 08:22:37 -0500 |
commit | 4374b2a5b4d73958847572eaa12e7643c7f48482 (patch) | |
tree | 193fb5bb0452198dad3aa931e6595f4171aedbe9 | |
parent | 7af31e151d0219a60b408913783056caee1f8392 (diff) |
Adding a parameter to allow the right mouse button to always set the
brightness level to maximum, instead of the default toggle behavior.
-rw-r--r-- | brightness-widget/README.md | 1 | ||||
-rw-r--r-- | brightness-widget/brightness.lua | 27 |
2 files changed, 17 insertions, 11 deletions
diff --git a/brightness-widget/README.md b/brightness-widget/README.md index 0cdb774..f10adb3 100644 --- a/brightness-widget/README.md +++ b/brightness-widget/README.md @@ -17,6 +17,7 @@ It is possible to customize widget by providing a table with all or some of the | `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 | | `percentage` | false | Display a '%' character after the brightness level | +| `rmb_set_max` | false | Right mouse click sets the brightness level to maximum | _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). diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index affaf47..bf79b75 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -46,6 +46,7 @@ local function worker(user_args) local current_level = 0 -- current brightness value local tooltip = args.tooltip or false local percentage = args.percentage or false + local rmb_set_max = args.rmb_set_max or false if program == 'light' then get_brightness_cmd = 'light -G' set_brightness_cmd = 'light -S %d' -- <level> @@ -136,19 +137,23 @@ local function worker(user_args) end local old_level = 0 function brightness_widget:toggle() - if old_level < 0.1 then - -- avoid toggling between '0' and 'almost 0' - old_level = 1 - end - if current_level < 0.1 then - -- restore previous level - current_level = old_level + if rmb_set_max then + brightness_widget:set(100) else - -- save current brightness for later - old_level = current_level - current_level = 0 + if old_level < 0.1 then + -- avoid toggling between '0' and 'almost 0' + old_level = 1 + end + if current_level < 0.1 then + -- restore previous level + current_level = old_level + else + -- save current brightness for later + old_level = current_level + current_level = 0 + end + brightness_widget:set(current_level) end - brightness_widget:set(current_level) end function brightness_widget:inc() spawn.easy_async(inc_brightness_cmd, function() |