diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 3ce738a8a..30728fa3e 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -742,8 +742,7 @@ public DisplayMode init() throws LWJGLException { case XRANDR: saved_mode = AccessController.doPrivileged(new PrivilegedAction() { public DisplayMode run() { - XRandR.saveConfiguration(); - return XRandR.ScreentoDisplayMode(XRandR.getConfiguration()); + return XRandR.ScreentoDisplayMode(XRandR.getConfiguration()); } }); break; diff --git a/src/java/org/lwjgl/opengl/XRandR.java b/src/java/org/lwjgl/opengl/XRandR.java index 6630f972d..8e59bb64a 100644 --- a/src/java/org/lwjgl/opengl/XRandR.java +++ b/src/java/org/lwjgl/opengl/XRandR.java @@ -177,6 +177,9 @@ public static void setConfiguration(boolean disableOthers, Screen... screens) { if ( screens.length == 0 ) throw new IllegalArgumentException("Must specify at least one screen"); + if ( savedConfiguration == null ) + saveConfiguration(); + List cmd = new ArrayList(); cmd.add("xrandr"); @@ -222,7 +225,7 @@ public static void setConfiguration(boolean disableOthers, Screen... screens) { * This configuration can be restored on exit/crash by calling * restoreConfiguration() */ - public static void saveConfiguration() { + private static void saveConfiguration() { populate(); savedConfiguration = current.clone(); } @@ -260,7 +263,7 @@ public static Screen[] getResolutions(String name) { private static final Pattern SCREEN_HEADER_PATTERN = Pattern.compile("^(\\d+)x(\\d+)[+](\\d+)[+](\\d+)$"); private static final Pattern SCREEN_MODELINE_PATTERN = Pattern.compile("^(\\d+)x(\\d+)$"); - private static final Pattern FREQ_PATTERN = Pattern.compile("^(\\d+)[.](\\d+)(?:\\s*[*])?(?:\\s*[+])?$"); + private static final Pattern FREQ_PATTERN = Pattern.compile("^(\\d+[.]\\d+)(?:\\s*[*])?(?:\\s*[+])?$"); /** * Parses a screen configuration and adds it to one of the lists if valid. @@ -286,7 +289,7 @@ private static void parseScreenModeline(List allModes, List curr return; } - int freq = Integer.parseInt(m.group(1)); + String freq = m.group(1); Screen s = new Screen(name, width, height, freq, 0, 0); if ( freqS.contains("*") ) { @@ -322,7 +325,7 @@ private static void parseScreenHeader(int[] screenPosition, String resPos) { static Screen DisplayModetoScreen(DisplayMode mode) { populate(); Screen primary = findPrimary(current); - return new Screen(primary.name, mode.getWidth(), mode.getHeight(), mode.getFrequency(), primary.xPos, primary.yPos); + return new Screen(primary.name, mode.getWidth(), mode.getHeight(), Integer.toString(mode.getFrequency()), primary.xPos, primary.yPos); } static DisplayMode ScreentoDisplayMode(Screen... screens) { @@ -360,17 +363,21 @@ public static class Screen implements Cloneable { /** Frequency in Hz */ public final int freq; + /** Frequency in Hz, in the original decimal format */ + final String freqOriginal; + /** Position on the x-axis, in pixels */ public int xPos; /** Position on the y-axis, in pixels */ public int yPos; - Screen(String name, int width, int height, int freq, int xPos, int yPos) { + Screen(String name, int width, int height, String freq, int xPos, int yPos) { this.name = name; this.width = width; this.height = height; - this.freq = freq; + this.freq = (int)Float.parseFloat(freq); + this.freqOriginal = freq; this.xPos = xPos; this.yPos = yPos; } @@ -381,14 +388,14 @@ private void getArgs(List argList) { argList.add("--mode"); argList.add(width + "x" + height); argList.add("--rate"); - argList.add(Integer.toString(freq)); + argList.add(freqOriginal); argList.add("--pos"); argList.add(xPos + "x" + yPos); } //@Override public String toString() { - return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos + " with " + freq + "Hz"; + return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos + " with " + freqOriginal + "Hz"; } } } \ No newline at end of file