Kaynağa Gözat

provide positioning hints when creating a window with LWJGL3

stephengold 8 ay önce
ebeveyn
işleme
9b88901e8b

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

@@ -298,6 +298,20 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
             requestWidth = videoMode.width();
             requestHeight = videoMode.height();
         }
+        int requestX = GLFW_ANY_POSITION;
+        int requestY = GLFW_ANY_POSITION;
+        if (!settings.isFullscreen()) {
+            if (settings.getCenterWindow()) {
+                // Center the window
+                requestX = videoMode.width() - requestWidth;
+                requestY = videoMode.height() - requestWidth;
+            } else {
+                requestX = settings.getWindowXPosition();
+                requestY = settings.getWindowYPosition();
+            }
+            glfwWindowHint(GLFW_POSITION_X, requestX);
+            glfwWindowHint(GLFW_POSITION_Y, requestY);
+        }
         window = glfwCreateWindow(requestWidth, requestHeight, settings.getTitle(), monitor, NULL);
         if (window == NULL) {
             throw new RuntimeException("Failed to create the GLFW window");
@@ -321,17 +335,11 @@ public abstract class LwjglWindow extends LwjglContext implements Runnable {
 
         int platformId = glfwGetPlatform();
         if (platformId != GLFW_PLATFORM_WAYLAND && !settings.isFullscreen()) {
-            // Wayland doesn't support window positioning.
-            if (settings.getCenterWindow()) {
-                // Center the window
-                glfwSetWindowPos(window,
-                        (videoMode.width() - requestWidth) / 2,
-                        (videoMode.height() - requestHeight) / 2);
-            } else {
-                glfwSetWindowPos(window,
-                        settings.getWindowXPosition(),
-                        settings.getWindowYPosition());
-            }
+            /*
+             * in case the window positioning hints above were ignored, but not
+             * on Wayland, since Wayland doesn't support window positioning.
+             */
+            glfwSetWindowPos(window, requestX, requestY);
         }
 
         // Make the OpenGL context current