Bug: Missing mouse position in SDL_MOUSEBUTTONDOWN event in x11 driver


I’m using SDL 2.0.10 with the x11 driver on linux, and I noticed a bug. After creating a new window if you click before the mouse has ever moved the SDL_MOUSEBUTTONDOWN event will be missing x,y mouse position (both zero incorrectly). If you move the mouse before clicking then xy position in the click event will be correct.

SDL_GetMouseState called before the mouse moves is also wrong (reports xy zero as well). However SDL_GetGlobalMouseState is correct and subtracting SDL_GetWindowPosition from that gives the correct position, giving the following workaround:

int x, y, wx, wy;
SDL_GetGlobalMouseState(&x, &y);
SDL_GetWindowPosition(SDL_GL_GetCurrentWindow(), &wx, &wy);
int mouse_x = x - wx;
int mouse_y = y - wy;

After debugging this a lot I found that ImGui actually has uses a similar workaround: https://github.com/ocornut/imgui/blob/master/examples/imgui_impl_sdl.cpp#L259-L266

I think the bug is in the X11 driver.