summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 })