Skip to content

Handle global mouse state for Emscripten #12669

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

Merged
merged 2 commits into from
Apr 2, 2025

Conversation

Temdog007
Copy link
Contributor

Fixes #12667

@sezero sezero requested review from icculus and slouken March 29, 2025 21:41
@vittorioromeo
Copy link
Contributor

Thanks for giving it a shot! Unfortunately, this doesn't seem to solve the problem.

It appears to work at first, but either resizing the browser window or resizing the canvas by changing the window size via SDL_SetWindowSize seems to screw up everything again.

In contrast, with my crappy workaround, the position is always consistent even after resizing the browser or the window:

Vector2i getPosition(const WindowBase& relativeTo)
{
#ifdef SFML_SYSTEM_EMSCRIPTEN
    return getPosition(); 
#else
    return getPosition() - relativeTo.getPosition();
//                         ^~~~~~~~~~~~~~~~~~~~~~~~
//                  uses SDL_GetWindowPosition() internally
#endif
}

@vittorioromeo
Copy link
Contributor

Thanks for giving it a shot! Unfortunately, this doesn't seem to solve the problem.

It appears to work at first, but either resizing the browser window or resizing the canvas by changing the window size via SDL_SetWindowSize seems to screw up everything again.

In contrast, with my crappy workaround, the position is always consistent even after resizing the browser or the window:

Vector2i getPosition(const WindowBase& relativeTo)
{
#ifdef SFML_SYSTEM_EMSCRIPTEN
    return getPosition(); 
#else
    return getPosition() - relativeTo.getPosition();
//                         ^~~~~~~~~~~~~~~~~~~~~~~~
//                  uses SDL_GetWindowPosition() internally
#endif
}

Thinking about it a bit more, the issue might now be SDL_GetWindowPosition()...

@slouken slouken added this to the 3.4.0 milestone Mar 30, 2025
@Temdog007
Copy link
Contributor Author

These changes will be merged into #12575. So, closing this PR.

@Temdog007 Temdog007 closed this Mar 31, 2025
@slouken
Copy link
Collaborator

slouken commented Mar 31, 2025

Please keep them as a separate PR unless there's an actual code dependency between them.

@Temdog007
Copy link
Contributor Author

Please keep them as a separate PR unless there's an actual code dependency between them.

A test was added to #12575 for verifying multiple windows for Emscripten. This involves spawning multiple windows. To prevent putting them in the same position, I would spawn them at the global position of the mouse. Thus, that branch needed this change. Since this was marked for 3.4.0, I figured it would be fine to merge this branch into that one to have just one PR.

@Temdog007 Temdog007 reopened this Apr 2, 2025
@slouken slouken merged commit cc8ec6c into libsdl-org:main Apr 2, 2025
78 checks passed
@slouken
Copy link
Collaborator

slouken commented Apr 2, 2025

Merged, thanks!

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.

Inconsistency between SDL_GetGlobalMouseState position and SDL_GetWindowPosition on Emscripten
4 participants