Last active
September 26, 2020 17:39
-
-
Save dgalli1/44a8378fa8d56aed817a9148a72f3ade to your computer and use it in GitHub Desktop.
MPV Lua Script X11, force resolution on fullscreen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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