Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 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,28 @@ public int getDisplay() {
public void setDisplay(int mon) {
putInteger("Display", mon);
}

/**
* Sets the preferred native platform for creating the GL context on Linux distributions.
* <p>
* This setting is relevant for Linux distributions or derivatives that utilize a Wayland session alongside an X11 via the XWayland bridge.
* Enabling this option allows the use of GLX for window positioning and/or icon configuration.
*
* @param preferred true to prefer GLX (native X11) for the GL context, false to prefer EGL (native Wayland).
*/
public void setX11PlatformPreferred(boolean preferred) {
putBoolean("X11PlatformPreferred", preferred);
}

/**
* Determines which native platform is preferred for GL context creation on Linux distributions.
* <p>
* This setting is only valid on Linux distributions or derivatives that support Wayland,
* and it indicates whether GLX (native X11) or EGL (native Wayland) is enabled for the GL context.
*
* @return true if GLX is preferred, otherwise false if EGL is preferred (native Wayland).
*/
public boolean isX11PlatformPreferred() {
return getBoolean("X11PlatformPreferred");
}
}
20 changes: 18 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 Expand Up @@ -404,6 +412,14 @@ public void invoke(final long window, final boolean focus) {
);

int platformId = glfwGetPlatform();
if (settings.isX11PlatformPreferred()) {
if (platformId == GLFW_PLATFORM_X11) {
LOGGER.log(Level.INFO, "Active X11 server for GLX management:\n * Platform: GLFW_PLATFORM_X11|XWayland ({0})", platformId);
} else {
LOGGER.log(Level.WARNING, "Can't change platform to X11 (GLX), check if you have XWayland enabled");
}
}

if (platformId != GLFW_PLATFORM_WAYLAND && !settings.isFullscreen()) {
/*
* in case the window positioning hints above were ignored, but not
Expand Down
Loading