summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2023-02-12 21:56:06 +0000
committerAnton Khirnov <anton@khirnov.net>2023-02-12 21:56:06 +0000
commit3c62f2d59a7319aef2eedbe0d2c6cc8bb9f87f03 (patch)
tree78888afd1bb6b62301d6495229dde3f1251a8d1d
parentf5fb3438098bb64da84f3c5562588c5bae449649 (diff)
rc: show notification on screen backlight changes
-rw-r--r--rc.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/rc.lua b/rc.lua
index 2bf47ca..28eb8e8 100644
--- a/rc.lua
+++ b/rc.lua
@@ -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 })