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 1634 - Can't detect if mouse is inside the window on Windows
Summary: Can't detect if mouse is inside the window on Windows
Status: RESOLVED WORKSFORME
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: HG 2.0
Hardware: x86 Windows (All)
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-04 23:13 UTC by Sik
Modified: 2013-07-11 01:00 UTC (History)
0 users

See Also:


Attachments
Modified testgl2.c (9.62 KB, text/plain)
2013-07-11 01:00 UTC, Ryan C. Gordon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sik 2012-11-04 23:13:06 UTC
When I was using a pre-built Windows DLL Sam Lantinga gave me some days ago for an expo, I noticed some issues with it. One of them is that my game seemed to be unable to detect whether the mouse was inside the window or not, which it needs to know to decide whether to render or not the cursor sprite. This issue doesn't happen in Ubuntu, only Windows.

The game does this:

   // Check if the cursor is inside our window
   // There's only one window so we don't need to check if it's exactly our
   // window (SDL won't know about stuff from other programs), just if it's
   // NULL or not
   SDL_Window *window = SDL_GetMouseFocus();
   input.cursor.inside = window != NULL ? 1 : 0;

Is SDL_GetMouseFocus meant to work like this?
Comment 1 Ryan C. Gordon 2013-07-11 01:00:29 UTC
Created attachment 1217 [details]
Modified testgl2.c


This is working for me here on Windows. We might have fixed it at some point.

I've attached a modified testgl2.c to demonstrate a working example. Just copy it over the one in the test directory and rebuild. It'll OutputDebugString() a 1 when the app gets mouse focus (by the cursor entering the window) and a 0 when it loses it (by the cursor leaving the window).

Note that this only works if you pump the SDL event loop. If SDL hasn't gotten the event from Windows yet, it thinks the mouse focus hasn't changed.

--ryan.