awesomewm/modules/backlight/util.lua

134 lines
2.6 KiB
Lua
Raw Normal View History

2024-04-11 16:21:10 -07:00
local brightnessctl = {}
brightnessctl.parse = function(s)
local batpec = string.match(s, ",%d?%d?%d%%,")
batpec = batpec:sub(2, batpec:len() - 2)
return tonumber(batpec)
end
brightnessctl.get = function(callback)
awful.spawn.easy_async(
"brightnessctl info -m",
function(stdout, stderr, exitreason, exitcode)
callback(brightnessctl.parse(stdout))
end
)
end
brightnessctl.set = function(value)
awful.spawn.easy_async(
"brightnessctl set " .. value .. "% -m",
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal(
"module::backlight:update",
brightnessctl.parse(stdout)
)
end
)
end
brightnessctl.watch = function(timeout, callback, widget)
awful.widget.watch(
"brightnessctl get -m",
timeout,
function(stdout, stderr, exitreason, exitcode)
callback(brightnessctl.parse(stdout))
end,
widget
)
end
brightnessctl.backlight_up = function(value)
awful.spawn.easy_async(
"brightnessctl set " .. value .. "%+ -m",
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal(
"module::backlight:update",
brightnessctl.parse(stdout)
)
end
)
end
brightnessctl.backlight_down = function(value)
awful.spawn.easy_async(
"brightnessctl set " .. value .. "%- -m",
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal(
"module::backlight:update",
brightnessctl.parse(stdout)
)
end
)
end
2022-07-16 16:06:02 -07:00
2024-04-11 16:21:10 -07:00
local xbacklight = {}
xbacklight.get = function(callback)
2022-07-16 16:06:02 -07:00
awful.spawn.easy_async(
2023-08-23 08:09:31 -07:00
"xbacklight -get",
2022-07-16 16:06:02 -07:00
function(stdout, stderr, exitreason, exitcode)
callback(tonumber(stdout))
end
)
end
2024-04-11 16:21:10 -07:00
xbacklight.set = function(value)
2023-08-23 08:09:31 -07:00
awful.spawn("xbacklight -set " .. value, false)
2022-07-16 16:06:02 -07:00
end
2024-04-11 16:21:10 -07:00
xbacklight.watch = function(timeout, callback, widget)
2022-07-16 16:06:02 -07:00
awful.widget.watch(
2023-08-23 08:09:31 -07:00
"xbacklight -get",
2022-07-16 16:06:02 -07:00
timeout,
callback,
widget
)
end
2024-04-11 16:21:10 -07:00
xbacklight.backlight_up = function(value)
2022-11-05 11:31:12 -07:00
awful.spawn.easy_async(
2023-08-23 08:09:31 -07:00
"xbacklight -inc " .. value,
2022-11-05 11:31:12 -07:00
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::backlight:update_read")
end
)
2022-07-16 16:06:02 -07:00
end
2024-04-11 16:21:10 -07:00
xbacklight.backlight_down = function(value)
2022-11-05 11:31:12 -07:00
awful.spawn.easy_async(
2023-08-23 08:09:31 -07:00
"xbacklight -dec " .. value,
2022-11-05 11:31:12 -07:00
function(stdout, stderr, exitreason, exitcode)
awesome.emit_signal("module::backlight:update_read")
end
)
2022-07-16 16:06:02 -07:00
end
2024-04-11 16:21:10 -07:00
local backlight = {}
if config.backlight.backend == "xbacklight" then
backlight = xbacklight
elseif config.backlight.backend == "brightnessctl" then
backlight = brightnessctl
else
backlight = xbacklight
end
2022-11-05 11:31:12 -07:00
awesome.connect_signal("module::backlight:update_read",
function()
backlight.get(
function(value)
awesome.emit_signal(
"module::backlight:update",
value
)
end
)
end
)
2022-07-16 16:06:02 -07:00
return backlight