added brightness and rotation controls, still WIP

This commit is contained in:
Izaya 2022-08-25 13:37:47 +10:00
parent 73299f770c
commit 5bbcf9d290
6 changed files with 139 additions and 2 deletions

BIN
brightness-down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
brightness-up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -1,6 +1,7 @@
local awful = require "awful"
local wibox = require("wibox")
local gears = require("gears")
local naughty = require("naughty")
local beautiful = require("beautiful")
local powermenu = {
buttonsize = 128,
@ -15,6 +16,58 @@ local powermenu = {
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()
@ -32,7 +85,8 @@ function powermenu.new()
placement = awful.placement.centered,
visible = false,
}
local function addButton(icon, fn)
local function addButton(icon, fn, hide)
if hide == nil then hide = true end
local newButton = awful.widget.button{
image = powermenu.iconPath .. "/" .. icon
}
@ -42,7 +96,9 @@ function powermenu.new()
newButton:buttons(),
awful.button({}, 1, nil, function()
fn()
powermenuPopup:hide()
if hide then
powermenuPopup:hide()
end
end)
))
@ -52,6 +108,10 @@ function powermenu.new()
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

BIN
rotate-left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

BIN
rotate-right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

77
rotate.lua Executable file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env lua
local tA = {...}
local direction = tA[1]
local disp = tA[2] or "LVDS-0"
local orientations = {"normal", "right", "inverted", "left"}
local ctms = {["normal"]="1 0 0 0 1 0 0 0 1",
["inverted"]="-1 0 1 0 -1 1 0 0 1",
["left"]="0 -1 1 1 0 0 0 0 1",
["right"]="0 1 0 -1 0 1 0 0 1"}
--[[
xrandr -q --verbose
LVDS-0 connected 800x1280+0+0 (0x43) left (normal left inverted right x axis y axis) 0mm x 0mm
NEW_ROT="normal"
CTM="1 0 0 0 1 0 0 0 1"
NEW_ROT="inverted"
CTM="-1 0 1 0 -1 1 0 0 1"
NEW_ROT="left"
CTM="0 -1 1 1 0 0 0 0 1"
NEW_ROT="right"
CTM="0 1 0 -1 0 1 0 0 1"
]]
local function nextRight(o)
local current = 1
for k,v in pairs(orientations) do
if o == v then
current = k
end
end
local ret = current + 1
if ret > #orientations then
ret = 1
end
return orientations[ret]
end
local function nextLeft(o)
local current = 1
for k,v in pairs(orientations) do
if o == v then
current = k
end
end
local ret = current - 1
if ret < 1 then
ret = #orientations
end
return orientations[ret]
end
local f = io.popen("xrandr -q --verbose","r")
c=f:read("*a")
f:close()
local line = (c:match("\n("..disp:gsub("%p","%%%1") .. ".-)\n"))
print(line)
local orientation = line:match("%S+ %S+ %S+ %S+ (%S+) ")
local f = io.popen("xinput --list","r")
local xin=f:read("*a"):lower()
f:close()
--⎜ ↳ Elan Touchscreen id=6 [slave pointer (2)]
local touchscreen = (xin:match("touch.*screen%s-id=(%d+)"))
print(orientation)
print(nextLeft(orientation))
print(nextRight(orientation))
local newRot = nextRight(orientation)
if direction == "left" then
newRot = nextLeft(orientation)
end
print(string.format("xrandr --output %s --rotate %s",disp,newRot))
os.execute(string.format("xrandr --output %s --rotate %s",disp,newRot))
print(string.format("xinput set-prop %s 'Coordinate Transformation Matrix' %s",touchscreen,ctms[newRot]))
os.execute(string.format("xinput set-prop %s 'Coordinate Transformation Matrix' %s",touchscreen,ctms[newRot]))