Skip to content

[rcore][web] Mouse position is locked after calling HideCursor() in PLATFORM_WEB #4940

Open
@proc0

Description

@proc0

Issue description

I'm trying to show and hide the cursor for a pause menu and this works on desktop but when compiling for web if the cursor is hidden the mouse position does not update at all. (Side note: This example seems broken (pressing H does not hide cursor?) not sure if that's the same issue or not. I reproduced the issue here and it's the same as the example).

I expect the behavior of HideCursor and ShowCursor to be the same as Desktop (whether it locks the mouse or not).

Environment

Raylib 5.5, PLATFORM_WEB, compiled on Windows11, MinGW and Emscripten

Issue Screenshot

Image

Code Example

    if (IsKeyPressed(KEY_H)){
        if (isCursorHidden == 0)
        {
            HideCursor();
            isCursorHidden = 1;
        }
        else
        {
            ShowCursor();
            isCursorHidden = 0;
        }
    }
    
    ballPosition = GetMousePosition(); // gets stuck in same X,Y if HideCursor was called

Workaround and comments

I think this is caused because CORE.Input.Mouse.cursorHidden is being used for both hiding the cursor and locking the cursor. I would expect that the DisableCursor would lock the mouse, and for HideCursor to not lock the mouse. But in rcore_web there is a check for cursorHidden before updating the mouse position.

Image

I think there could be two flags here, maybe? cursorHidden and cursorLocked. and cursorHidden only gets set and unset from Hide/ShowCursor. I could be missing something as well and maybe this is intended behavior for Web (since hiding cursor automatically locks it?).

The workaround I found is to use GetMouseDelta, but this only works if I use DisableCursor and EnableCursor instead of Hide and ShowCursor... which then makes me ask the question what exactly is the difference between Hiding and Disabling the Cursor? And also between Hiding and Locking (as used by Emscripten and GLFW).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions