diff options
author | Sam Delmerico <svdelmerico@gmail.com> | 2018-11-26 16:21:48 -0500 |
---|---|---|
committer | Sam Delmerico <svdelmerico@gmail.com> | 2018-11-26 16:21:48 -0500 |
commit | 2cf217dc6c45f206aef0e065fa3ede4c36d73e3b (patch) | |
tree | a257f029216862d7525ca7e6e1818982b4a03085 /brightness-widget | |
parent | f369e1cb28a308f6967d7bc31375c637755b1e3f (diff) | |
parent | 1eefac87faefa22b0d3941a9fd4c76010688f59e (diff) |
merge biased battery levels
Diffstat (limited to 'brightness-widget')
-rw-r--r-- | brightness-widget/brightness.lua | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/brightness-widget/brightness.lua b/brightness-widget/brightness.lua index ef30905..1b2e8a6 100644 --- a/brightness-widget/brightness.lua +++ b/brightness-widget/brightness.lua @@ -10,17 +10,19 @@ local wibox = require("wibox") local watch = require("awful.widget.watch") +local spawn = require("awful.spawn") ---local GET_BRIGHTNESS_CMD = "xbacklight -get" -local GET_BRIGHTNESS_CMD = "light -G" -local path_to_icons = "/usr/share/icons/Arc/status/symbolic/" +local PATH_TO_ICON = "/usr/share/icons/Arc/status/symbolic/display-brightness-symbolic.svg" +local GET_BRIGHTNESS_CMD = "light -G" -- "xbacklight -get" +local INC_BRIGHTNESS_CMD = "light -A 1" -- "xbacklight -inc 5" +local DEC_BRIGHTNESS_CMD = "light -U 1" -- "xbacklight -dec 5" local brightness_text = wibox.widget.textbox() brightness_text:set_font('Play 9') local brightness_icon = wibox.widget { { - image = path_to_icons .. "display-brightness-symbolic.svg", + image = PATH_TO_ICON, resize = false, widget = wibox.widget.imagebox, }, @@ -34,13 +36,21 @@ local brightness_widget = wibox.widget { layout = wibox.layout.fixed.horizontal, } -watch( - GET_BRIGHTNESS_CMD, 1, - function(widget, stdout, stderr, exitreason, exitcode) - local brightness_level = tonumber(string.format("%.0f", stdout)) - widget:set_text(" " .. brightness_level .. "%") - end, - brightness_text -) +local update_widget = function(widget, stdout, stderr, exitreason, exitcode) + local brightness_level = tonumber(string.format("%.0f", stdout)) + widget:set_text(" " .. brightness_level .. "%") +end, + +brightness_widget:connect_signal("button::press", function(_,_,_,button) + if (button == 4) then spawn(INC_BRIGHTNESS_CMD, false) + elseif (button == 5) then spawn(DEC_BRIGHTNESS_CMD, false) + end + + spawn.easy_async(GET_BRIGHTNESS_CMD, function(stdout, stderr, exitreason, exitcode) + update_widget(brightness_widget, stdout, stderr, exitreason, exitcode) + end) +end) + +watch(GET_BRIGHTNESS_CMD, 1, update_widget, brightness_text) return brightness_widget |