diff options
-rw-r--r-- | rc.lua | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -9,6 +9,8 @@ local beautiful = require("beautiful") -- Notification library local naughty = require("naughty") +local gio = require("lgi").Gio + -- local modules local bindings = require("bindings") local commondefs = require("commondefs") @@ -233,3 +235,39 @@ do end) end end + +-- show notification on display brightness changes +local function brightness_stdout(line) + local action, device = string.match(line, '^KERNEL%[%d+.%d*%]%s+(%a+)%s+([^%s]+)%s+%(backlight%)$') + if action ~= 'change' then + return + end + + local function readnum(name) + local file = gio.File.new_for_path('/sys/' .. device .. '/' .. name) + local contents = file:load_contents(nil) + + if contents then + contents = string.gsub(contents, "%s$", "") + return string.len(contents) > 0 and tonumber(contents) or nil + end + + return nil + end + + local brightness = readnum('brightness') + local max_brightness = readnum('max_brightness') + + if brightness and max_brightness then + utils.notify_singleton(wsp, 'brightness', + { title = 'Brightness', + text = tostring(100 * brightness // max_brightness) .. '%'}) + end + + return nil +end +local function brightness_exit(reason, code) + utils.warn('brightness', 'udevadm monitor exited: %s/%d', reason, code) +end +awful.spawn.with_line_callback('udevadm monitor --kernel --subsystem-match=backlight', + { stdout = brightness_stdout, exit = brightness_exit }) |