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 1175 - Captured mouse and WM_MOVE messages
Summary: Captured mouse and WM_MOVE messages
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: HG 2.0
Hardware: x86 Windows (All)
: P2 normal
Assignee: (disabled) Jørgen Tjernø
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-22 08:19 UTC by Alex Denisov
Modified: 2013-06-05 15:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Denisov 2011-03-22 08:19:42 UTC
In Windows OS, the file SDL_windowsevents.c converts WM_MOUSEMOVE event incorrectly:

case WM_MOUSEMOVE:

...

SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));

The issue is manifested in windowed mode, when the main window has captured the mouse using SetCapture() call from windows API. In this case, when the mouse is on the left or above the main window, WM_MOUSEMOVE is sending negative 16bit coordinates and LOWORD incorrectly typecasts it to an unsigned word. Typecasting LOWORD(lParam) to (Sint16)LOWORD(lParam) resolves the problem. 

Of course, for this to work properly, further modifications are required in SDL_mouse.c. I had to remove the constraints on mouse cursor assignment:

if (mouse->x > x_max) { mouse->x = x_max; }, etc...

If would be nice if you could add a flag into the SDL_mouse structure to disable this check.

I know that in general, cursor capturing is not supported, but it would be beneficial for building GUIs based on SDL. At its present stage, it is possible to work around by using direct windows API calls, but some built-in support would be good.
Comment 1 Sam Lantinga 2013-05-21 02:32:27 UTC
Hey Jorgen, can you take a quick look at this for SDL 2.0 release?

Thanks!
Comment 2 (disabled) Jørgen Tjernø 2013-06-05 15:00:57 UTC
Alex, if you look at SDL_GetMouse()->last_x + event.motion.xrel and SDL_GetMouse()->last_y + event.motion.yrel, you should be able to get the coordinate outside the window even with SetCapture.

I'm updating the code so that it will properly cast the lParam, but I'm not adding any functionality (right now) to support mouse motion events with absolute values outside of the window.

Fixed in http://hg.libsdl.org/SDL/rev/37814e7eeff3

Let me know if this works for you. :)