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 - SDL_GetMouseState always returns (0,0) before moving the mouse the first time
Summary: SDL_GetMouseState always returns (0,0) before moving the mouse the first time
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: events (show other bugs)
Version: 2.0.8
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-11 14:28 UTC by Andre
Modified: 2018-04-10 04:39 UTC (History)
2 users (show)

See Also:


Attachments
MWE (788 bytes, text/x-c)
2016-11-11 14:28 UTC, Andre
Details

Note You need to log in before you can comment on or make changes to this bug.
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.