File fix-crash-on-multimonitor.patch of Package java3d

From: Jiri Slaby <jslaby@suse.cz>
Subject: Fix crash on multimonitor

When using Xinerama setup and programs try to appear on a secondary
screen which is at 0,0, the java3d chokes. It is because it is trying
to find a configuration for screen 1, but there is none. Xinerama uses
only screen 0.

There was sort of handling of this situation, but was incomplete. It
didn't handle secondary screens at 0,0. Only primary ones.

So handle this better, according to documentation of
GraphicsConfiguration. We need to check all screens in the system...

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java |   45 +++++++---
 1 file changed, 34 insertions(+), 11 deletions(-)

--- a/j3d-core/src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java
+++ b/j3d-core/src/classes/x11/javax/media/j3d/X11NativeConfigTemplate3D.java
@@ -32,6 +32,7 @@
 package javax.media.j3d;
 
 import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsConfigTemplate;
 import java.awt.Rectangle;
@@ -66,6 +67,36 @@ class X11NativeConfigTemplate3D extends
     native int getStencilSize(long display, int screen, int vid);
 
     /*
+     *  Checks whether we have physical or virtual screens (Xinerama)
+     *  According to docs of GraphicsConfiguration, we have to check all screens in the system.
+     */
+    static boolean isVirtualEnvironment() {
+	if (VirtualUniverse.mc.xineramaDisabled)
+	    return false;
+
+	final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+	final GraphicsDevice[] gs = ge.getScreenDevices();
+
+	for (int i = 0; i < gs.length; i++) {
+	    final GraphicsConfiguration[] gc = gs[i].getConfigurations();
+
+	    for (int j = 0; j < gc.length; j++) {
+		Rectangle bounds = gc[j].getBounds();
+
+		if (bounds.x != 0 || bounds.y != 0) {
+		    if (debug) {
+			System.out.println("  Non-primary Xinerama screen " + i + ":");
+			System.out.println("    bounds = " + bounds);
+			System.out.println("    using screen 0 visual");
+		    }
+		    return true;
+		}
+	    }
+	}
+	return false;
+    }
+
+    /*
      *  Chooses the best FBConfig for Java 3D apps.
      */
     @Override
@@ -92,18 +123,10 @@ class X11NativeConfigTemplate3D extends
 	    }
 	}
 
-	Rectangle bounds = gc[0].getBounds();
-	if ((bounds.x != 0 || bounds.y != 0) &&
-	    (! VirtualUniverse.mc.xineramaDisabled)) {
-	    // Xinerama is being used.  The screen needs to be set to 0 since
-	    // glxChooseFBConfig will not return a valid visual otherwise.
+	// Xinerama is being used.  The screen needs to be set to 0 since
+	// glxChooseFBConfig will not return a valid visual otherwise.
+	if (isVirtualEnvironment())
 	    screen = 0;
-	    if (debug) {
-		System.out.println("  Non-primary Xinerama screen:");
-		System.out.println("    bounds = " + bounds);
-		System.out.println("    using screen 0 visual");
-	    }
-	}
 
         int[] attrList;   // holds the list of attributes to be translated
                           // for glxChooseFBConfig call