From 9763ef14f6d906724e4c597eaea6a59c4b782afb Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 12 Jan 2020 17:08:29 +0100 Subject: [PATCH] brightness: use brightnessctl --- lib/brightness.lua | 30 ++++++++++-------------------- requirements.txt | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/lib/brightness.lua b/lib/brightness.lua index 221e859..8d69807 100644 --- a/lib/brightness.lua +++ b/lib/brightness.lua @@ -1,4 +1,4 @@ --- Handle brightness (with gsd-backlight-helper) +-- Handle brightness (with brightnessctl) local awful = require("awful") local naughty = require("naughty") @@ -15,37 +15,27 @@ local icons = package.loaded["vbe/icons"] module("vbe/brightness") local nid = nil -local function change(percent) - 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")) - +local function change(value) -- Set new value - local target = math.floor(current + percent*max / 100) - target = math.max(0, target) - target = math.min(max, target) - os.execute(cmd .. " --set-brightness " .. target) - current = tonumber(awful.util.pread(cmd .. " --get-brightness")) + os.execute("brightnessctl -m s " .. value) + + -- Get and display current value + current = awful.util.pread("brightnessctl -m i") + current = tonumber(string.match(current, ",(%d+)%%,")) local icon = icons.lookup({name = "display-brightness", type = "status"}) - nid = naughty.notify({ text = string.format("%3d %%", current * 100 / max), + nid = naughty.notify({ text = string.format("%3d %%", current), icon = icon, font = "Free Sans Bold 24", replaces_id = nid }).id end function increase() - change(5) + change("5%+") end function decrease() - change(-5) + change("5%-") end diff --git a/requirements.txt b/requirements.txt index 67ee1a9..4ff0124 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,7 +14,7 @@ fvwm fvwm-crystal gnome-themes-standard gnome-wine-icon-theme -gnome-settings-daemon +brightnessctl alsa-utils pavucontrol pulseaudio