Skip to content

Commit 57831a9

Browse files
authored
Merge pull request #2500 from JNightRider/platform
Support for switching platforms (from Wayland EGL to X11 GLX)
2 parents 4db274c + 19cb38d commit 57831a9

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

jme3-core/src/main/java/com/jme3/system/AppSettings.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ public final class AppSettings extends HashMap<String, Object> {
295295
defaults.put("UseRetinaFrameBuffer", false);
296296
defaults.put("WindowYPosition", 0);
297297
defaults.put("WindowXPosition", 0);
298+
defaults.put("X11PlatformPreferred", false);
298299
// defaults.put("Icons", null);
299300
}
300301

@@ -1507,4 +1508,28 @@ public int getDisplay() {
15071508
public void setDisplay(int mon) {
15081509
putInteger("Display", mon);
15091510
}
1511+
1512+
/**
1513+
* Sets the preferred native platform for creating the GL context on Linux distributions.
1514+
* <p>
1515+
* This setting is relevant for Linux distributions or derivatives that utilize a Wayland session alongside an X11 via the XWayland bridge.
1516+
* Enabling this option allows the use of GLX for window positioning and/or icon configuration.
1517+
*
1518+
* @param preferred true to prefer GLX (native X11) for the GL context, false to prefer EGL (native Wayland).
1519+
*/
1520+
public void setX11PlatformPreferred(boolean preferred) {
1521+
putBoolean("X11PlatformPreferred", preferred);
1522+
}
1523+
1524+
/**
1525+
* Determines which native platform is preferred for GL context creation on Linux distributions.
1526+
* <p>
1527+
* This setting is only valid on Linux distributions or derivatives that support Wayland,
1528+
* and it indicates whether GLX (native X11) or EGL (native Wayland) is enabled for the GL context.
1529+
*
1530+
* @return true if GLX is preferred, otherwise false if EGL is preferred (native Wayland).
1531+
*/
1532+
public boolean isX11PlatformPreferred() {
1533+
return getBoolean("X11PlatformPreferred");
1534+
}
15101535
}

jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,20 @@ public void invoke(int error, long description) {
275275
);
276276

277277
if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) {
278-
278+
279+
/*
280+
* Change the platform GLFW uses to enable GLX on Wayland as long as you
281+
* have XWayland (X11 compatibility)
282+
*/
283+
if (settings.isX11PlatformPreferred() && glfwPlatformSupported(GLFW_PLATFORM_X11)) {
284+
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
285+
}
286+
279287
// Disables the libdecor bar when creating a fullscreen context
280288
// https://www.glfw.org/docs/latest/intro_guide.html#init_hints_wayland
281289
glfwInitHint(GLFW_WAYLAND_LIBDECOR, settings.isFullscreen() ? GLFW_WAYLAND_DISABLE_LIBDECOR : GLFW_WAYLAND_PREFER_LIBDECOR);
282290
}
283-
291+
284292
if (!glfwInit()) {
285293
throw new IllegalStateException("Unable to initialize GLFW");
286294
}
@@ -404,6 +412,14 @@ public void invoke(final long window, final boolean focus) {
404412
);
405413

406414
int platformId = glfwGetPlatform();
415+
if (settings.isX11PlatformPreferred()) {
416+
if (platformId == GLFW_PLATFORM_X11) {
417+
LOGGER.log(Level.INFO, "Active X11 server for GLX management:\n * Platform: GLFW_PLATFORM_X11|XWayland ({0})", platformId);
418+
} else {
419+
LOGGER.log(Level.WARNING, "Can't change platform to X11 (GLX), check if you have XWayland enabled");
420+
}
421+
}
422+
407423
if (platformId != GLFW_PLATFORM_WAYLAND && !settings.isFullscreen()) {
408424
/*
409425
* in case the window positioning hints above were ignored, but not

0 commit comments

Comments
 (0)