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

Changes SetWindowMonitor() to no longer force fullscreen #3209

Merged
merged 2 commits into from Jul 28, 2023
Merged

Changes SetWindowMonitor() to no longer force fullscreen #3209

merged 2 commits into from Jul 28, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jul 28, 2023

Since invoking glfwSetWindowMonitor() (L1676) forces fullscreen, changes SetWindowMonitor() to instead move the window to the defined monitor.

To move the window it checks if the screen size is larger than the monitor workarea (R1684-R1693). If it is larger, then anchors it on the top left corner (R1693), otherwise, center it (R1696-R1698). This is done because if the window is larger than the workarea, centering could make the window bars/handles unreachable for the user.

Before this proposed change (while using the previous SetWindowMonitor() implementation L1675-L1676), I wasn't able to change the monitor while already on fullscreen. But, just be safe and prevent SetWindowMonitor() from being executed while already on fullscreen, added a check for it before attempting to move the window anyway (R1673, R1694). (Sorry, I retested this today and it's working. I probably messed something locally yesterday while testing multiple monitor layout configurations. I amended the commit to allow moving the fullscreen window again: R1673-R1679)

This proposed change leaves up to the user to call ToggleFullscreen() or SetWindowState(FLAG_FULLSCREEN_MODE) when required.

Environment

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

Code Example

Minimal reproduction code to test the change:

#include "raylib.h"

void changeWindowSize(int monitor) {
    int monitorCount = GetMonitorCount();
    if ((monitor >= 0) && (monitor < monitorCount)) {
        SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
    } else {
        TraceLog(LOG_WARNING, "Monitor %i not found", monitor);
    }
}

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

        if (IsKeyPressed(KEY_F1)) { SetWindowMonitor(0); }
        if (IsKeyPressed(KEY_F2)) { SetWindowMonitor(1); }
        if (IsKeyPressed(KEY_F3)) { SetWindowMonitor(2); }
        if (IsKeyPressed(KEY_F4)) { SetWindowMonitor(3); }

        if (IsKeyPressed(KEY_F5)) { changeWindowSize(0); }
        if (IsKeyPressed(KEY_F6)) { changeWindowSize(1); }
        if (IsKeyPressed(KEY_F7)) { changeWindowSize(2); }
        if (IsKeyPressed(KEY_F8)) { changeWindowSize(3); }

        if (IsKeyPressed(KEY_F9))  { SetWindowSize(800, 450); }
        if (IsKeyPressed(KEY_F10)) { TraceLog(LOG_INFO, "Current monitor: %i", GetCurrentMonitor()); }
        if (IsKeyPressed(KEY_F11)) { ToggleFullscreen(); }

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("Move window to monitor 0 [F1], 1 [F2], 2 [F3], 3 [F4]", 20, 20, 20, BLACK);
        DrawText("Make window the size of monitor 0 [F5], 1 [F6], 2 [F7], 3 [F8], 800x450 [F9]", 20, 60, 20, BLACK);
        DrawText("Print current monitor on log [F10], Toggle fullscreen [F11]", 20, 100, 20, BLACK);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}

Edit 1: added line marks.
Edit 2: fixes #3198.
Edit 3: amended commit to allow moving the fullscreen window again.

@raysan5 raysan5 merged commit 962030e into raysan5:master Jul 28, 2023
12 checks passed
@raysan5
Copy link
Owner

raysan5 commented Jul 28, 2023

@ubkp thank you very much for the improvement! 👍🙂

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] TOPMOST flag does not work with multiple monitors
1 participant