Added backlight module

This commit is contained in:
2022-07-16 16:06:02 -07:00
parent 8e8c4840da
commit 3014105bbf
12 changed files with 178 additions and 180 deletions

View File

@ -0,0 +1,37 @@
#!/usr/bin/fish
#
# Usage:
# backlight get
# backlight set [value]
# backlight max
#
# Returns:
# Set - nothing
# Get, max - Number between 0 and 100 (eg: 0, 25.445283, 100)
#
function backlight
switch $argv[1]
case "get"
xbacklight -get
case "max"
echo 100
case "set"
xbacklight -set $argv[2]
case "up"
xbacklight -inc 10
case "down"
xbacklight -dec 10
case "*"
echo "Unknown function \"$argv[1]\""
echo ""
echo "Usage:"
echo " backlight get"
echo " backlight set [value]"
echo " backlight max"
return 0
end
return 1
end
backlight $argv

View File

@ -0,0 +1,6 @@
return {
widgets = {
backlight = require("modules.backlight.widget").widget
},
keybinds = require("modules.backlight.keybinds"),
}

58
modules/backlight/keybinds.lua Executable file
View File

@ -0,0 +1,58 @@
local backlight = req_rel(..., "util")
return gears.table.join(
awful.key( {}, "XF86MonBrightnessUp",
function ()
backlight.backlight_up()
end,
{
description = "Raise brightness",
group = "System"
}
),
awful.key( {}, "XF86MonBrightnessDown",
function ()
backlight.backlight_down()
end,
{
description = "Lower brightness",
group = "System"
}
),
awful.key( { "Mod4" }, "o",
function ()
backlight.redshift(5600)
end,
{
description = "Default redshift",
group = "System"
}
),
awful.key( { "Mod4", "Shift" }, "o",
function ()
backlight.reset_redshift()
end,
{
description = "Reset redshift",
group = "System"
}
),
awful.key( { "Mod4", "Shift", "Control" }, "o",
function ()
backlight.reset_redshift()
awful.prompt.run {
prompt = "<b>Color temperature: </b>",
textbox = awful.screen.focused().mypromptbox.widget,
exe_callback = backlight.redshift
}
end,
{
description = "Set redshift",
group = "System"
}
)
)

62
modules/backlight/util.lua Executable file
View File

@ -0,0 +1,62 @@
local backlight = {}
-- The space at the end is important!
local script = configuration_dir .. "modules/backlight/backlight.fish"
script = script .. " "
backlight.hooks = {}
backlight.add_hook = function(callback)
backlight.hooks[#backlight.hooks + 1] = callback
end
backlight.exec_hooks = function()
backlight.read(function(status)
for i=1, #backlight.hooks do
backlight.hooks[i](status)
end
end)
end
backlight.read = function(callback)
awful.spawn.easy_async(
script .. "get",
function(stdout, stderr, exitreason, exitcode)
callback(tonumber(stdout))
end
)
end
backlight.set = function(value)
awful.spawn(script .. "set " .. value, false)
end
backlight.watch = function(timeout, callback, widget)
awful.widget.watch(
script .. "get",
timeout,
callback,
widget
)
end
backlight.backlight_up = function()
awful.spawn(script .. "up", false)
backlight.exec_hooks()
end
backlight.backlight_down = function()
awful.spawn(script .. "down", false)
backlight.exec_hooks()
end
backlight.redshift = function(temp)
awful.spawn("redshift -O " .. tostring(temp), false)
end
backlight.reset_redshift = function()
awful.spawn("redshift -x", false)
end
return backlight

101
modules/backlight/widget.lua Executable file
View File

@ -0,0 +1,101 @@
local backlight = req_rel(..., "util")
local widget = {}
widget.icon = wibox.widget {
id = "icon",
image = beautiful.icons.brightness.i,
resize = true,
widget = wibox.widget.imagebox,
}
widget.arc = wibox.widget {
{
widget.icon,
top = beautiful.dpi(1),
bottom = beautiful.dpi(1),
layout = wibox.container.margin,
},
max_value = 100,
thickness = beautiful.dpi(4),
start_angle = 4.71238898, -- 2pi*3/4
--forced_height = beautiful.dpi(16),
--forced_width = beautiful.dpi(16),
colors = {"#27D4CC", "#00446B"},
bg = "#FFFFFF30",
paddings = beautiful.dpi(2),
widget = wibox.container.arcchart
}
widget.widget = wibox.widget {
{
{ -- Right space
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
{ -- Main indicator. Can be replaced with widget.arc
widget.arc,
top = beautiful.dpi(2),
bottom = beautiful.dpi(2),
layout = wibox.container.margin,
},
{ -- Left space
widget = wibox.widget.separator,
color = beautiful.color.transparent,
forced_width = beautiful.dpi(3)
},
layout = wibox.layout.align.horizontal,
},
layout = wibox.container.background,
}
widget.widget:connect_signal("mouse::enter", function(result)
widget.widget.bg = beautiful.color.bar.hover_bg
end)
widget.widget:connect_signal("mouse::leave", function(result)
widget.widget.bg = beautiful.color.transparent
end)
widget.widget:connect_signal("button::press",
function(_, _, _, button, mods)
-- Scroll up
if (button == 4) then
backlight.backlight_up()
-- Scroll down
elseif (button == 5) then
backlight.backlight_down()
end
end
)
widget.update = function(value)
widget.arc.value = value
--[[if value > 90 then widget.icon.image = beautiful.icons.brightness.i
elseif value > 80 then widget.icon.image = beautiful.icons.brightness.h
elseif value > 70 then widget.icon.image = beautiful.icons.brightness.g
elseif value > 60 then widget.icon.image = beautiful.icons.brightness.f
elseif value > 50 then widget.icon.image = beautiful.icons.brightness.e
elseif value > 40 then widget.icon.image = beautiful.icons.brightness.d
elseif value > 30 then widget.icon.image = beautiful.icons.brightness.c
elseif value > 20 then widget.icon.image = beautiful.icons.brightness.b
elseif value <= 10 then widget.icon.image = beautiful.icons.brightness.a end
--]]
end
backlight.add_hook(widget.update)
backlight.watch(
5,
function()
backlight.read(widget.update)
end,
widget.widget
)
return widget