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

Summary: Can't detect if mouse is inside the window on Windows
Product: SDL Reporter: Sik <sik.the.hedgehog>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED WORKSFORME QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Windows (All)   
Attachments: Modified testgl2.c

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.