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] Add ToggleBorderlessWindowed() implementation for PLATFORM_WEB #3622

Merged
merged 2 commits into from Dec 11, 2023
Merged

[rcore] Add ToggleBorderlessWindowed() implementation for PLATFORM_WEB #3622

merged 2 commits into from Dec 11, 2023

Conversation

ghost
Copy link

@ghost ghost commented Dec 10, 2023

Changes

  1. Adds implementation for ToggleBorderlessWindowed() for PLATFORM_WEB (R214-R240).
  2. Does that by first checking if it's in (any form of) browser fullscreen (R214-R215).
  3. This is done with EM_ASM_INT (R214) to ensure the correct browser state, regardless internal variables or implementations.
  4. If it is in fullscreen, leave fullscreen (R217) and also reset the CORE fullscreen flags (R219-R220).
  5. After that, checks if FLAG_BORDERLESS_WINDOWED_MODE is set (R223).
  6. If it isn't set, enters the fullscreen equivalent to Borderless Windowed (R230).
  7. This was done on a short timeout to reliably handle the browser mode change delay (R228-R235).
  8. It also (and also on a timeout R231-R234) sets the canvas CSS width to unset (R233), which handles the possibility of a width="value%" CSS property like on the default shell.html file.
  9. This way ToggleBorderlessWindowed() can work on both a minshell.html-style or shell.html-style shell file.
  10. Finally, sets the FLAG_BORDERLESS_WINDOWED_MODE (R238).
  11. If the FLAG_BORDERLESS_WINDOWED_MODE was set, then just unset it (R240), since we already left fullscreen previously (R217).

Code example

  • This change can be tested for PLATFORM_WEB (requires ASYNCIFY) with:
#include "raylib.h"

int main(void) {
    InitWindow(800, 450, "test");
    SetTargetFPS(60);
    while (!WindowShouldClose()) {

        if (IsKeyPressed(KEY_F)) ToggleBorderlessWindowed();

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("[F] ToggleBorderlessWindowed()", 20, 20, 20, BLACK);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Environment

  • Compiled on Linux (Ubuntu 22.04 64-bit) and tested on Firefox (115.3.1esr 64-bit) and Chromium (117.0.5938.149 64-bit) for both minshell.html and shell.html files.

Edits

  • 1: editting; added line marks.
  • 2: formatting.

@raysan5 raysan5 merged commit 39457ac into raysan5:master Dec 11, 2023
14 checks passed
@raysan5
Copy link
Owner

raysan5 commented Dec 11, 2023

@ubkp Really nice addition! Thank you very much!

@ghost ghost deleted the add/web-borderlessfullscreen branch December 11, 2023 12:35
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.

1 participant