Skip to content

Commit

Permalink
(Draft) Add FLAG_FULLSCREEN_DESKTOP
Browse files Browse the repository at this point in the history
  • Loading branch information
M374LX committed Oct 6, 2023
1 parent bc15c19 commit 62d3066
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/raylib.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,8 @@ typedef enum {
FLAG_WINDOW_MOUSE_PASSTHROUGH = 0x00004000, // Set to support mouse passthrough, only supported when FLAG_WINDOW_UNDECORATED
FLAG_BORDERLESS_WINDOWED_MODE = 0x00008000, // Set to run program in borderless windowed mode
FLAG_MSAA_4X_HINT = 0x00000020, // Set to try enabling MSAA 4X
FLAG_INTERLACED_HINT = 0x00010000 // Set to try enabling interlaced video format (for V3D)
FLAG_INTERLACED_HINT = 0x00010000, // Set to try enabling interlaced video format (for V3D)
FLAG_FULLSCREEN_DESKTOP = 0x00020000 // Set to prevent a video mode change when toggling fullscreen mode
} ConfigFlags;

// Trace log level
Expand Down
34 changes: 32 additions & 2 deletions src/rcore.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ typedef struct CoreData {
Size previousScreen; // Screen previous width and height (required on borderless windowed toggle)
Size currentFbo; // Current render width and height (depends on active fbo)
Size render; // Framebuffer width and height (render area, including black bars if required)
Size restoreSize;
Point renderOffset; // Offset from render area (must be divided by 2)
Size screenMin; // Screen minimum width and height (for resizable window)
Size screenMax; // Screen maximum width and height (for resizable window)
Expand Down Expand Up @@ -1223,18 +1224,35 @@ void ToggleFullscreen(void)
}
else
{
int width = CORE.Window.screen.width;
int height = CORE.Window.screen.height;
int refreshRate = GLFW_DONT_CARE;

if (IsWindowState(FLAG_FULLSCREEN_DESKTOP))
{
CORE.Window.restoreSize.width = width;
CORE.Window.restoreSize.height = height;

width = GetMonitorWidth(monitorIndex);
height = GetMonitorHeight(monitorIndex);
refreshRate = GetMonitorRefreshRate(monitorIndex);

CORE.Window.screen.width = width;
CORE.Window.screen.height = height;
}

CORE.Window.fullscreen = true;
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;

glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
glfwSetWindowMonitor(CORE.Window.handle, monitor, 0, 0, width, height, refreshRate);
}
}
else
{
CORE.Window.fullscreen = false;
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;

glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.screen.width, CORE.Window.screen.height, GLFW_DONT_CARE);
glfwSetWindowMonitor(CORE.Window.handle, NULL, CORE.Window.position.x, CORE.Window.position.y, CORE.Window.restoreSize.width, CORE.Window.restoreSize.height, GLFW_DONT_CARE);
}

// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
Expand Down Expand Up @@ -1439,6 +1457,12 @@ void SetWindowState(unsigned int flags)
CORE.Window.flags |= FLAG_VSYNC_HINT;
}

// State change: FLAG_FULLSCREEN_DESKTOP
if (((CORE.Window.flags & FLAG_FULLSCREEN_DESKTOP) != (flags & FLAG_FULLSCREEN_DESKTOP)) && ((flags & FLAG_FULLSCREEN_DESKTOP) > 0))
{
CORE.Window.flags |= FLAG_FULLSCREEN_DESKTOP;
}

// State change: FLAG_BORDERLESS_WINDOWED_MODE
// NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) != (flags & FLAG_BORDERLESS_WINDOWED_MODE)) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
Expand Down Expand Up @@ -1556,6 +1580,12 @@ void ClearWindowState(unsigned int flags)
CORE.Window.flags &= ~FLAG_VSYNC_HINT;
}

// State change: FLAG_WINDOW_FULLSCREEN_DESKTOP
if (((CORE.Window.flags & FLAG_FULLSCREEN_DESKTOP) > 0) && ((flags & FLAG_FULLSCREEN_DESKTOP) > 0))
{
CORE.Window.flags &= ~FLAG_FULLSCREEN_DESKTOP;
}

// State change: FLAG_BORDERLESS_WINDOWED_MODE
// NOTE: This must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running
if (((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0) && ((flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0))
Expand Down

0 comments on commit 62d3066

Please sign in to comment.