From 4cbacd910b2621139cfd1fb6d61cc764e5eb9fd3 Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Thu, 15 Apr 2021 21:57:28 +0100 Subject: brightness-widget: remove sh wrapper not needed --- brightness-widget/brightness.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index 2afb38a..fed6a91 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -40,9 +40,9 @@ local function worker(user_args) local program = args.program or 'light' local step = args.step or 5 if program == 'light' then - get_brightness_cmd = 'sh -c "light -G"' - inc_brightness_cmd = 'sh -c "light -A ' .. step .. '"' - dec_brightness_cmd = 'sh -c "light -U ' .. step .. '"' + get_brightness_cmd = 'light -G' + inc_brightness_cmd = 'light -A ' .. step + dec_brightness_cmd = 'light -U ' .. step elseif program == 'xbacklight' then get_brightness_cmd = 'xbacklight -get' inc_brightness_cmd = 'xbacklight -inc ' .. step -- cgit v1.2.3 From c340f49ae57d012f504da3e9b40af905130b49a2 Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Thu, 15 Apr 2021 22:01:12 +0100 Subject: brightness-widget: support left click sets brightness to "base" level --- brightness-widget/README.md | 1 + brightness-widget/brightness.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/brightness-widget/README.md b/brightness-widget/README.md index 5428029..5b1a23a 100644 --- a/brightness-widget/README.md +++ b/brightness-widget/README.md @@ -11,6 +11,7 @@ It is possible to customize widget by providing a table with all or some of the | `type`| `arc` | The widget type. Could be `arc` or `icon_and_text` | | `program` | `light` | The program used to control the brightness, either 'light' or 'xbacklight'. | | `step` | 5 | Step | +| `base` | 20 | Base level to set brightness to on left click. | | `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon | | `font` | `Play 9` | Font | | `timeout` | 1 | How often in seconds the widget refreshes. Check the note below | diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index fed6a91..052c56b 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -16,6 +16,7 @@ local naughty = require("naughty") local ICON_DIR = os.getenv("HOME") .. '/.config/awesome/awesome-wm-widgets/brightness-widget/' local get_brightness_cmd +local set_brightness_cmd local inc_brightness_cmd local dec_brightness_cmd @@ -39,12 +40,15 @@ local function worker(user_args) local program = args.program or 'light' local step = args.step or 5 + local base = args.base or 20 if program == 'light' then get_brightness_cmd = 'light -G' + set_brightness_cmd = 'light -S ' -- inc_brightness_cmd = 'light -A ' .. step dec_brightness_cmd = 'light -U ' .. step elseif program == 'xbacklight' then get_brightness_cmd = 'xbacklight -get' + set_brightness_cmd = 'xbacklight -set ' -- inc_brightness_cmd = 'xbacklight -inc ' .. step dec_brightness_cmd = 'xbacklight -dec ' .. step else @@ -107,6 +111,13 @@ local function worker(user_args) widget:set_value(brightness_level) end + function brightness_widget:set(value) + spawn.easy_async(set_brightness_cmd .. value, function() + spawn.easy_async(get_brightness_cmd, function(out) + update_widget(brightness_widget.widget, out) + end) + end) + end function brightness_widget:inc() spawn.easy_async(inc_brightness_cmd, function() spawn.easy_async(get_brightness_cmd, function(out) @@ -124,6 +135,7 @@ local function worker(user_args) brightness_widget.widget:buttons( awful.util.table.join( + awful.button({}, 1, function() brightness_widget:set(base) end), awful.button({}, 4, function() brightness_widget:inc() end), awful.button({}, 5, function() brightness_widget:dec() end) ) -- cgit v1.2.3 From ce1af8e6072464112e792829565d8b922122e265 Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Thu, 15 Apr 2021 22:38:19 +0100 Subject: brightness-widget: support right click toggles brightness between current level and 0 --- brightness-widget/brightness.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index 052c56b..f222adc 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -41,6 +41,7 @@ local function worker(user_args) local program = args.program or 'light' local step = args.step or 5 local base = args.base or 20 + local level = 0 -- current brightness value if program == 'light' then get_brightness_cmd = 'light -G' set_brightness_cmd = 'light -S ' -- @@ -108,16 +109,34 @@ local function worker(user_args) local update_widget = function(widget, stdout, _, _, _) local brightness_level = tonumber(string.format("%.0f", stdout)) + level = brightness_level widget:set_value(brightness_level) end function brightness_widget:set(value) + level = value spawn.easy_async(set_brightness_cmd .. value, function() spawn.easy_async(get_brightness_cmd, function(out) update_widget(brightness_widget.widget, out) end) end) 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 level < 0.1 then + -- restore previous level + level = old_level + else + -- save current brightness for later + old_level = level + level = 0 + end + brightness_widget:set(level) + end function brightness_widget:inc() spawn.easy_async(inc_brightness_cmd, function() spawn.easy_async(get_brightness_cmd, function(out) @@ -136,6 +155,7 @@ local function worker(user_args) brightness_widget.widget:buttons( awful.util.table.join( awful.button({}, 1, function() brightness_widget:set(base) end), + awful.button({}, 3, function() brightness_widget:toggle() end), awful.button({}, 4, function() brightness_widget:inc() end), awful.button({}, 5, function() brightness_widget:dec() end) ) -- cgit v1.2.3 From e85d353933dcfd9dfc9101a3b53616d07f0cba20 Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Thu, 15 Apr 2021 23:03:13 +0100 Subject: brightness-widget: add tooltip showing current level --- brightness-widget/README.md | 1 + brightness-widget/brightness.lua | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/brightness-widget/README.md b/brightness-widget/README.md index 5b1a23a..47f7d9c 100644 --- a/brightness-widget/README.md +++ b/brightness-widget/README.md @@ -15,6 +15,7 @@ It is possible to customize widget by providing a table with all or some of the | `path_to_icon` | `/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg` | Path to the icon | | `font` | `Play 9` | Font | | `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 | _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 f222adc..0994ba7 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -42,6 +42,7 @@ local function worker(user_args) local step = args.step or 5 local base = args.base or 20 local level = 0 -- current brightness value + local tooltip = args.tooltip or false if program == 'light' then get_brightness_cmd = 'light -G' set_brightness_cmd = 'light -S ' -- @@ -163,6 +164,15 @@ local function worker(user_args) watch(get_brightness_cmd, timeout, update_widget, brightness_widget.widget) + if tooltip then + awful.tooltip { + objects = { brightness_widget.widget }, + timer_function = function() + return level .. " %" + end, + } + end + return brightness_widget.widget end -- cgit v1.2.3 From 50f686d2c28c5a56481944d16ee2bd70d939b40f Mon Sep 17 00:00:00 2001 From: Nuno Silva Date: Fri, 16 Apr 2021 21:32:32 +0100 Subject: brightness-widget: fix CI warning about shadowed variable --- brightness-widget/brightness.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index 0994ba7..b66b1f0 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -41,7 +41,7 @@ local function worker(user_args) local program = args.program or 'light' local step = args.step or 5 local base = args.base or 20 - local level = 0 -- current brightness value + local current_level = 0 -- current brightness value local tooltip = args.tooltip or false if program == 'light' then get_brightness_cmd = 'light -G' @@ -110,12 +110,12 @@ local function worker(user_args) local update_widget = function(widget, stdout, _, _, _) local brightness_level = tonumber(string.format("%.0f", stdout)) - level = brightness_level + current_level = brightness_level widget:set_value(brightness_level) end function brightness_widget:set(value) - level = value + current_level = value spawn.easy_async(set_brightness_cmd .. value, function() spawn.easy_async(get_brightness_cmd, function(out) update_widget(brightness_widget.widget, out) @@ -128,15 +128,15 @@ local function worker(user_args) -- avoid toggling between '0' and 'almost 0' old_level = 1 end - if level < 0.1 then + if current_level < 0.1 then -- restore previous level - level = old_level + current_level = old_level else -- save current brightness for later - old_level = level - level = 0 + old_level = current_level + current_level = 0 end - brightness_widget:set(level) + brightness_widget:set(current_level) end function brightness_widget:inc() spawn.easy_async(inc_brightness_cmd, function() @@ -168,7 +168,7 @@ local function worker(user_args) awful.tooltip { objects = { brightness_widget.widget }, timer_function = function() - return level .. " %" + return current_level .. " %" end, } end -- cgit v1.2.3