Skip to content

Instantly share code, notes, and snippets.

@Anachron
Forked from nilninull/turn-off-dpms.lua
Created March 6, 2023 13:35
Show Gist options
  • Save Anachron/5e29b943b5890cd721cec03bf0cc5158 to your computer and use it in GitHub Desktop.
Save Anachron/5e29b943b5890cd721cec03bf0cc5158 to your computer and use it in GitHub Desktop.
A mpv script for turn off dpms while playing video automatically
-- save this file to $XDG_CONFIG_HOME/mpv/scripts/
local dpms_mod = nil
-- local function dpms_mod_start(event)
-- print("RUN dpms mod start", dpms_mod)
-- if dpms_mod == nil then
-- -- This code was checked on xset 1.2.3
-- if os.execute("[ `xset q | sed -n '/^DPMS/,${/^ DPMS/s/^ DPMS is //p}'` == Enabled ]") == 0 then
-- dpms_mod = true
-- else
-- dpms_mod = false
-- end
-- end
-- end
-- mp.register_event("video-reconfig", dpms_mod_start)
local function on_property_change(name, value)
print('RUN on property change', value, dpms_mod)
if dpms_mod == nil and value then
-- This code was checked on xset 1.2.3
if os.execute("[ `xset q | sed -n '/^DPMS/,${/^ DPMS/s/^ DPMS is //p}'` == Enabled ]") == 0 then
dpms_mod = true
else
dpms_mod = false
end
end
end
mp.observe_property("vo-configured", "bool", on_property_change)
local function dpms_mod_stop(event)
if dpms_mod then
os.execute("xset +dpms")
end
end
mp.register_event("shutdown", dpms_mod_stop)
local function dpms_on_play(event)
if dpms_mod then
os.execute("xset -dpms")
end
end
mp.register_event("playback-restart", dpms_on_play)
local function dpms_on_pause(name, value)
if dpms_mod then
if value then
os.execute("xset +dpms")
else
os.execute("xset -dpms")
end
end
end
mp.observe_property("pause", "bool", dpms_on_pause)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment