Skip to content
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

[rcore] [SDL2] Fix maximizing, minimizing and restoring windows #4607

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

asdqwe
Copy link
Contributor

@asdqwe asdqwe commented Dec 16, 2024

Fixes RestoreWindow() (ref) for PLATFORM_DESKTOP_SDL that was using the incorrect call.

Fixes manually minimizing, maximizing and restoring the window not setting the correct FLAG_WINDOW_MAXIMIZED and FLAG_WINDOW_MINIMIZED respectively on PLATFORM_DESKTOP_SDL, and IsWindowMinimized() (ref) and IsWindowMaximized() (ref) that were INOP on PLATFORM_DESKTOP_SDL because the platform was missing event handling for SDL_WINDOWEVENT_MINIMIZED, SDL_WINDOWEVENT_MAXIMIZED and SDL_WINDOWEVENT_RESTORED (ref, ref). Manual detection to check if the window was maximized was necessary due to SDL2 restore being unreliable on some platforms (ref).

This PR was tested with SDL2.30.10 on Linux Mind 22.0. SDL3 wasn't tested but left placeholders for it and probably should work if SDL_WINDOW_MAXIMIZED was fixed there.

The PR can be tested with:
#include "raylib.h"
int main(void) {

    SetWindowState(FLAG_WINDOW_RESIZABLE);

    InitWindow(800, 450, "test");
    SetTargetFPS(60);

    while (!WindowShouldClose()) {

        if (IsKeyPressed(KEY_ONE)) MinimizeWindow();
        if (IsKeyPressed(KEY_TWO)) MaximizeWindow();
        if (IsKeyPressed(KEY_THREE)) RestoreWindow();
        TraceLog(LOG_INFO, "Minimized %i.  Maximized %i.", IsWindowMinimized(), IsWindowMaximized());

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText( "[1] Minimize\n[2] Maximize\n[3] Restore", 20, 20, 20, BLACK);
        EndDrawing();
     }
    CloseWindow();
    return 0;
}

@raysan5 raysan5 merged commit bdfbd6e into raysan5:master Dec 16, 2024
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Dec 16, 2024

@asdqwe thanks for the improvements!

@asdqwe asdqwe deleted the fix-sdl-flags branch December 16, 2024 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants