~q3cpma/dotfiles

dotfiles/.config/mpv/scripts/redshift_toggle.lua -rw-r--r-- 897 bytes
4ec701dbq3cpma Forgot -USR1 a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Toggle redshift when viewing videos with mpv

if os.execute("ps -a -o comm= | grep -qFx redshift") ~= 0
then
	return
end

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

function rs_toggle()
	os.execute("pid=$(ps -a -o comm=,pid= | sed -n 's#^redshift[[:blank:]]\\{1,\\}##p'); [ $pid ] && kill -USR1 $pid")
	mp.msg.log("info", (rs_enabled and "Dis" or "Reen") .. "abling redshift")
	rs_enabled = not rs_enabled
end

function vo_configured_handler(name, value)
	if value == rs_enabled
	then
		rs_toggle()
	end
end

function pause_handler(name, value)
	if value ~= rs_enabled
	then
		rs_toggle()
	end
end

function shutdown_handler()
	if mp.get_property_bool("vo-configured")
	then
		rs_toggle()
	end
end

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