We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2367 - Bad mouse motion coordinates with two windows where one has changed logical size
Summary: Bad mouse motion coordinates with two windows where one has changed logical size
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.1
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords: target-2.0.4
Depends on:
Blocks:
 
Reported: 2014-01-27 13:11 UTC by Andreas Ragnerstam
Modified: 2015-05-28 19:18 UTC (History)
0 users

See Also:


Attachments
Suggested fix (1.09 KB, patch)
2014-01-27 14:57 UTC, Andreas Ragnerstam
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Ragnerstam 2014-01-27 13:11:08 UTC
I have two windows where one has a renderer where the logical size has been changed with SDL_RenderSetLogicalSize. When I get SDL_MOUSEMOTION events belonging to the non-scaled window these will have been scaled with the factor of the scaled window, which is not expected.

Adding some printf debugging to SDL_RendererEventWatch of SDL_render.c, where (event->type == SDL_MOUSEMOTION), I found that for every mouse motion SDL_RendererEventWatch is called twice and the event->motion.x and event.motion.y are set twice for the event, once for each renderer where only the last one set will be saved to the event struct. This will work fine if both renderers have the same scale, but otherwise the motion coordinates will be scaled for the renderer belonging to another window than the mouse was moved in.

I guess one solution would be to check that window == renderer->window for SDL_MOUSEMOTION events, similar to what is done for when SDL_WINDOWEVENT events.

I get the same error on both X11 and Windows.
The same problem also exists for SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP events.
Comment 1 Andreas Ragnerstam 2014-01-27 13:56:09 UTC
One way to reproduce a similar error is to run a example from the test suite as follows:

./testrendercopyex --windows 2 --geometry 640x480 --logical 1280x960

Then move the mouse pointer to the lower right corner and press space. The coordinates shown will be the double that one would expect. This is because the scale (.5) is divided twice.
Comment 2 Andreas Ragnerstam 2014-01-27 14:57:54 UTC
Created attachment 1538 [details]
Suggested fix

Here is a patch that solves the problem for me.
Comment 3 Ryan C. Gordon 2015-02-19 05:22:20 UTC
Marking a large number of bugs with the "triage-2.0.4" keyword at once. Sorry if you got a lot of email from this. This is to help me sort through some bugs in regards to a 2.0.4 release. We may or may not fix this bug for 2.0.4, though!
Comment 4 Ryan C. Gordon 2015-04-07 04:57:55 UTC
(sorry if you get a lot of copies of this email, I'm marking several bugs at once)

Marking bugs for the (mostly) final 2.0.4 TODO list. This means we're hoping to resolve this bug before 2.0.4 ships if possible. In a perfect world, the open bug count with the target-2.0.4 keyword is zero when we ship.

(Note that closing a bug report as WONTFIX, INVALID or WORKSFORME might still happen.)

--ryan.
Comment 5 Sam Lantinga 2015-05-28 19:18:33 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/aea5a2032785