summary refs log tree commit diff
path: root/.config/mpv/scripts/hooks.lua
blob: 902846eaad80fb7fe8803f56115959d641cc6c39 (plain) (blame)
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
local mp = require("mp")
local utils = require("mp.utils")

local run = function(...)
	utils.subprocess_detached({
		args = { "sh", "-c", table.concat({ ... }, " ") .. " >/dev/null 2>&1" },
		max_size = 0,
		cancellable = false,
	})
end

local has_video = function()
	local v = mp.get_property("video")
	return v and v ~= "no" and v ~= ""
end

mp.register_event("start-file", function()
	run("makoctl", "mode", "-a", "off")
	if has_video() then
		run("svdn", "wlsunset")
	end
end)

mp.register_event("shutdown", function()
	run("makoctl", "mode", "-r", "off")
	if has_video() then
		run("svup", "wlsunset")
	end
end)