Skip to content

Instantly share code, notes, and snippets.

@dgalli1
Last active September 26, 2020 17:39
Show Gist options
  • Save dgalli1/44a8378fa8d56aed817a9148a72f3ade to your computer and use it in GitHub Desktop.
Save dgalli1/44a8378fa8d56aed817a9148a72f3ade to your computer and use it in GitHub Desktop.
MPV Lua Script X11, force resolution on fullscreen
function on_fullscreen_change(name, value)
--[[
xrandr | grep "HDMI-A-0 connected primary 1920x1080+0+0" && echo "true" || echo "false"
xrandr | grep "HDMI-A-0 connected primary 3840x2160+0+0" && echo "true" || echo "false"
--]]
if value == true then
local xrandr_response = os.capture('/usr/bin/xrandr | grep "HDMI-A-0 connected primary 1920x1080+0+0"')
if xrandr_response == "HDMI-A-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 1600mm x 900mm" then
os.capture('xrandr --output DisplayPort-0 --off --output DisplayPort-1 --off --output DisplayPort-2 --off --output HDMI-A-0 --primary --mode 3840x2160 --pos 0x0 --rotate normal')
end
else
local xrandr_response = os.capture('/usr/bin/xrandr| grep "HDMI-A-0 connected primary 3840x2160+0+0"')
if xrandr_response == "HDMI-A-0 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 1600mm x 900mm" then
os.capture('xrandr --output DisplayPort-1 --off --output DisplayPort-0 --off --output DisplayPort-2 --off --output HDMI-A-0 --primary --mode 1920x1080 --pos 0x0 --rotate normal')
end
end
end
function reset_resolution(name)
print("reset")
local xrandr_response = os.capture('/usr/bin/xrandr| grep "HDMI-A-0 connected primary 3840x2160+0+0"')
if xrandr_response == "HDMI-A-0 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 1600mm x 900mm" then
os.capture('xrandr --output DisplayPort-1 --off --output DisplayPort-0 --off --output DisplayPort-2 --off --output HDMI-A-0 --primary --mode 1920x1080 --pos 0x0 --rotate normal')
end
end
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
mp.observe_property("fullscreen", "bool", on_fullscreen_change)
mp.register_event("end-file",reset_resolution)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment