Skip to content

Commit

Permalink
Changes SetWindowMonitor() to no longer force fullscreen
Browse files Browse the repository at this point in the history
  • Loading branch information
ubkp committed Jul 28, 2023
1 parent 5d28bad commit 4d08d82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ RLAPI void SetWindowIcon(Image image); // Set icon fo
RLAPI void SetWindowIcons(Image *images, int count); // Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
RLAPI void SetWindowTitle(const char *title); // Set title for window (only PLATFORM_DESKTOP)
RLAPI void SetWindowPosition(int x, int y); // Set window position on screen (only PLATFORM_DESKTOP)
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window (fullscreen mode)
RLAPI void SetWindowMonitor(int monitor); // Set monitor for the current window
RLAPI void SetWindowMinSize(int width, int height); // Set window minimum dimensions (for FLAG_WINDOW_RESIZABLE)
RLAPI void SetWindowSize(int width, int height); // Set window dimensions
RLAPI void SetWindowOpacity(float opacity); // Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
Expand Down
28 changes: 23 additions & 5 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ void SetWindowPosition(int x, int y)
#endif
}

// Set monitor for the current window (fullscreen mode)
// Set monitor for the current window
void SetWindowMonitor(int monitor)
{
#if defined(PLATFORM_DESKTOP)
Expand All @@ -1670,10 +1670,28 @@ void SetWindowMonitor(int monitor)

if ((monitor >= 0) && (monitor < monitorCount))
{
TRACELOG(LOG_INFO, "GLFW: Selected fullscreen monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));

const GLFWvidmode *mode = glfwGetVideoMode(monitors[monitor]);
glfwSetWindowMonitor(CORE.Window.handle, monitors[monitor], 0, 0, mode->width, mode->height, mode->refreshRate);
if (!CORE.Window.fullscreen)
{
TRACELOG(LOG_INFO, "GLFW: Selected monitor: [%i] %s", monitor, glfwGetMonitorName(monitors[monitor]));

const int screenWidth = CORE.Window.screen.width;
const int screenHeight = CORE.Window.screen.height;
int monitorWorkareaX = 0;
int monitorWorkareaY = 0;
int monitorWorkareaWidth = 0;
int monitorWorkareaHeight = 0;
glfwGetMonitorWorkarea(monitors[monitor], &monitorWorkareaX, &monitorWorkareaY, &monitorWorkareaWidth, &monitorWorkareaHeight);

// If the screen size is larger than the monitor workarea, anchor it on the top left corner, otherwise, center it
if ((screenWidth >= monitorWorkareaWidth) || (screenHeight >= monitorWorkareaHeight)) glfwSetWindowPos(CORE.Window.handle, monitorWorkareaX, monitorWorkareaY);
else
{
const int x = monitorWorkareaX + (monitorWorkareaWidth*0.5f) - (screenWidth*0.5f);
const int y = monitorWorkareaY + (monitorWorkareaHeight*0.5f) - (screenHeight*0.5f);
glfwSetWindowPos(CORE.Window.handle, x, y);
}
}
else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor because it's on fullscreen");
}
else TRACELOG(LOG_WARNING, "GLFW: Failed to find selected monitor");
#endif
Expand Down

0 comments on commit 4d08d82

Please sign in to comment.