summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRafael Bordoni <[email protected]>2024-04-19 10:17:22 -0300
committerGitHub <[email protected]>2024-04-19 15:17:22 +0200
commit88f77629218c71b21cd8ce5cb74bc0a1b38ce1e6 (patch)
treecf31f61176baf7ce87c239e6c7c3362e6bd95628
parentb00e4674949e6005e26a7f4088c491b50ec45886 (diff)
downloadraylib-88f77629218c71b21cd8ce5cb74bc0a1b38ce1e6.tar.gz
raylib-88f77629218c71b21cd8ce5cb74bc0a1b38ce1e6.zip
Fix window not initializing on primary monitor on GLFW backend (#3923)
The way the current code worked was by calling `GetCurrentMonitor()`, which would always return the monitor at position (0,0). This isn't the primary monitor on all platforms, on Linux in particular it isn't the case. This isn't the case on the SDL backend, after calling `InitWindow()` the window would always show up on the primary monitor. Even on the GLFW backend, if the full screen flag was set it would attempt to put it on the primary monitor as it would call `glfwGetPrimaryMonitor()` to do it, so for consistency's sake we should do it on windowed mode too.
-rw-r--r--src/platforms/rcore_desktop.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/platforms/rcore_desktop.c b/src/platforms/rcore_desktop.c
index 64e79c6d..211a6cbb 100644
--- a/src/platforms/rcore_desktop.c
+++ b/src/platforms/rcore_desktop.c
@@ -1518,10 +1518,16 @@ int InitPlatform(void)
else
{
// Try to center window on screen but avoiding window-bar outside of screen
- int posX = GetMonitorWidth(GetCurrentMonitor())/2 - CORE.Window.screen.width/2;
- int posY = GetMonitorHeight(GetCurrentMonitor())/2 - CORE.Window.screen.height/2;
- if (posX < 0) posX = 0;
- if (posY < 0) posY = 0;
+ int monitorX = 0;
+ int monitorY = 0;
+ int monitorWidth = 0;
+ int monitorHeight = 0;
+ glfwGetMonitorWorkarea(monitor, &monitorX, &monitorY, &monitorWidth, &monitorHeight);
+
+ int posX = monitorX + (monitorWidth - CORE.Window.screen.width)/2;
+ int posY = monitorY + (monitorHeight - CORE.Window.screen.height)/2;
+ if (posX < monitorX) posX = monitorX;
+ if (posY < monitorY) posY = monitorY;
SetWindowPosition(posX, posY);
}