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

[core] GetCurrentMonitor() detection inconsistency issue for PLATFORM_DESKTOP #3213

Closed
4 tasks done
ghost opened this issue Jul 31, 2023 · 0 comments · Fixed by #3215
Closed
4 tasks done

[core] GetCurrentMonitor() detection inconsistency issue for PLATFORM_DESKTOP #3213

ghost opened this issue Jul 31, 2023 · 0 comments · Fixed by #3215

Comments

@ghost
Copy link

ghost commented Jul 31, 2023

  • I tested it on latest raylib version from master branch
  • I checked there is no similar issue already reported
  • I checked the documentation on the wiki
  • My code has no errors or misuse of raylib

Issue description

The current implementation of GetCurrentMonitor() (rcore.c#L1801) uses the workarea dimensions (rcore.c#L1842) for checking which is the current monitor while not on fullscreen mode.

The problem of using workarea for monitor detection is that it's (usually) a smaller area than the actual monitor dimension. While the workarea is a good solution for window placement, it becomes a problem for monitor detection, since if the window is larger than the workarea (e.g.: windowWidth = monitorWidth; windowHeight = monitorHeight; ) it will end up outside the workarea limits, causing it to be detected as inside the wrong monitor.

Proposed solution

This can be fixed by changing glfwGetMonitorWorkarea() by glfwGetMonitorPos() and glfwGetVideoMode() on GetCurrentMonitor().

I'll send a PR with the proposed fix shortly.

Environment

Platform: Desktop
Operating System: Linux Mint 21.1 (x86_64)
OpenGL version: 3.1 Mesa 22.0.5
GPU: Intel HD Graphics 3000

Code Example

Minimal reproduction code to test the issue:

#include "raylib.h"

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

        if (IsKeyPressed(KEY_F1)) {
            if (GetMonitorCount() > 1) {
                int monitor = 1;
                SetWindowState(FLAG_WINDOW_UNDECORATED);
                SetWindowMonitor(monitor);
                SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
                SetWindowPosition(GetMonitorPosition(monitor).x, GetMonitorPosition(monitor).y);
            }
        }

        BeginDrawing();
        ClearBackground(RAYWHITE);
        DrawText("This test requires at least 2 monitors.", 20, 20, 20, BLACK);
        DrawText("[F1] Move window to monitor 1 and resize it to monitor 1 size.", 20, 60, 20, BLACK);
        DrawText("Current monitor:", 20, 100, 20, BLACK);
        DrawText(TextFormat("%i", GetCurrentMonitor()), 200, 100, 20, RED);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}
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 a pull request may close this issue.

0 participants