Backlight fixes

master
Mark 2024-04-11 16:21:10 -07:00
parent 219873c890
commit 885ee3d66f
3 changed files with 91 additions and 7 deletions

View File

@ -35,8 +35,13 @@ config.screenshot = { enabled = true }
config.simple_widgets = { enabled = true } config.simple_widgets = { enabled = true }
config.keymap_popup = { enabled = true } config.keymap_popup = { enabled = true }
config.battery = { enabled = false } config.battery = { enabled = false }
config.backlight = { enabled = false }
config.picom = { enabled = true } config.picom = { enabled = true }
config.backlight = {
enabled = false,
button_step = 5,
scroll_step = 5,
backend = "xbacklight"
}
config.core = { config.core = {
-- Icon to use when a window doesn't provide one -- Icon to use when a window doesn't provide one

View File

@ -129,6 +129,10 @@ return function(s)
awesome.connect_signal("module::backlight:update", awesome.connect_signal("module::backlight:update",
function(value) function(value)
if value == nil then
value = 0
end
-- Update slider -- Update slider
widget. widget.
container. container.

View File

@ -1,6 +1,69 @@
local backlight = {} 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
backlight.get = function(callback) 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
local xbacklight = {}
xbacklight.get = function(callback)
awful.spawn.easy_async( awful.spawn.easy_async(
"xbacklight -get", "xbacklight -get",
function(stdout, stderr, exitreason, exitcode) function(stdout, stderr, exitreason, exitcode)
@ -9,11 +72,11 @@ backlight.get = function(callback)
) )
end end
backlight.set = function(value) xbacklight.set = function(value)
awful.spawn("xbacklight -set " .. value, false) awful.spawn("xbacklight -set " .. value, false)
end end
backlight.watch = function(timeout, callback, widget) xbacklight.watch = function(timeout, callback, widget)
awful.widget.watch( awful.widget.watch(
"xbacklight -get", "xbacklight -get",
timeout, timeout,
@ -23,7 +86,7 @@ backlight.watch = function(timeout, callback, widget)
end end
backlight.backlight_up = function(value) xbacklight.backlight_up = function(value)
awful.spawn.easy_async( awful.spawn.easy_async(
"xbacklight -inc " .. value, "xbacklight -inc " .. value,
function(stdout, stderr, exitreason, exitcode) function(stdout, stderr, exitreason, exitcode)
@ -32,7 +95,7 @@ backlight.backlight_up = function(value)
) )
end end
backlight.backlight_down = function(value) xbacklight.backlight_down = function(value)
awful.spawn.easy_async( awful.spawn.easy_async(
"xbacklight -dec " .. value, "xbacklight -dec " .. value,
function(stdout, stderr, exitreason, exitcode) function(stdout, stderr, exitreason, exitcode)
@ -41,6 +104,18 @@ backlight.backlight_down = function(value)
) )
end end
local backlight = {}
if config.backlight.backend == "xbacklight" then
backlight = xbacklight
elseif config.backlight.backend == "brightnessctl" then
backlight = brightnessctl
else
backlight = xbacklight
end
awesome.connect_signal("module::backlight:update_read", awesome.connect_signal("module::backlight:update_read",
function() function()
backlight.get( backlight.get(