129 lines
4.2 KiB
Lua
129 lines
4.2 KiB
Lua
local awful = require "awful"
|
|
local wibox = require("wibox")
|
|
local gears = require("gears")
|
|
local naughty = require("naughty")
|
|
local beautiful = require("beautiful")
|
|
local powermenu = {
|
|
buttonsize = 128,
|
|
spacing = 5,
|
|
iconPath = gears.filesystem.get_configuration_dir() .. "/awesome-powermenu/",
|
|
lock = function()
|
|
error("Lock requested, but no function specified")
|
|
end,
|
|
suspend = function()
|
|
error("Suspend requested, but no function specified")
|
|
end,
|
|
poweroff = function()
|
|
error("Power off requested, but no function specified")
|
|
end,
|
|
rotateLeft = function()
|
|
awful.spawn(gears.filesystem.get_configuration_dir() .. "/awesome-powermenu/rotate.lua left")
|
|
awesome.restart()
|
|
end,
|
|
rotateRight = function()
|
|
awful.spawn(gears.filesystem.get_configuration_dir() .. "/awesome-powermenu/rotate.lua right")
|
|
awesome.restart()
|
|
end,
|
|
brightnessUp = function()
|
|
awful.spawn.easy_async_with_shell("ls /sys/class/backlight/",function(stdout,stderr,_,_)
|
|
local devices = {}
|
|
for line in stdout:gmatch("%S+") do
|
|
local f = io.open(string.format("/sys/class/backlight/%s/brightness",line),"rb")
|
|
if not f then error("wtf") end
|
|
local brightness = tonumber(f:read("*a"))
|
|
f:close()
|
|
local f = io.open(string.format("/sys/class/backlight/%s/max_brightness",line),"rb")
|
|
local max_brightness = tonumber(f:read("*a"))
|
|
f:close()
|
|
devices[line]={["brightness"]=brightness,["max_brightness"]=max_brightness}
|
|
end
|
|
for k,v in pairs(devices) do
|
|
v.stepsize = math.floor(v.max_brightness / 10)
|
|
v.currentstep = math.floor(v.brightness / v.stepsize)
|
|
local f = io.open(string.format("/sys/class/backlight/%s/brightness",k),"wb")
|
|
f:write(v.stepsize * math.min(10,(v.currentstep+1)))
|
|
f:close()
|
|
end
|
|
end)
|
|
end,
|
|
brightnessDown = function()
|
|
awful.spawn.easy_async_with_shell("ls /sys/class/backlight/",function(stdout,stderr,_,_)
|
|
local devices = {}
|
|
for line in stdout:gmatch("%S+") do
|
|
local f = io.open(string.format("/sys/class/backlight/%s/brightness",line),"rb")
|
|
if not f then error("wtf") end
|
|
local brightness = tonumber(f:read("*a"))
|
|
f:close()
|
|
local f = io.open(string.format("/sys/class/backlight/%s/max_brightness",line),"rb")
|
|
local max_brightness = tonumber(f:read("*a"))
|
|
f:close()
|
|
devices[line]={["brightness"]=brightness,["max_brightness"]=max_brightness}
|
|
end
|
|
for k,v in pairs(devices) do
|
|
v.stepsize = math.floor(v.max_brightness / 10)
|
|
v.currentstep = math.floor(v.brightness / v.stepsize)
|
|
local f = io.open(string.format("/sys/class/backlight/%s/brightness",k),"wb")
|
|
f:write(v.stepsize * math.max(1,(v.currentstep-1)))
|
|
f:close()
|
|
end
|
|
end)
|
|
end
|
|
}
|
|
|
|
function powermenu.new()
|
|
local powermenuWidget = wibox.widget{
|
|
layout = wibox.layout.grid.vertical(2),
|
|
spacing = powermenu.spacing,
|
|
}
|
|
local powermenuPopup = awful.popup{
|
|
layout = wibox.layout.fixed.vertical,
|
|
-- widget = wibox.container.constraint(powermenuWidget, "min", 512, 512),
|
|
widget = powermenuWidget,
|
|
border_color = beautiful.border_focus,
|
|
border_width = 2,
|
|
ontop = true,
|
|
placement = awful.placement.centered,
|
|
visible = false,
|
|
}
|
|
local function addButton(icon, fn, hide)
|
|
if hide == nil then hide = true end
|
|
local newButton = awful.widget.button{
|
|
image = powermenu.iconPath .. "/" .. icon
|
|
}
|
|
newButton:set_forced_width(powermenu.buttonsize)
|
|
newButton:set_forced_height(powermenu.buttonsize)
|
|
newButton:buttons(gears.table.join(
|
|
newButton:buttons(),
|
|
awful.button({}, 1, nil, function()
|
|
fn()
|
|
if hide then
|
|
powermenuPopup:hide()
|
|
end
|
|
end)
|
|
))
|
|
|
|
powermenuWidget:add(newButton)
|
|
end
|
|
addButton("poweroff.png", powermenu.poweroff)
|
|
addButton("suspend.png", powermenu.suspend)
|
|
addButton("restart.png", awesome.restart)
|
|
addButton("lock.png", powermenu.lock)
|
|
addButton("rotate-left.png", powermenu.rotateLeft)
|
|
addButton("rotate-right.png", powermenu.rotateRight)
|
|
addButton("brightness-up.png", powermenu.brightnessUp, false)
|
|
addButton("brightness-down.png", powermenu.brightnessDown, false)
|
|
|
|
function powermenuPopup.show(self)
|
|
self.visible = true
|
|
end
|
|
function powermenuPopup.hide(self)
|
|
self.visible = false
|
|
end
|
|
function powermenuPopup.toggle(self)
|
|
self.visible = not self.visible
|
|
end
|
|
return powermenuPopup
|
|
end
|
|
|
|
return powermenu
|