feat: Unified method for detecting a Wayland session#2848
Conversation
There was a problem hiding this comment.
Code Review
This pull request centralizes Wayland session detection by introducing isWaylandSession() in JmeSystem and JmeSystemDelegate, replacing local checks in LwjglCanvas and LwjglWindow, and deprecating the old isWayland() method in LwjglxDefaultGLPlatform. Feedback includes a recommendation to restrict the Wayland check to Linux/FreeBSD platforms and wrap it in a try-catch block to handle potential SecurityExceptions, as well as a minor typo correction in the Javadoc.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| public boolean isWaylandSession() { | ||
| // The following matches the test GLFW does to enable the Wayland backend. | ||
| if ("wayland".equalsIgnoreCase(System.getenv("XDG_SESSION_TYPE")) && System.getenv("WAYLAND_DISPLAY") != null) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
The isWaylandSession() method should be restricted to Linux/FreeBSD platforms to avoid false positives on other platforms (e.g., Windows/macOS where these environment variables might be set in certain environments like WSL or custom shells). Additionally, accessing environment variables via System.getenv() can throw a SecurityException in environments with restricted permissions (such as applets or custom security managers). Wrapping the platform check and environment lookup in a try-catch block makes the detection robust and safe.
public boolean isWaylandSession() {
try {
Platform platform = getPlatform();
if (platform == Platform.Linux64 || platform == Platform.Linux_ARM64) {
return "wayland".equalsIgnoreCase(System.getenv("XDG_SESSION_TYPE"))
&& System.getenv("WAYLAND_DISPLAY") != null;
}
} catch (SecurityException | UnsupportedOperationException e) {
// Safe fallback for restricted environments or unsupported platforms
}
return false;
}There was a problem hiding this comment.
Users must first determine which platform they are on and then use this method:
if (JmeSystem.getPlatform().getOs() == Platform.Os.Linux) {
if (JmeSystem.isWaylandSession()) {
...
}
}Since isWaylandSession() is not designed to detect the operating system
Currently, Wayland session detection is duplicated in the JME3 code, which can lead to inconsistencies. Therefore, this pull request introduces a way to detect them using
JmeSystem.