diff options
-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 |