I’ve been playing minecraft on my Linux system from time to time, and had an annoying “misfeature” – when exiting the client, my screen resolutions would get messed up.
Investigating a bit more, i found it’s because of my monitor setup and the nvidia driver. I’m using 3 monitors, one very old 1680×1050 monitor that i use for some status info only, and two nice Philips 288P6 monitors that can do 4K (3840×2160) resolution. However, I’m using them in 2560×1440 mode.
One of the monitors is running from the DVI port, where 2560×1440 runs just fine. The other is on the DisplayPort however, which can’t do 2560×1440 in hardware. Instead, the nvidia driver sets the monitor to full 3840×2160 and emulates the lower resolution in software.
However, minecraft calls
xrandr to get the current resolution when it starts, and calls it again to re-set the old resolution at end. But
xrandr doesn’t know anything about emulated resolutions, so the first call will just tell minecraft it’s running on 4K, and the second call will set the screen to that, overriding the software scaledown.
Fortunately, however, minecraft seems to try and find
xrandr in the current
PATH, which (on my system) includes
xrandr actually resides. So i just put a wrapper there to ignore the screen switch:
echo -n `date` " " >> /tmp/xrandr.calls
echo "$@" >> /tmp/xrandr.calls
case "$@" in
exec /usr/bin/xrandr "$@"
This disables any attempt to set the 4K resolution by
xrandr, so it fixes my problem. (And it creates a log of
xrandr calls as well to help in debugging).
Of course, you can get even more fancy – put that script in a separate directory, and add that directory to
PATH in your minecraft start script. Or use
$PPID to find out who’s calling
xrandr, and act on that. Whatever’s best for you.
The downside? If you use full screen mode in minecraft, it’ll fail to restore the old video mode when it exits. If that’s a problem for you, you need to enhance the script a bit to change “3840×2160” to “2560×1440” in the argument string before calling the real
xrandr. Or whichever resolutions you want.