~q3cpma/dotfiles

1cc7220f1968a77858b6b3164c4aeaf13ac281e0 — q3cpma 1 year, 9 months ago daeefe9
Update redshift_toggle mpv script
1 files changed, 14 insertions(+), 17 deletions(-)

M .config/mpv/scripts/redshift_toggle.lua
M .config/mpv/scripts/redshift_toggle.lua => .config/mpv/scripts/redshift_toggle.lua +14 -17
@@ 2,42 2,39 @@

if os.execute("pgrep -x redshift >/dev/null") ~= 0
then
   return
	return
end

-- Consider that redshift is enabled when starting
rs_enabled = true

function rs_toggle()
	os.execute("pkill -x -USR1 redshift")
	os.execute("pkill -USR1 -x redshift")
	mp.msg.log("info", (rs_enabled and "Dis" or "Reen") .. "abling redshift")
	rs_enabled = not rs_enabled
end

function rs_disable()
	if rs_enabled
function vo_configured_handler(name, value)
	if value == rs_enabled
	then
		rs_toggle()
		rs_enabled = false
		mp.msg.log("info", "Disabling redshift")
	end
end

function rs_enable()
	if not rs_enabled
function pause_handler(name, value)
	if value ~= rs_enabled
	then
		rs_toggle()
		rs_enabled = true
		mp.msg.log("info", "Reenabling redshift")
	end
end

function rs_handler()
	if mp.get_property("video") ~= "no"
function shutdown_handler()
	if mp.get_property_bool("vo-configured")
	then
		rs_disable()
	else
		rs_enable()
		rs_toggle()
	end
end

mp.register_event("file-loaded", rs_handler)
mp.register_event("shutdown", rs_enable)
mp.observe_property("vo-configured", "bool", vo_configured_handler)
mp.observe_property("pause", "bool", pause_handler)
mp.register_event("shutdown", shutdown_handler)