From: <ka...@us...> - 2010-04-14 22:34:49
|
Revision: 3327 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3327&view=rev Author: kappa1 Date: 2010-04-14 22:34:43 +0000 (Wed, 14 Apr 2010) Log Message: ----------- fix: When using unsigned jars with signed lwjgl jars it fails when creating a Display on linux with an AccessController error. This is due to the new XRandR class missing a AccessController.doPriviledged method when it requires out of sandbox access. (LWJGL Applet Distribution is borken on linux without this fix) Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-04-14 20:48:01 UTC (rev 3326) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-04-14 22:34:43 UTC (rev 3327) @@ -40,6 +40,8 @@ import java.util.List; import java.util.Map; import java.util.regex.Pattern; +import java.security.AccessController; +import java.security.PrivilegedAction; /** * Utility for working with the xrandr commmand-line utility. Assumes @@ -103,7 +105,12 @@ * xrandr is not supported */ public static Screen[] getConfiguration() { - populate(); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + populate(); + return null; + } + }); return (Screen[]) current.clone(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-04-16 19:06:59
|
Revision: 3331 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3331&view=rev Author: kappa1 Date: 2010-04-16 19:06:53 +0000 (Fri, 16 Apr 2010) Log Message: ----------- minor tweak to XRandR class to add AccessControllers to remaining methods that need it. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-04-15 20:38:39 UTC (rev 3330) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-04-16 19:06:53 UTC (rev 3331) @@ -119,11 +119,20 @@ * @param screens * The desired screen set, may not be <code>null</code> */ - public static void setConfiguration(Screen[]/* ... */screens) { + public static void setConfiguration(final Screen[]/* ... */screens) { if (screens.length == 0) { throw new IllegalArgumentException("Must specify at least one screen"); } - + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + setScreen(screens); + return null; + } + }); + } + + private static void setScreen(Screen[] screens) { List/* <String> */cmd = new ArrayList/* <String> */(); cmd.add("xrandr"); @@ -164,7 +173,6 @@ } catch (IOException e) { e.printStackTrace(); } - } /** @@ -172,7 +180,13 @@ * xrandr is not supported */ public static String[] getScreenNames() { - populate(); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + populate(); + return null; + } + }); + return (String[]) screens.keySet().toArray(new String[screens.size()]); } @@ -182,7 +196,13 @@ * <code>null</code> if there is no such screen */ public static Screen[] getResolutions(String name) { - populate(); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + populate(); + return null; + } + }); + // clone the array to prevent held copies being altered return (Screen[]) ((Screen[]) screens.get(name)).clone(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-05-20 18:11:54
|
Revision: 3340 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3340&view=rev Author: kappa1 Date: 2010-05-20 18:11:47 +0000 (Thu, 20 May 2010) Log Message: ----------- XrandR fix for parsing some screen sizes, credit to MatthiasM for providing patch. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-07 17:03:36 UTC (rev 3339) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-20 18:11:47 UTC (rev 3340) @@ -39,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; import java.util.regex.Pattern; /** @@ -82,10 +83,10 @@ name = sa[0]; // record the current config - currentList.add(new Screen(name, sa[2])); + parseScreen(currentList, name, sa[2]); } else if (Pattern.matches("\\d*x\\d*", sa[0])) { // found a new mode line - possibles.add(new Screen(name, sa[0])); + parseScreen(possibles, name, sa[0]); } } @@ -179,7 +180,43 @@ // clone the array to prevent held copies being altered return (Screen[]) ((Screen[]) screens.get(name)).clone(); } + + private static final Pattern SCREEN_PATTERN1 = Pattern.compile("^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$"); + private static final Pattern SCREEN_PATTERN2 = Pattern.compile("^(\\d+)x(\\d+)$"); + /** + * Parses a screen configuration and adds it to the list if it's valid. + * + * @param list + * the list to add the Screen to if it's valid + * @param name + * the name of this screen + * @param conf + * config string, format either widthxheight or + * widthxheight+xPos+yPos + */ + private static void parseScreen(List /* <Screen> */ list, String name, String what) { + Matcher m = SCREEN_PATTERN1.matcher(what); + if(!m.matches()) { + m = SCREEN_PATTERN2.matcher(what); + if(!m.matches()) { + System.out.println("Did not match: " + what); + return; + } + } + int width = Integer.parseInt(m.group(1)); + int height = Integer.parseInt(m.group(2)); + int xpos, ypos; + if(m.groupCount() > 3) { + xpos = Integer.parseInt(m.group(3)); + ypos = Integer.parseInt(m.group(4)); + } else { + xpos = 0; + ypos = 0; + } + list.add(new Screen(name, width, height, xpos, ypos)); + } + /** * Encapsulates the configuration of a monitor. Resolution is * fixed, position is mutable @@ -213,24 +250,12 @@ */ public int yPos = 0; - /** - * @param name - * name of the screen - * @param conf - * config string, format either widthxheight or - * widthxheight+xPos+yPos - */ - private Screen(String name, String conf) { + private Screen(String name, int width, int height, int xPos, int yPos) { this.name = name; - - String[] sa = conf.split("\\D"); - width = Integer.parseInt(sa[0]); - height = Integer.parseInt(sa[1]); - - if (sa.length > 2) { - xPos = Integer.parseInt(sa[2]); - yPos = Integer.parseInt(sa[3]); - } + this.width = width; + this.height = height; + this.xPos = xPos; + this.yPos = yPos; } private void getArgs(List/* <String> */argList) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-05-21 22:13:06
|
Revision: 3341 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3341&view=rev Author: kappa1 Date: 2010-05-21 22:12:57 +0000 (Fri, 21 May 2010) Log Message: ----------- Further XRandR fixes, it now catches throwable in populate(), if there are any problems in parsing the xrandr output we revert to LWJGL's regular behaviour. All output now goes to LWJGLUtil.log() instead of the out.println and err.println. Credit to Ryanm for patch. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-20 18:11:47 UTC (rev 3340) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-21 22:12:57 UTC (rev 3341) @@ -1,33 +1,28 @@ /* - * Copyright (c) 2002-2010 LWJGL Project - * All rights reserved. - * + * Copyright (c) 2002-2010 LWJGL Project All rights reserved. * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'LWJGL' nor the names of - * its contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * modification, are permitted provided that the following conditions + * are met: * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. * Redistributions in binary form must reproduce the + * above copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. * Neither the name of 'LWJGL' nor the names + * of its contributors may be used to endorse or promote products + * derived from this software without specific prior written + * permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. */ package org.lwjgl.opengl; @@ -42,60 +37,74 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.lwjgl.LWJGLUtil; + /** * Utility for working with the xrandr commmand-line utility. Assumes * xrandr v1.2 or higher. * * @author ryanm */ -public class XRandR { +public class XRandR +{ + private static Screen[] current; - private static Screen[] current; + private static Map /* <String, Screen[]> */screens; - private static Map /* <String, Screen[]> */screens; - - private static void populate() { - if (screens == null) { + private static void populate() + { + if( screens == null ) + { screens = new HashMap/* <String, Screen[]> */(); // ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" ); // pb.redirectErrorStream(); - try { + try + { // Process p= pb.start(); - Process p = Runtime.getRuntime().exec(new String[] { "xrandr", "-q"}); + Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } ); List/* <Screen> */currentList = new ArrayList/* <Screen> */(); List/* <Screen> */possibles = new ArrayList/* <Screen> */(); String name = null; - BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); String line; - while ((line = br.readLine()) != null) { + while( ( line = br.readLine() ) != null ) + { line = line.trim(); - String[] sa = line.split("\\s+"); + String[] sa = line.split( "\\s+" ); - if (sa[1].equals("connected")) { + if( sa[ 1 ].equals( "connected" ) ) + { // found a new screen block - if (name != null) { - screens.put(name, possibles.toArray(new Screen[possibles.size()])); + if( name != null ) + { + screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) ); possibles.clear(); } - name = sa[0]; + name = sa[ 0 ]; // record the current config - parseScreen(currentList, name, sa[2]); - } else if (Pattern.matches("\\d*x\\d*", sa[0])) { + parseScreen( currentList, name, sa[ 2 ] ); + } + else if( Pattern.matches( "\\d*x\\d*", sa[ 0 ] ) ) + { // found a new mode line - parseScreen(possibles, name, sa[0]); + parseScreen( possibles, name, sa[ 0 ] ); } } - screens.put(name, possibles.toArray(new Screen[possibles.size()])); + screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) ); - current = (Screen[]) currentList.toArray(new Screen[currentList.size()]); - } catch (IOException e) { - e.printStackTrace(); + current = ( Screen[] ) currentList.toArray( new Screen[ currentList.size() ] ); } + catch( Throwable e ) + { + LWJGLUtil.log( "Exception in XRandR.populate(): " + e.getMessage() ); + screens.clear(); + current = new Screen[ 0 ]; + } } } @@ -103,71 +112,86 @@ * @return The current screen configuration, or an empty array if * xrandr is not supported */ - public static Screen[] getConfiguration() { + public static Screen[] getConfiguration() + { populate(); - return (Screen[]) current.clone(); + return current.clone(); } /** * @param screens * The desired screen set, may not be <code>null</code> + * @throws IllegalArgumentException + * if no screens are specified */ - public static void setConfiguration(Screen[]/* ... */screens) { - if (screens.length == 0) { - throw new IllegalArgumentException("Must specify at least one screen"); + public static void setConfiguration( Screen[]/* ... */screens ) + { + if( screens.length == 0 ) + { + throw new IllegalArgumentException( "Must specify at least one screen" ); } List/* <String> */cmd = new ArrayList/* <String> */(); - cmd.add("xrandr"); + cmd.add( "xrandr" ); // switch off those in the current set not in the new set - for (int i = 0; i < current.length; i++) { + for( int i = 0; i < current.length; i++ ) + { boolean found = false; - for (int j = 0; j < screens.length; j++) { - if (screens[j].name.equals(current[i].name)) { + for( int j = 0; j < screens.length; j++ ) + { + if( screens[ j ].name.equals( current[ i ].name ) ) + { found = true; break; } } - if (!found) { - cmd.add("--output"); - cmd.add(current[i].name); - cmd.add("--off"); + if( !found ) + { + cmd.add( "--output" ); + cmd.add( current[ i ].name ); + cmd.add( "--off" ); } } // set up new set - for (int i = 0; i < screens.length; i++) { - screens[i].getArgs(cmd); + for( int i = 0; i < screens.length; i++ ) + { + screens[ i ].getArgs( cmd ); } - try { + try + { // ProcessBuilder pb = new ProcessBuilder( cmd ); // pb.redirectErrorStream(); // Process p = pb.start(); - Process p = Runtime.getRuntime().exec((String[]) cmd.toArray(new String[cmd.size()])); + Process p = + Runtime.getRuntime().exec( ( String[] ) cmd.toArray( new String[ cmd.size() ] ) ); // no output is expected, but check anyway - BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); String line; - while ((line = br.readLine()) != null) { - System.out.println(line); + while( ( line = br.readLine() ) != null ) + { + LWJGLUtil.log( "Unexpected output from xrandr process: " + line ); } current = screens; - } catch (IOException e) { - e.printStackTrace(); } - + catch( IOException e ) + { + LWJGLUtil.log( "XRandR exception in setConfiguration(): " + e.getMessage() ); + } } /** * @return the name of connected screens, or an empty array if * xrandr is not supported */ - public static String[] getScreenNames() { + public static String[] getScreenNames() + { populate(); - return (String[]) screens.keySet().toArray(new String[screens.size()]); + return ( String[] ) screens.keySet().toArray( new String[ screens.size() ] ); } /** @@ -175,82 +199,93 @@ * @return the possible resolutions of the named screen, or * <code>null</code> if there is no such screen */ - public static Screen[] getResolutions(String name) { + public static Screen[] getResolutions( String name ) + { populate(); // clone the array to prevent held copies being altered - return (Screen[]) ((Screen[]) screens.get(name)).clone(); + return ( ( Screen[] ) screens.get( name ) ).clone(); } - - private static final Pattern SCREEN_PATTERN1 = Pattern.compile("^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$"); - private static final Pattern SCREEN_PATTERN2 = Pattern.compile("^(\\d+)x(\\d+)$"); - /** - * Parses a screen configuration and adds it to the list if it's valid. - * - * @param list - * the list to add the Screen to if it's valid - * @param name - * the name of this screen + private static final Pattern SCREEN_PATTERN1 = + Pattern.compile( "^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$" ); + + private static final Pattern SCREEN_PATTERN2 = Pattern.compile( "^(\\d+)x(\\d+)$" ); + + /** + * Parses a screen configuration and adds it to the list if it's + * valid. + * + * @param list + * the list to add the Screen to if it's valid + * @param name + * the name of this screen * @param conf * config string, format either widthxheight or * widthxheight+xPos+yPos - */ - private static void parseScreen(List /* <Screen> */ list, String name, String what) { - Matcher m = SCREEN_PATTERN1.matcher(what); - if(!m.matches()) { - m = SCREEN_PATTERN2.matcher(what); - if(!m.matches()) { - System.out.println("Did not match: " + what); - return; - } - } - int width = Integer.parseInt(m.group(1)); - int height = Integer.parseInt(m.group(2)); - int xpos, ypos; - if(m.groupCount() > 3) { - xpos = Integer.parseInt(m.group(3)); - ypos = Integer.parseInt(m.group(4)); - } else { - xpos = 0; - ypos = 0; - } - list.add(new Screen(name, width, height, xpos, ypos)); - } - + */ + private static void parseScreen( List /* <Screen> */list, String name, String what ) + { + Matcher m = SCREEN_PATTERN1.matcher( what ); + if( !m.matches() ) + { + m = SCREEN_PATTERN2.matcher( what ); + if( !m.matches() ) + { + System.out.println( "Did not match: " + what ); + return; + } + } + int width = Integer.parseInt( m.group( 1 ) ); + int height = Integer.parseInt( m.group( 2 ) ); + int xpos, ypos; + if( m.groupCount() > 3 ) + { + xpos = Integer.parseInt( m.group( 3 ) ); + ypos = Integer.parseInt( m.group( 4 ) ); + } + else + { + xpos = 0; + ypos = 0; + } + list.add( new Screen( name, width, height, xpos, ypos ) ); + } + /** * Encapsulates the configuration of a monitor. Resolution is * fixed, position is mutable * * @author ryanm */ - public static class Screen implements Cloneable { - + public static class Screen implements Cloneable + { /** * Name for this output */ - public final String name; + public final String name; /** * Width in pixels */ - public final int width; + public final int width; /** * Height in pixels */ - public final int height; + public final int height; /** * Position on the x-axis, in pixels */ - public int xPos = 0; + public int xPos = 0; /** * Position on the y-axis, in pixels */ - public int yPos = 0; + public int yPos = 0; - private Screen(String name, int width, int height, int xPos, int yPos) { + private Screen( String name, int width, int height, int xPos, int yPos ) + { this.name = name; this.width = width; this.height = height; @@ -258,17 +293,19 @@ this.yPos = yPos; } - private void getArgs(List/* <String> */argList) { - argList.add("--output"); - argList.add(name); - argList.add("--mode"); - argList.add(width + "x" + height); - argList.add("--pos"); - argList.add(xPos + "x" + yPos); + private void getArgs( List/* <String> */argList ) + { + argList.add( "--output" ); + argList.add( name ); + argList.add( "--mode" ); + argList.add( width + "x" + height ); + argList.add( "--pos" ); + argList.add( xPos + "x" + yPos ); } - // @Override - public String toString() { + @Override + public String toString() + { return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-05-21 22:26:30
|
Revision: 3342 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3342&view=rev Author: kappa1 Date: 2010-05-21 22:26:23 +0000 (Fri, 21 May 2010) Log Message: ----------- XRandr add missing casts Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-21 22:12:57 UTC (rev 3341) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-05-21 22:26:23 UTC (rev 3342) @@ -97,7 +97,7 @@ screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) ); - current = ( Screen[] ) currentList.toArray( new Screen[ currentList.size() ] ); + current = (Screen[]) currentList.toArray(new Screen[currentList.size()]); } catch( Throwable e ) { @@ -116,7 +116,7 @@ { populate(); - return current.clone(); + return (Screen[]) current.clone(); } /** @@ -203,7 +203,7 @@ { populate(); // clone the array to prevent held copies being altered - return ( ( Screen[] ) screens.get( name ) ).clone(); + return (Screen[]) ((Screen[]) screens.get(name)).clone(); } private static final Pattern SCREEN_PATTERN1 = @@ -303,7 +303,7 @@ argList.add( xPos + "x" + yPos ); } - @Override + //@Override public String toString() { return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |