LWJGL/lwjgl — pull request #81 by tfg13 (2014-08-09 22:44:18+00:00)
Title: linux: basic compatibility for systems with multiple monitors

**tl;dr:** This brings multi-monitor awareness on linux on par with windows

I had this lying around for quite a while now and finally found the time to polish and test it - hope it still makes it to 2.9.2

This patch originates in my fixes for serveral bugs related to fullscreen mode: https://github.com/LWJGL/lwjgl/issues/64 and http://lwjgl.org/forum/index.php/topic,4920.0.html
While working on those, I became aware of the problems lwjgl based applications face on linux systems with more than one monitor.

**Description:**

As everyone knows, LWJGL 2 will not support multiple monitors, and this is no attempt to fix it. However, the windows version *knows* about multiple monitors and just always uses the first one.

This patch brings the same behavior to linux - with one enhancement:
My implementation uses not the first monitor, but the "primary" one. We get this information from XRandR (which is queried anyway). If there is no output device marked as primary, the implementation selects the one with the biggest resolution.

**Internal changes:**

* No longer use nGetAvailableDisplayModes() on linux. Due to some limitations in RandR 1.1, the returned DisplayModes have always been wrong for systems with multiple monitors. (Fun fact: There is even a nvidia employee explaning why they *needed* to be wrong for such setups: http://www.nvnews.net/vbulletin/showthread.php?t=151441)
* Use the "xrandr" command line utility instead to get the available modes. This really is nothing new, "xrandr" has been used to reset on exit for years. I just improved the parser to additionally extract all available DisplayModes.
* Do not use the native methods to *change* the DisplayMode. This is also done by xrandr now. There was nothing wrong with those native methods, but they only accept the crude values created by nGetAvailableDisplayModes().
* getDesktopDisplayMode() now returns the actual DisplayMode of the primary screen. Before, it returned a meta-mode that covered both (all) screens. Since this is what most games use to select a fullscreen mode, this often resulted in only partially visible games.

**Impact:**

I tried to keep the impact as low as possible:
* The changes only affect Linux
* Linux + 1 monitor: the experience should be exactly the same (for both users and devs)
* Linux + >1 monitors: LWJGL now "just works" and displays the game on the primary monitor.
* Linux without XRandr: No difference, the legacy-support was not touched.
* The "old" way of modifying the screens is still there and used as a fallback.

The switch to XRandR also fixed some other problems on linux:
* The resolutions returned from getAvailableDisplayModes() are now longer wrong for systems with multiple monitors
* The wrong values from the old getAvailableDisplayModes() could lead to situations where it was impossible for games to reach 120Hz, even if game + output device supported it. (because the old native code only allowed switching its own (wrong) frequencys. If something unknown was requested, it just used 60 Hz)

**Testing:**

I conducted a couple of test to make sure this works as intended and nothing breaks:
* The official **FullScreenWindowedTest** still works and the fullscreen window is now created on the primary monitor. (plus the others are no longer disabled - just like in windows)
* **Minecraft** now creates a fullscreen window with the intended resolution. (it used the super-wide meta-mode + wrong monitor before, resulting in a way to large window on the second screen. There are multiple users with the same problem in the related bug reports (https://github.com/LWJGL/lwjgl/issues/64, https://github.com/LWJGL/lwjgl/issues/38). Note: There is (still) a bug in Minecraft (https://bugs.mojang.com/browse/MC-55045) making switching to fullscreen difficult. But this is another issue, also occures on systems with only one monitor, and must be fixed by @Mojang anyway.
* **Revenge of the Titans** (latest HumbleBundle version) had the same problem as Minecraft, works now.