Skip to content

Commit

Permalink
little ToggleFullscreen() cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperUserNameMan committed Jul 11, 2024
1 parent 21bff48 commit a76adf9
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/platforms/rcore_desktop_glfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void ToggleFullscreen(void)
if (!CORE.Window.fullscreen)
{
// Store previous window position (in case we exit fullscreen)
glfwGetWindowPos(platform.handle, &CORE.Window.position.x, &CORE.Window.position.y);
glfwGetWindowPos(platform.handle, &CORE.Window.previousPosition.x, &CORE.Window.previousPosition.y);

int monitorCount = 0;
int monitorIndex = GetCurrentMonitor();
Expand All @@ -156,14 +156,19 @@ void ToggleFullscreen(void)
// Use current monitor, so we correctly get the display the window is on
GLFWmonitor *monitor = (monitorIndex < monitorCount)? monitors[monitorIndex] : NULL;

// The size at which the content of the window shall be rendered
// taking into account the DPI scaling if FLAG_WINDOW_HIGHDPI is set :
int renderingWidth = GetRenderWidth();
int renderingHeight = GetRenderHeight();

if (monitor == NULL)
{
TRACELOG(LOG_WARNING, "GLFW: Failed to get monitor");

CORE.Window.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;

glfwSetWindowMonitor(platform.handle, NULL, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
// There is nothing more to do. Just leave the window where it is.
}
else
{
Expand All @@ -173,13 +178,10 @@ void ToggleFullscreen(void)
// We need to save the "size at which the content of the window is rendered"
// because we might have FLAG_WINDOW_HIGHDPI enabled.

int renderWidth = GetRenderWidth();
int renderHeight = GetRenderHeight();

CORE.Window.previousScreen.width = renderWidth;
CORE.Window.previousScreen.height = renderHeight;
CORE.Window.previousScreen.width = renderingWidth;
CORE.Window.previousScreen.height = renderingHeight;

glfwSetWindowMonitor(platform.handle, monitor, 0, 0, renderWidth, renderHeight, GLFW_DONT_CARE);
glfwSetWindowMonitor(platform.handle, monitor, 0, 0, renderingWidth, renderingHeight, GLFW_DONT_CARE);
}

}
Expand All @@ -188,7 +190,7 @@ void ToggleFullscreen(void)
CORE.Window.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;

glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height, GLFW_DONT_CARE);
glfwSetWindowMonitor(platform.handle, NULL, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height, GLFW_DONT_CARE);
}

// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
Expand Down

0 comments on commit a76adf9

Please sign in to comment.