awesomewm/modules/backlight/util.lua

63 lines
1.2 KiB
Lua
Raw Normal View History

2022-07-16 16:06:02 -07:00
local backlight = {}
-- The space at the end is important!
2022-07-16 17:41:00 -07:00
local script = conf_dir .. "modules/backlight/backlight.fish"
2022-07-16 16:06:02 -07:00
script = script .. " "
backlight.hooks = {}
backlight.add_hook = function(callback)
backlight.hooks[#backlight.hooks + 1] = callback
end
backlight.exec_hooks = function()
backlight.read(function(status)
for i=1, #backlight.hooks do
backlight.hooks[i](status)
end
end)
end
backlight.read = function(callback)
awful.spawn.easy_async(
script .. "get",
function(stdout, stderr, exitreason, exitcode)
callback(tonumber(stdout))
end
)
end
backlight.set = function(value)
awful.spawn(script .. "set " .. value, false)
end
backlight.watch = function(timeout, callback, widget)
awful.widget.watch(
script .. "get",
timeout,
callback,
widget
)
end
backlight.backlight_up = function()
awful.spawn(script .. "up", false)
backlight.exec_hooks()
end
backlight.backlight_down = function()
awful.spawn(script .. "down", false)
backlight.exec_hooks()
end
backlight.redshift = function(temp)
awful.spawn("redshift -O " .. tostring(temp), false)
end
backlight.reset_redshift = function()
awful.spawn("redshift -x", false)
end
return backlight