Skip to content

Commit

Permalink
Store XRandR frequencies in the original format to improve #64
Browse files Browse the repository at this point in the history
Also, reset the screen configuration on exit only if there has been a display mode change.
  • Loading branch information
Spasi committed Sep 9, 2016
1 parent d0c96df commit 8bb7dfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/java/org/lwjgl/opengl/LinuxDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ public DisplayMode init() throws LWJGLException {
case XRANDR:
saved_mode = AccessController.doPrivileged(new PrivilegedAction<DisplayMode>() {
public DisplayMode run() {
XRandR.saveConfiguration();
return XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
return XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
}
});
break;
Expand Down
23 changes: 15 additions & 8 deletions src/java/org/lwjgl/opengl/XRandR.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> cmd = new ArrayList<String>();
cmd.add("xrandr");

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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.
Expand All @@ -286,7 +289,7 @@ private static void parseScreenModeline(List<Screen> allModes, List<Screen> 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("*") ) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -381,14 +388,14 @@ private void getArgs(List<String> 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";
}
}
}

0 comments on commit 8bb7dfe

Please sign in to comment.