11/*
2- * Copyright (c) 2009-2023 jMonkeyEngine
2+ * Copyright (c) 2009-2025 jMonkeyEngine
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
@@ -353,13 +353,27 @@ public void invoke(int error, long description) {
353353 requestWidth = videoMode .width ();
354354 requestHeight = videoMode .height ();
355355 }
356-
356+ int requestX = GLFW_ANY_POSITION ;
357+ int requestY = GLFW_ANY_POSITION ;
358+ if (!settings .isFullscreen ()) {
359+ if (settings .getCenterWindow ()) {
360+ // Center the window
361+ requestX = videoMode .width () - requestWidth ;
362+ requestY = videoMode .height () - requestWidth ;
363+ } else {
364+ requestX = settings .getWindowXPosition ();
365+ requestY = settings .getWindowYPosition ();
366+ }
367+ glfwWindowHint (GLFW_POSITION_X , requestX );
368+ glfwWindowHint (GLFW_POSITION_Y , requestY );
369+ }
357370 // Lets use the monitor selected from AppSettings if FullScreen is
358371 // set.
359- if (settings .isFullscreen ()) window =
360- glfwCreateWindow (requestWidth , requestHeight , settings .getTitle (), monitor , NULL ); else window =
361- glfwCreateWindow (requestWidth , requestHeight , settings .getTitle (), NULL , NULL );
362-
372+ if (settings .isFullscreen ()) {
373+ window = glfwCreateWindow (requestWidth , requestHeight , settings .getTitle (), monitor , NULL );
374+ } else {
375+ window = glfwCreateWindow (requestWidth , requestHeight , settings .getTitle (), NULL , NULL );
376+ }
363377 if (window == NULL ) {
364378 throw new RuntimeException ("Failed to create the GLFW window" );
365379 }
@@ -383,17 +397,13 @@ public void invoke(final long window, final boolean focus) {
383397 }
384398 );
385399
386- if (!settings .isFullscreen ()) {
387- if (settings .getCenterWindow ()) {
388- // Center the window
389- glfwSetWindowPos (
390- window ,
391- (videoMode .width () - requestWidth ) / 2 ,
392- (videoMode .height () - requestHeight ) / 2
393- );
394- } else {
395- glfwSetWindowPos (window , settings .getWindowXPosition (), settings .getWindowYPosition ());
396- }
400+ int platformId = glfwGetPlatform ();
401+ if (platformId != GLFW_PLATFORM_WAYLAND && !settings .isFullscreen ()) {
402+ /*
403+ * in case the window positioning hints above were ignored, but not
404+ * on Wayland, since Wayland doesn't support window positioning
405+ */
406+ glfwSetWindowPos (window , requestX , requestY );
397407 }
398408
399409 // Make the OpenGL context current
@@ -490,6 +500,11 @@ protected void showWindow() {
490500 * @param settings settings for getting the icons
491501 */
492502 protected void setWindowIcon (final AppSettings settings ) {
503+ if (glfwGetPlatform () == GLFW_PLATFORM_WAYLAND ) {
504+ // Wayland doesn't support custom icons.
505+ return ;
506+ }
507+
493508 final Object [] icons = settings .getIcons ();
494509 if (icons == null ) return ;
495510
0 commit comments