Skip to content

Commit

Permalink
Don't crash when xrandr executable is not accessible
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed May 25, 2022
1 parent 3caaa44 commit b3a3103
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/java/org/lwjgl/opengl/LinuxDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.awt.event.FocusEvent;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteOrder;
Expand Down Expand Up @@ -210,9 +211,25 @@ private static int getBestDisplayModeExtension() {
return result;
}

private static String findXrandr() {
for (String path : System.getenv("PATH").split(File.pathSeparator)) {
File file = new File(path, "xrandr");
if (file.isFile() && file.canExecute()) {
return file.getAbsolutePath();
}
}

return null;
}

private static boolean isXrandrSupported() {
if (Display.getPrivilegedBoolean("LWJGL_DISABLE_XRANDR"))
return false;

if (findXrandr() == null) {
return false;
}

lockAWT();
try {
incDisplay();
Expand Down
1 change: 1 addition & 0 deletions src/java/org/lwjgl/opengl/XRandR.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ private static void populate() {
LWJGLUtil.log("Exception in XRandR.populate(): " + e.getMessage());
screens.clear();
current = new Screen[0];
throw new RuntimeException(e);
}
}

Expand Down

0 comments on commit b3a3103

Please sign in to comment.