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 local xbacklight = {} xbacklight.get = function(callback) awful.spawn.easy_async( "xbacklight -get", function(stdout, stderr, exitreason, exitcode) callback(tonumber(stdout)) end ) end xbacklight.set = function(value) awful.spawn("xbacklight -set " .. value, false) end xbacklight.watch = function(timeout, callback, widget) awful.widget.watch( "xbacklight -get", timeout, callback, widget ) end xbacklight.backlight_up = function(value) awful.spawn.easy_async( "xbacklight -inc " .. value, function(stdout, stderr, exitreason, exitcode) awesome.emit_signal("module::backlight:update_read") end ) end xbacklight.backlight_down = function(value) awful.spawn.easy_async( "xbacklight -dec " .. value, function(stdout, stderr, exitreason, exitcode) awesome.emit_signal("module::backlight:update_read") 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", function() backlight.get( function(value) awesome.emit_signal( "module::backlight:update", value ) end ) end ) return backlight