Skip to content

[rcore] GetMousePosition() does not show the correct position if the window spans multiple monitors, in Wayland #4931

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

Open
4 tasks done
lsck0 opened this issue May 9, 2025 · 2 comments
Labels
platform: Linux Linux platform

Comments

@lsck0
Copy link

lsck0 commented May 9, 2025

Please, before submitting a new issue verify and check:

  • 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

When the window is on multiple monitors, the X component of GetMousePosition() is not updated for the region visible on the monitor that does not contain the top left corner. The Y component is updated as expected.

Environment

OS: Arch Linux x86_64
Kernel: 6.14.4-arch1-1
WM: Hyprland
CPU: AMD Ryzen 5 5600X (12) @ 4.654GHz
GPU: AMD ATI Radeon RX 7700 XT / 7800 XT
INFO: GL: Supported extensions count: 239
INFO: GL: OpenGL device information:
INFO:     > Vendor:   AMD
INFO:     > Renderer: AMD Radeon RX 7800 XT (radeonsi, navi32, LLVM 19.1.7, DRM 3.61, 6.14.4-arch1-1)
INFO:     > Version:  4.6 (Core Profile) Mesa 25.0.4-arch1.1
INFO:     > GLSL:     4.60

Issue Screenshot

2025-05-09.22-02-20.mp4

Code Example

// gcc main.c -o main -lraylib
#include <raylib.h>

int main(void) {
  InitWindow(400, 400, "GetMousePosition() Bug Example");
  SetTargetFPS(60);

  while (!WindowShouldClose()) {
    if (IsKeyPressed(KEY_Q)) break;

    Vector2 mouse_position = GetMousePosition();
    TraceLog(LOG_INFO, "Mouse Position: (%f, %f)", mouse_position.x, mouse_position.y);

    BeginDrawing();
    ClearBackground(RAYWHITE);
    DrawCircle(mouse_position.x, mouse_position.y, 10, RED);
    EndDrawing();
  }

  CloseWindow();
  return 0;
}
@raysan5 raysan5 added the platform: Linux Linux platform label May 11, 2025
@raysan5 raysan5 changed the title [rcore] Wayland: GetMousePosition() does not show the correct position if the window spans multiple monitors [rcore] GetMousePosition() does not show the correct position if the window spans multiple monitors, in Wayland May 11, 2025
@raysan5
Copy link
Owner

raysan5 commented May 11, 2025

@lsck0 this seems to be a very specific use case and probably related to windowing system...

@lsck0
Copy link
Author

lsck0 commented May 11, 2025

I did some more testing on this. I tried 3 different window managers, and all showed different but incorrect results in this case. However, when building raylib with -DUSE_EXTERNAL_GLFW=ON, the raylib window is not displayed through Xwayland, but as a native Wayland window, which completely fixed this issue (and disabled things like SetWindowPosition). Other Xwayland windows show similar problems in this edge case. So not a raylib bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: Linux Linux platform
Projects
None yet
Development

No branches or pull requests

2 participants