luca-awesome-dotfiles/home/.config/awesome/ui/sidebar/services/redshift.lua
2023-02-05 05:02:49 +01:00

144 lines
3.3 KiB
Lua

-- ## Redshift button/widget ##
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- Requirements :
-- ~~~~~~~~~~~~~~
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local dpi = beautiful.xresources.apply_dpi
-- # Libs :
-- ~~~~~~~~
local helpers = require("libs.helpers")
local rubato = require("libs.rubato")
-- misc/vars
-- ~~~~~~~~~
local service_name = "Night Light"
local service_icon = ""
-- widgets
-- ~~~~~~~
-- icon
local icon = wibox.widget{
font = theme.sidebar_font,
markup = helpers.colorize_text(service_icon, colors.white),
widget = wibox.widget.textbox,
valign = "center",
align = "center"
}
-- name
local name = wibox.widget{
font = theme.font,
widget = wibox.widget.textbox,
markup = helpers.colorize_text(service_name, colors.white),
valign = "center",
align = "center"
}
-- animation :love:
local circle_animate = wibox.widget{
widget = wibox.container.background,
shape = helpers.rrect(theme.rounded),
bg = colors.main_scheme,
forced_width = 110,
}
-- mix those
local alright = wibox.widget{
{
{
nil,
{
circle_animate,
layout = wibox.layout.fixed.horizontal
},
layout = wibox.layout.align.horizontal,
expand = "none"
},
{
nil,
{
icon,
name,
layout = wibox.layout.fixed.vertical,
spacing = dpi(10)
},
layout = wibox.layout.align.vertical,
expand = "none"
},
layout = wibox.layout.stack
},
shape = helpers.rrect(theme.rounded),
widget = wibox.container.background,
border_color = colors.brightblack,
forced_width = dpi(80),
forced_height = dpi(80),
bg = colors.brightblack
}
local animation_button_opacity = rubato.timed{
pos = 0,
rate = 60,
intro = 0.08,
duration = 0.3,
awestore_compat = true,
subscribed = function(pos)
circle_animate.opacity = pos
end
}
-- kill every redshift process
local readwrite = require("ui.sidebar.services.read_writer")
local output = readwrite.readall("blue_light_state")
if output:match("true") then
icon.markup = helpers.colorize_text(service_icon, colors.black)
name.markup = helpers.colorize_text(service_name, colors.black)
animation_button_opacity:set(1)
else
icon.markup = helpers.colorize_text(service_icon, colors.black)
name.markup = helpers.colorize_text(service_name, colors.black)
animation_button_opacity:set(0)
end
-- buttons
alright:buttons(gears.table.join(awful.button({}, 1, nil, function()
awful.spawn.easy_async_with_shell(
[[
if [ ! -z $(pgrep redshift) ];
then
redshift -x && pkill redshift && killall redshift
echo "false" > /tmp/blue_light_state
echo 'OFF'
else
redshift -l 0:0 -t 4500:4500 -r &>/dev/null &
echo "true" > /tmp/blue_light_state
echo 'ON'
fi
]],
function(stdout)
if stdout:match("ON") then
icon.markup = helpers.colorize_text(service_icon, colors.black)
name.markup = helpers.colorize_text(service_name, colors.black)
animation_button_opacity:set(1)
else
icon.markup = helpers.colorize_text(service_icon, colors.black)
name.markup = helpers.colorize_text(service_name, colors.black)
animation_button_opacity:set(0)
end
end
)
end)))
return alright