Open
Description
Follow up from #12667.
This still seems to be broken for me after merging both #12669 and #12575. The relative mouse position is reported incorrectly -- see this GIF:
https://i.imgur.com/sqBYbwe.mp4
This is my logic:
////////////////////////////////////////////////////////////
Vector2i getPosition()
{
Vector2f result;
SDL_GetGlobalMouseState(&result.x, &result.y);
return result.toVector2i();
}
////////////////////////////////////////////////////////////
Vector2i getPosition(const WindowBase& relativeTo)
{
return getPosition() - relativeTo.getPosition();
// ^~~~~~~~~~~~~~~~~~~~~~~~
// uses SDL_GetWindowPosition() internally
}
@Temdog007: my guess here is that SDL_GetWindowPosition
is not returning the correct position of the canvas relative to the parent web page shell, but I might be incorrect.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]`SDL_GetGlobalMouseState` and `SDL_GetWindowPosition` still present on Emscripten[/-][+]`SDL_GetGlobalMouseState` and `SDL_GetWindowPosition` inconsistency still present on Emscripten[/+]Temdog007 commentedon Apr 7, 2025
A call to
SDL_SyncWindow
is necessary to ensure that the window position is sync'd with position in the DOM.Calling
SDL_SetHint(SDL_HINT_VIDEO_SYNC_WINDOW_OPERATIONS, "1");
before callingSDL_Init
will ensure that the window position is always sync'd after the position or size of the window changes.The functions in SDL where this occurs:
SDL_SetWindowFullscreenMode
SDL_SetWindowPosition
SDL_SetWindowSize
SDL_MaximizeWindow
SDL_MinimizeWindow
SDL_RestoreWindow
SDL_SetWindowFullscreen
If the canvas is moved outside of SDL, the window position won't be sync'd without explicitly calling
SDL_SyncWindow.
vittorioromeo commentedon Apr 8, 2025
Even with
SDL_SetHint(SDL_HINT_VIDEO_SYNC_WINDOW_OPERATIONS, "1")
I am getting inconsistent results. When I open the browser at first, the relative position is screwed up as usual. If I resize the window once, the position seems to fix itself, but stops being correct again as soon as I resize the browser window.Is there a chance I am doing something wrong? How can I debug this and figure out what is the culprit?
vittorioromeo commentedon Apr 8, 2025
So, calling
SDL_SetHint
beforeSDL_Init
doesn't work, but callingSDL_SyncWindow
every frame does. I will experiment further.