Skip to content

[rcore][RGFW] bug fixes #4798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 10, 2025
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 63 additions & 23 deletions src/platforms/rcore_desktop_rgfw.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,22 @@ bool InitGraphicsDevice(void); // Initialize graphics device
// Check if application should close
bool WindowShouldClose(void)
{
if (CORE.Window.shouldClose == false)
if (CORE.Window.shouldClose == false && platform.window != NULL)
CORE.Window.shouldClose = RGFW_window_shouldClose(platform.window);
if (CORE.Window.ready) return CORE.Window.shouldClose;
else return true;
}

// Toggle fullscreen mode
void ToggleFullscreen(void)
{
{
if (platform.window == NULL) return;

if (!CORE.Window.fullscreen)
{
// Store previous window position (in case we exit fullscreen)
CORE.Window.previousPosition = CORE.Window.position;
CORE.Window.previousScreen = CORE.Window.screen;

platform.mon = RGFW_window_getMonitor(platform.window);
CORE.Window.fullscreen = true;
Expand All @@ -292,7 +295,9 @@ void ToggleFullscreen(void)

// we update the window position right away
CORE.Window.position = CORE.Window.previousPosition;
RGFW_window_setFullscreen(platform.window, 0);
RGFW_window_move(platform.window, RGFW_POINT(CORE.Window.position.x, CORE.Window.position.y));
RGFW_window_resize(platform.window, RGFW_AREA(CORE.Window.previousScreen.width, CORE.Window.previousScreen.height));
}

// Try to enable GPU V-Sync, so frames are limited to screen refresh rate (60Hz -> 60 FPS)
Expand All @@ -303,8 +308,7 @@ void ToggleFullscreen(void)
// Toggle borderless windowed mode
void ToggleBorderlessWindowed(void)
{
if (platform.window == NULL)
return;
if (platform.window == NULL) return;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to avoid adding that check to all the functions, if that check is required I think it should be implemented in RGFW library side.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, they exist on the RGFW side as asserts.


if (CORE.Window.fullscreen)
{
Expand All @@ -328,18 +332,23 @@ void ToggleBorderlessWindowed(void)
// Set window state: maximized, if resizable
void MaximizeWindow(void)
{
if (platform.window == NULL) return;
RGFW_window_maximize(platform.window);
}

// Set window state: minimized
void MinimizeWindow(void)
{
if (platform.window == NULL) return;

RGFW_window_minimize(platform.window);
}

// Set window state: not minimized/maximized
void RestoreWindow(void)
{
if (platform.window == NULL) return;

if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED))
RGFW_window_focus(platform.window);

Expand All @@ -351,7 +360,7 @@ void SetWindowState(unsigned int flags)
{
CORE.Window.flags |= flags;

if (flags & FLAG_VSYNC_HINT)
if (flags & FLAG_VSYNC_HINT && platform.window != NULL)
{
RGFW_window_swapInterval(platform.window, 1);
}
Expand All @@ -360,24 +369,24 @@ void SetWindowState(unsigned int flags)
if (!CORE.Window.fullscreen)
ToggleFullscreen();
}
if (flags & FLAG_WINDOW_RESIZABLE)
if (flags & FLAG_WINDOW_RESIZABLE && platform.window != NULL)
{
RGFW_window_setMaxSize(platform.window, RGFW_AREA(0, 0));
RGFW_window_setMinSize(platform.window, RGFW_AREA(0, 0));
}
if (flags & FLAG_WINDOW_UNDECORATED)
if (flags & FLAG_WINDOW_UNDECORATED && platform.window != NULL)
{
RGFW_window_setBorder(platform.window, 0);
}
if (flags & FLAG_WINDOW_HIDDEN)
if (flags & FLAG_WINDOW_HIDDEN && platform.window != NULL)
{
RGFW_window_hide(platform.window);
}
if (flags & FLAG_WINDOW_MINIMIZED)
if (flags & FLAG_WINDOW_MINIMIZED && platform.window != NULL)
{
RGFW_window_minimize(platform.window);
}
if (flags & FLAG_WINDOW_MAXIMIZED)
if (flags & FLAG_WINDOW_MAXIMIZED && platform.window != NULL)
{
RGFW_window_maximize(platform.window);
}
Expand All @@ -401,7 +410,7 @@ void SetWindowState(unsigned int flags)
{
TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization");
}
if (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH)
if (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH && platform.window != NULL)
{
RGFW_window_setMousePassthrough(platform.window, 1);
}
Expand All @@ -424,7 +433,7 @@ void ClearWindowState(unsigned int flags)
{
CORE.Window.flags &= ~flags;

if (flags & FLAG_VSYNC_HINT)
if (flags & FLAG_VSYNC_HINT && platform.window != NULL)
{
RGFW_window_swapInterval(platform.window, 0);
}
Expand All @@ -433,29 +442,29 @@ void ClearWindowState(unsigned int flags)
if (CORE.Window.fullscreen)
ToggleFullscreen();
}
if (flags & FLAG_WINDOW_RESIZABLE)
if (flags & FLAG_WINDOW_RESIZABLE && platform.window != NULL)
{
RGFW_window_setMaxSize(platform.window, RGFW_AREA(platform.window->r.w, platform.window->r.h));
RGFW_window_setMinSize(platform.window, RGFW_AREA(platform.window->r.w, platform.window->r.h));
}
if (flags & FLAG_WINDOW_UNDECORATED)
if (flags & FLAG_WINDOW_UNDECORATED && platform.window != NULL)
{
RGFW_window_setBorder(platform.window, 1);
}
if (flags & FLAG_WINDOW_HIDDEN)
if (flags & FLAG_WINDOW_HIDDEN && platform.window != NULL)
{
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED))
RGFW_window_focus(platform.window);
RGFW_window_show(platform.window);
}
if (flags & FLAG_WINDOW_MINIMIZED)
if (flags & FLAG_WINDOW_MINIMIZED && platform.window != NULL)
{
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED))
RGFW_window_focus(platform.window);

RGFW_window_restore(platform.window);
}
if (flags & FLAG_WINDOW_MAXIMIZED)
if (flags & FLAG_WINDOW_MAXIMIZED && platform.window != NULL)
{
if (!(CORE.Window.flags & FLAG_WINDOW_UNFOCUSED))
RGFW_window_focus(platform.window);
Expand All @@ -465,7 +474,7 @@ void ClearWindowState(unsigned int flags)
{
CORE.Window.flags &= ~FLAG_WINDOW_UNFOCUSED;
}
if (flags & FLAG_WINDOW_TOPMOST)
if (flags & FLAG_WINDOW_TOPMOST && platform.window != NULL)
{
RGFW_window_setFloating(platform.window, RGFW_FALSE);
}
Expand All @@ -481,7 +490,7 @@ void ClearWindowState(unsigned int flags)
{
TRACELOG(LOG_WARNING, "WINDOW: High DPI can only be configured before window initialization");
}
if (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH)
if (flags & FLAG_WINDOW_MOUSE_PASSTHROUGH && platform.window != NULL)
{
RGFW_window_setMousePassthrough(platform.window, 0);
}
Expand Down Expand Up @@ -532,18 +541,23 @@ int RGFW_formatToChannels(int format)
case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: // 2 bpp
return 4;
default: return 4;
return 4;
default: return 4;
}
}

// Set icon for window
void SetWindowIcon(Image image)
{
if (platform.window == NULL) return;
RGFW_window_setIcon(platform.window, image.data, RGFW_AREA(image.width, image.height), RGFW_formatToChannels(image.format));
}

// Set icon for window
void SetWindowIcons(Image *images, int count)
{
if (platform.window == NULL) return;

if ((images == NULL) || (count <= 0))
{
RGFW_window_setIcon(platform.window, NULL, RGFW_AREA(0, 0), 0);
Expand All @@ -568,25 +582,30 @@ void SetWindowIcons(Image *images, int count)
// Set title for window
void SetWindowTitle(const char *title)
{
if (platform.window == NULL) return;

RGFW_window_setName(platform.window, (char *)title);
CORE.Window.title = title;
}

// Set window position on screen (windowed mode)
void SetWindowPosition(int x, int y)
{
if (platform.window == NULL) return;
RGFW_window_move(platform.window, RGFW_POINT(x, y));
}

// Set monitor for the current window
void SetWindowMonitor(int monitor)
{
if (platform.window == NULL) return;
RGFW_window_moveToMonitor(platform.window, RGFW_getMonitors()[monitor]);
}

// Set window minimum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMinSize(int width, int height)
{
if (platform.window == NULL) return;
RGFW_window_setMinSize(platform.window, RGFW_AREA(width, height));
CORE.Window.screenMin.width = width;
CORE.Window.screenMin.height = height;
Expand All @@ -595,6 +614,7 @@ void SetWindowMinSize(int width, int height)
// Set window maximum dimensions (FLAG_WINDOW_RESIZABLE)
void SetWindowMaxSize(int width, int height)
{
if (platform.window == NULL) return;
RGFW_window_setMaxSize(platform.window, RGFW_AREA(width, height));
CORE.Window.screenMax.width = width;
CORE.Window.screenMax.height = height;
Expand All @@ -603,6 +623,7 @@ void SetWindowMaxSize(int width, int height)
// Set window dimensions
void SetWindowSize(int width, int height)
{
if (platform.window == NULL) return;
CORE.Window.screen.width = width;
CORE.Window.screen.height = height;

Expand All @@ -612,18 +633,21 @@ void SetWindowSize(int width, int height)
// Set window opacity, value opacity is between 0.0 and 1.0
void SetWindowOpacity(float opacity)
{
if (platform.window == NULL) return;
RGFW_window_setOpacity(platform.window, opacity);
}

// Set window focused
void SetWindowFocused(void)
{
if (platform.window == NULL) return;
RGFW_window_focus(platform.window);
}

// Get native window handle
void *GetWindowHandle(void)
{
if (platform.window == NULL) return NULL;
#ifdef RGFW_WEBASM
return (void *)platform.window->src.ctx;
#else
Expand Down Expand Up @@ -653,9 +677,11 @@ int GetMonitorCount(void)

// Get number of monitors
int GetCurrentMonitor(void)
{
{
RGFW_monitor *mons = RGFW_getMonitors();
RGFW_monitor mon = RGFW_window_getMonitor(platform.window);
RGFW_monitor mon;
if (platform.window) mon = RGFW_window_getMonitor(platform.window);
else mon = RGFW_getPrimaryMonitor();

for (int i = 0; i < 6; i++)
{
Expand Down Expand Up @@ -724,13 +750,16 @@ const char *GetMonitorName(int monitor)
// Get window position XY on monitor
Vector2 GetWindowPosition(void)
{
if (platform.window == NULL) return (Vector2){ 0.0f, 0.0f };
return (Vector2){ (float)platform.window->r.x, (float)platform.window->r.y };
}

// Get window scale DPI factor for current monitor
Vector2 GetWindowScaleDPI(void)
{
RGFW_monitor monitor = RGFW_window_getMonitor(platform.window);
RGFW_monitor monitor;
if (platform.window) monitor = RGFW_window_getMonitor(platform.window);
else monitor = RGFW_getPrimaryMonitor();

return (Vector2){monitor.scaleX, monitor.scaleX};
}
Expand Down Expand Up @@ -785,20 +814,23 @@ Image GetClipboardImage(void)
// Show mouse cursor
void ShowCursor(void)
{
if (platform.window == NULL) return;
RGFW_window_showMouse(platform.window, true);
CORE.Input.Mouse.cursorHidden = false;
}

// Hides mouse cursor
void HideCursor(void)
{
if (platform.window == NULL) return;
RGFW_window_showMouse(platform.window, false);
CORE.Input.Mouse.cursorHidden = true;
}

// Enables cursor (unlock cursor)
void EnableCursor(void)
{
if (platform.window == NULL) return;
RGFW_disableCursor = false;
RGFW_window_mouseUnhold(platform.window);

Expand All @@ -811,6 +843,7 @@ void EnableCursor(void)
// Disables cursor (lock cursor)
void DisableCursor(void)
{
if (platform.window == NULL) return;
RGFW_disableCursor = true;
RGFW_window_mouseHold(platform.window, RGFW_AREA(0, 0));
HideCursor();
Expand All @@ -819,6 +852,7 @@ void DisableCursor(void)
// Swap back buffer with front buffer (screen drawing)
void SwapScreenBuffer(void)
{
if (platform.window == NULL) return;
RGFW_window_swapBuffers(platform.window);
}

Expand Down Expand Up @@ -871,6 +905,7 @@ void SetGamepadVibration(int gamepad, float leftMotor, float rightMotor, float d
// Set mouse position XY
void SetMousePosition(int x, int y)
{
if (platform.window == NULL) return;
RGFW_window_moveMouse(platform.window, RGFW_POINT(x, y));
CORE.Input.Mouse.currentPosition = (Vector2){ (float)x, (float)y };
CORE.Input.Mouse.previousPosition = CORE.Input.Mouse.currentPosition;
Expand All @@ -879,6 +914,7 @@ void SetMousePosition(int x, int y)
// Set mouse cursor
void SetMouseCursor(int cursor)
{
if (platform.window == NULL) return;
RGFW_window_setMouseStandard(platform.window, cursor);
}

Expand Down Expand Up @@ -914,6 +950,7 @@ int RGFW_gpConvTable[18] = {
// Register all input events
void PollInputEvents(void)
{
if (platform.window == NULL) return;
#if defined(SUPPORT_GESTURES_SYSTEM)
// NOTE: Gestures update must be called every frame to reset gestures correctly
// because ProcessGestureEvent() is just called on an event, not every frame
Expand Down Expand Up @@ -989,8 +1026,10 @@ void PollInputEvents(void)
case RGFW_quit:
if (CORE.Window.flags & FLAG_WINDOW_ALWAYS_RUN)
event->type = 0;
else
else {
CORE.Window.shouldClose = true;
return;
}
break;
case RGFW_DND: // Dropped file
{
Expand Down Expand Up @@ -1352,6 +1391,7 @@ int InitPlatform(void)
// Close platform
void ClosePlatform(void)
{
if (platform.window == NULL) return;
RGFW_window_close(platform.window);
}

Expand Down
Loading