Mouse Scaling Bug With Multiple Full Screen Windows

I’ve found a bug in SDL2 that incorrectly scales the mouse coordinates when viewing two (or more) windows in full screen view. The problem seems to be that SDL_RendererEventWatch(void *userdata, SDL_Event *event) in SDL_render.c gets called for each renderer for all events. So, if you have multiple renderers each with different scale values then the mouse coordinates will be scaled for each renderer. In my case, this lead to the same scaling being applied twice.

I’ve come up with a simple fix that ensures a renderer only affects events associated with the window the renderer is associated with. Changing

Code:

} else if (event->type == SDL_MOUSEMOTION) {
    if (renderer->logical_w) {

to

Code:

} else if (event->type == SDL_MOUSEMOTION) {
    if (renderer->logical_w &&
        renderer->window == SDL_GetWindowFromID(event->motion.windowID)) {

Seems to fix the problem. I’m not sure this is the best solution, but it is working for me currently.