brightness: use brightnessctl

This commit is contained in:
Vincent Bernat 2020-01-12 17:08:29 +01:00
parent 26a3d833b8
commit 9763ef14f6
2 changed files with 11 additions and 21 deletions

View file

@ -1,4 +1,4 @@
-- Handle brightness (with gsd-backlight-helper) -- Handle brightness (with brightnessctl)
local awful = require("awful") local awful = require("awful")
local naughty = require("naughty") local naughty = require("naughty")
@ -15,37 +15,27 @@ local icons = package.loaded["vbe/icons"]
module("vbe/brightness") module("vbe/brightness")
local nid = nil local nid = nil
local function change(percent) local function change(value)
local cmd = "pkexec /usr/lib/gnome-settings-daemon/gsd-backlight-helper"
-- Current value
local current = awful.util.pread(cmd .. " --get-brightness")
if not current or current == "" then return end
current = tonumber(current)
-- Maximum value
local max = tonumber(awful.util.pread(cmd .. " --get-max-brightness"))
-- Set new value -- Set new value
local target = math.floor(current + percent*max / 100) os.execute("brightnessctl -m s " .. value)
target = math.max(0, target)
target = math.min(max, target) -- Get and display current value
os.execute(cmd .. " --set-brightness " .. target) current = awful.util.pread("brightnessctl -m i")
current = tonumber(awful.util.pread(cmd .. " --get-brightness")) current = tonumber(string.match(current, ",(%d+)%%,"))
local icon = icons.lookup({name = "display-brightness", local icon = icons.lookup({name = "display-brightness",
type = "status"}) type = "status"})
nid = naughty.notify({ text = string.format("%3d %%", current * 100 / max), nid = naughty.notify({ text = string.format("%3d %%", current),
icon = icon, icon = icon,
font = "Free Sans Bold 24", font = "Free Sans Bold 24",
replaces_id = nid }).id replaces_id = nid }).id
end end
function increase() function increase()
change(5) change("5%+")
end end
function decrease() function decrease()
change(-5) change("5%-")
end end

View file

@ -14,7 +14,7 @@ fvwm
fvwm-crystal fvwm-crystal
gnome-themes-standard gnome-themes-standard
gnome-wine-icon-theme gnome-wine-icon-theme
gnome-settings-daemon brightnessctl
alsa-utils alsa-utils
pavucontrol pavucontrol
pulseaudio pulseaudio