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

Adds BORDERLESS_WINDOWED_MODE for PLATFORM_DESKTOP #3216

Merged
merged 1 commit into from Aug 2, 2023
Merged

Adds BORDERLESS_WINDOWED_MODE for PLATFORM_DESKTOP #3216

merged 1 commit into from Aug 2, 2023

Conversation

ghost
Copy link

@ghost ghost commented Aug 1, 2023

Adds the FLAG_BORDERLESS_WINDOWED_MODE flag to the ConfigFlags enum (R529).

Adds CORE.Window.previousPosition and CORE.Window.previousScreen to the CoreData.Window struct (R415-R416).

Adds ToggleBorderlessWindowed() (R951, R1329-R1403) to handle the FLAG_BORDERLESS_WINDOWED_MODE on PLATFORM_DESKTOP that will be called from SetWindowState() (R1454-R1459), ClearWindowState() (R1571-R1576) and/or directly (R951). Didn't implement it inside SetWindowState() and ClearWindowState() because this flag required some checks and calculations, so I thought it would group better in a separated function.

The ToggleBorderlessWindowed() initially checks if it's in fullscreen mode (R1335). If it is:

  1. Backups CORE.Window.position (that was saved by ToggleFullscreen() L1216) on CORE.Window.previousPosition (R1337) before leaving fullscreen mode. Didn't reuse CORE.Window.position to not interfere with the ToggleFullscreen() independent operation;
  2. Leaves fullscreen mode (R1338);
  3. Sets a wasOnFullscreen var that will be required later (R1334, R1339).

After that, ToggleBorderlessWindowed() checks:

  1. For a valid monitor (that will be required for glfwGetMonitorPos) (R1342-R1345);
  2. For a video mode (that will be required for glfwGetVideoMode to get the monitor width and height) (R1347-R1348);
  3. For the FLAG_BORDERLESS_WINDOWED_MODE value (R1350, R1380).

If the FLAG_BORDERLESS_WINDOWED_MODE is not set:

  1. Backups the screen position to CORE.Window.previousPosition (if this didn't already happen it it was on fullscreen mode) (R1354);
  2. Backups the screen size to CORE.Window.previousScreen (R1355);
  3. Sets the FLAG_WINDOW_UNDECORATED mode and flag (R1358-R1359);
  4. Sets the FLAG_WINDOW_TOPMOST mode and flag (R1360-R1361);
  5. Gets the monitor position and size (R1364-R1369);
  6. Sets the screen position to the monitor position (R1372);
  7. Sets the screen size to the monitor size (R1373);
  8. Refocus the window (R1376);
  9. Sets the FLAG_BORDERLESS_WINDOWED_MODE flag on the CORE.Window.flags (R1378).

If the FLAG_BORDERLESS_WINDOWED_MODE is set:

  1. Removes the FLAG_WINDOW_TOPMOST mode and flag (R1383-R1384);
  2. Removes the FLAG_WINDOW_UNDECORATED mode and flag (R1385-R1386);
  3. Sets the screen size to the CORE.Window.previousScreen (R1390). This must be done before setting the screen position, otherwise the screen will be positioned incorrectly;
  4. Sets the screen position to the CORE.Window.previousPosition (R1391);
  5. Refocus the window (R1394);
  6. Removes the FLAG_BORDERLESS_WINDOWED_MODE flag from the CORE.Window.flags (R1396).

Also adds FLAG_BORDERLESS_WINDOWED_MODE to SetWindowState() (R1456-R1459) and ClearWindowState() (R1573-R1576). These must be handled before FLAG_FULLSCREEN_MODE because ToggleBorderlessWindowed() needs to get some fullscreen values if fullscreen is running.

Since no scaling is being applied and the monitor size (which already has some valid aspect ratio) is being used, this implementation doesn't make any aspect ratio calculations, using the monitor size (and aspect ratio) as is.

Environment

Tested this change successfully on PLATFORM_DESKTOP native Linux (Linux Mint 21.1 x86_64) with two monitors (1600x900 and 1280x1024 resolutions).

Code Example

Minimal reproduction code to test the change:

#include "raylib.h"

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

        if (IsKeyPressed(KEY_F1))  { ToggleBorderlessWindowed(); TraceLog(LOG_INFO, "F1 - ToggleBorderlessWindowed()"); }
        if (IsKeyPressed(KEY_F2))  { SetWindowState(FLAG_BORDERLESS_WINDOWED_MODE); TraceLog(LOG_INFO, "F2 - SetWindowState(FLAG_BORDERLESS_WINDOWED_MODE)"); }
        if (IsKeyPressed(KEY_F3))  { ClearWindowState(FLAG_BORDERLESS_WINDOWED_MODE); TraceLog(LOG_INFO, "F3 - ClearWindowState(FLAG_BORDERLESS_WINDOWED_MODE)"); }
        if (IsKeyPressed(KEY_F11)) { ToggleFullscreen(); TraceLog(LOG_INFO, "F11 - ToggleFullscreen()"); }

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Test", 20, 20, 20, BLACK);
        DrawRectangle(20, 60, 40, 40, RED);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Fixes #3207.

Edit 1: added line marks.
Edit 2: formating.

@raysan5 raysan5 merged commit 464e714 into raysan5:master Aug 2, 2023
12 checks passed
@raysan5
Copy link
Owner

raysan5 commented Aug 2, 2023

@ubkp This is an amazing addition! Thank you very much for all the work put on it and the detailed information!

src/rcore.c Show resolved Hide resolved
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.

[core] Support BORDERLESS_WINDOWED_MODE for non-exclusive fullscreen
1 participant