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 3487

Summary: SDL_GetMouseState always returns (0,0) before moving the mouse the first time
Product: SDL Reporter: Andre <andreapfel>
Component: eventsAssignee: Sam Lantinga <slouken>
Status: ASSIGNED --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: andreapfel, luancthums
Version: 2.0.8   
Hardware: x86_64   
OS: Linux   
Attachments: MWE

Description Andre 2016-11-11 14:28:47 UTC
Created attachment 2611 [details]
MWE

I have a problem with SDL_GetMouseState: I want to get the initial mouse coordinate before the user moves the mouse the first time, but the function only returns (0,0) regardless of the actual mouse position.

I have attached a MWE that shows my problem. The first line that is printed is always "init: 0, 0". I expected it to give the actual coordinates.

This behavior can be reproduced under Linux 2.28.2 with GNOME shell 3.22.1 and the X window system. It works fine under Windows 7.



How to reproduce:

Run my attached program. Then remember the position of the window. Close the program. Then move the mouse into the position where the window was created last time. Start the program again.

Now you can see that the initial call of SDL_GetMouseState always returns (0,0) although the mouse is somewhere else inside the window.
Comment 1 Thums 2018-04-10 04:38:40 UTC
I have the same problem, SDL_GetMouseState always returns (0,0) until the mouse is moved for the first time since the program was opened.

Tested on Arch Linux, kernel 4.15.14-1 under i3wm.

Calling SDL_PumpEvents before obtaining the mouse state changes nothing.