mirror of
https://github.com/don-philipe/knorke.git
synced 2025-11-08 14:57:02 +01:00
Add display backlight control notification
This commit is contained in:
67
displaybacklight.lua
Normal file
67
displaybacklight.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
-- requires xorg-xbacklight installed
|
||||
|
||||
local awful = require("awful")
|
||||
local vicious = require("vicious")
|
||||
local wibox = require("wibox")
|
||||
local naughty = require("naughty")
|
||||
local beautiful = require("beautiful")
|
||||
|
||||
local icon_brightness
|
||||
local brightness_id
|
||||
|
||||
|
||||
-- Create layout with widgets
|
||||
local widget = wibox.widget {
|
||||
{
|
||||
id = "icon",
|
||||
widget = wibox.widget.imagebox,
|
||||
resize = true
|
||||
},
|
||||
layout = wibox.layout.align.horizontal
|
||||
}
|
||||
|
||||
local function change_brightness(amount)
|
||||
if (amount < 0) then
|
||||
awful.util.spawn("xbacklight -dec " .. math.abs(amount))
|
||||
else
|
||||
awful.util.spawn("xbacklight -inc " .. math.abs(amount))
|
||||
end
|
||||
local f = io.popen("xbacklight -get")
|
||||
local bright = 0
|
||||
for line in f:lines() do
|
||||
bright = line
|
||||
end
|
||||
-- add changed amount as the current value is not yet changed when calling io.popen
|
||||
return tonumber(bright) + amount
|
||||
end
|
||||
|
||||
-- Widget functions that are available from the outside.
|
||||
function widget.set_icons(brightness)
|
||||
icon_brightness = brightness
|
||||
end
|
||||
|
||||
function widget.notify_brightness(delta)
|
||||
local brightness = change_brightness(delta)
|
||||
notify_icon = icon_brightness
|
||||
local notify_icon_bright = naughty.notify({
|
||||
position = "top_middle",
|
||||
border_width = 0,
|
||||
icon = notify_icon,
|
||||
replaces_id = brightness_id })
|
||||
brightness_id = notify_icon_bright.id
|
||||
local notify_width = notify_icon_bright.width
|
||||
local bar = wibox.widget.progressbar()
|
||||
bar:set_value(brightness)
|
||||
bar:set_max_value(100)
|
||||
bar:set_color(beautiful.archcolor)
|
||||
bar:set_background_color(beautiful.archcolor_bg)
|
||||
wibox.widget.draw_to_svg_file(bar, "/tmp/bright-bar.svg", 128, 10)
|
||||
brightness_id_1 = naughty.notify({
|
||||
position = "top_middle",
|
||||
border_width = 0,
|
||||
icon = "/tmp/bright-bar.svg",
|
||||
width = notify_width,
|
||||
replaces_id = brightness_id_1 }).id
|
||||
end
|
||||
|
||||
return widget
|
||||
Reference in New Issue
Block a user