Skip to content

feat: Unified method for detecting a Wayland session#2848

Open
JNightRider wants to merge 5 commits into
jMonkeyEngine:masterfrom
JNightRider:feature/check-wayland-session
Open

feat: Unified method for detecting a Wayland session#2848
JNightRider wants to merge 5 commits into
jMonkeyEngine:masterfrom
JNightRider:feature/check-wayland-session

Conversation

@JNightRider
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +312 to +318
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;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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;
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread jme3-core/src/main/java/com/jme3/system/JmeSystem.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant