diff options
author | Anton Khirnov <anton@khirnov.net> | 2023-02-12 21:56:06 +0000 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2023-02-12 21:56:06 +0000 |
commit | 3c62f2d59a7319aef2eedbe0d2c6cc8bb9f87f03 (patch) | |
tree | 78888afd1bb6b62301d6495229dde3f1251a8d1d /rc.lua | |
parent | f5fb3438098bb64da84f3c5562588c5bae449649 (diff) |
rc: show notification on screen backlight changes
Diffstat (limited to 'rc.lua')
-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 }) |