From: yawnt Date: Mon, 23 Dec 2013 16:19:25 +0000 (+0100) Subject: contrib-widget: brightness X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/5a297dcfbb75e732671988a049095772fc2fdd76 contrib-widget: brightness --- diff --git a/widgets/contrib/brightness.lua b/widgets/contrib/brightness.lua new file mode 100644 index 0000000..bf14baf --- /dev/null +++ b/widgets/contrib/brightness.lua @@ -0,0 +1,46 @@ + +--[[ + + Licensed under GNU General Public License v2 + * (c) 2013, yawnt + +--]] + +local newtimer = require("lain.helpers").newtimer + +local wibox = require("wibox") +local io = { popen = io.popen } +local string = { match = string.match } + +local setmetatable = setmetatable + +-- Brightness +-- lain.widgets.contrib.brightness +local brightness = {} + +local function worker(args) + local args = args or {} + local backlight = args.backlight or "acpi_video0" + local timeout = args.timeout or 5 + local settings = args.settings or function() end + + brightness.widget = wibox.widget.textbox('') + + function brightness.update() + local f = assert(io.popen('cat /sys/class/backlight/' .. backlight .. "/brightness")) + + brightness_now = { + level = f:read("*a") + } + f:close() + + widget = brightness.widget + settings() + end + + newtimer("brightness", timeout, brightness.update) + + return setmetatable(brightness, { __index = brightness.widget }) +end + +return setmetatable(brightness, { __call = function(_, ...) return worker(...) end })