Skip to content

Support for switching platforms (from Wayland EGL to X11 GLX) #2500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions jme3-core/src/main/java/com/jme3/system/AppSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public final class AppSettings extends HashMap<String, Object> {
defaults.put("UseRetinaFrameBuffer", false);
defaults.put("WindowYPosition", 0);
defaults.put("WindowXPosition", 0);
defaults.put("X11PlatformPreferred", false);
// defaults.put("Icons", null);
}

Expand Down Expand Up @@ -1507,4 +1508,36 @@ public int getDisplay() {
public void setDisplay(int mon) {
putInteger("Display", mon);
}

/**
* Sets the native platform to be used to create the GL context.
*
* <p>
* This only affects Linux distributions or derivatives that use a Wayland session in conjunction
* with X11 via the XWayland bridge, which enables or disables GLX for window positioning and/or
* icon configuration.
* </p>
*
* <p>
* <strong>NOTE:</strong> Note that disabling this option uses GLX (native X11) instead of EGL (native WL).
* </p>
*
* @param nplaf true if you want to enable GLX, otherwise false when using EGL (native)
*/
public void setX11PlatformPreferred(boolean nplaf) {
put("X11PlatformPreferred", nplaf);
}

/**
* Gets what type of platform is being used.
*
* <p>
* Only valid on Linux distributions or derivatives that support Wayland, where it indicates whether GLX or EGL is enabled.
* </p>
*
* @return returns true if GLX is enabled, otherwise false if used in EGL (native)
*/
public boolean isX11PlatformPreferred() {
return getBoolean("X11PlatformPreferred");
}
}
12 changes: 10 additions & 2 deletions jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,20 @@ public void invoke(int error, long description) {
);

if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {


/*
* Change the platform GLFW uses to enable GLX on Wayland as long as you
* have XWayland (X11 compatibility)
*/
if (settings.isX11PlatformPreferred() && glfwPlatformSupported(GLFW_PLATFORM_X11)) {
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
}

// Disables the libdecor bar when creating a fullscreen context
// https://www.glfw.org/docs/latest/intro_guide.html#init_hints_wayland
glfwInitHint(GLFW_WAYLAND_LIBDECOR, settings.isFullscreen() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
}

if (!glfwInit()) {
throw new IllegalStateException("Unable to initialize GLFW");
}
Expand Down