-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmpv-dim-screen.lua
More file actions
43 lines (39 loc) · 1.8 KB
/
mpv-dim-screen.lua
File metadata and controls
43 lines (39 loc) · 1.8 KB
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
41
42
43
require 'mp.msg'
local utils = require 'mp.utils'
local original_brightness
function dim_screen()
local target_output = mp.get_opt("screen_brightness_output")
local brightness = mp.get_opt("screen_brightness_value")
if target_output == nil or brightness == nil then
mp.msg.log("error", "screen_brightess_output and screen_brightness_value script-opts should be set")
else
local r = mp.command_native({name = "subprocess",
playback_only = false,
capture_stdout = true,
args = {"kscreen-doctor", "-j"}})
local data = utils.parse_json(r.stdout)
for i,output in ipairs(data["outputs"]) do
if output["name"] == target_output then
original_brightness = output["sdr-brightness"]
mp.msg.log("info", "Original brightness is " .. original_brightness .. ".")
end
end
if original_brightness == nil then
mp.msg.log("error", "Failed to get original brightness.")
else
mp.msg.log("info", "Setting brightness to " .. brightness .. ".")
mp.commandv("run", "kscreen-doctor", "output." .. target_output .. ".sdr-brightness." .. brightness)
end
end
end
function bright_screen()
local target_output = mp.get_opt("screen_brightness_output")
if target_output == nil or original_brightness == nil then
mp.msg.log("error", "original output or original brightness aren't known")
else
mp.msg.log("info", "Restoring brightness to " .. original_brightness .. ".")
mp.commandv("run", "kscreen-doctor", "output." .. target_output .. ".sdr-brightness." .. original_brightness)
end
end
mp.register_event("shutdown", bright_screen)
dim_screen()