Discussion:
[SDL] How to get the initial mouse coords before moving the mouse?
Andre
2016-11-09 23:37:16 UTC
Permalink
Hi everybody,

I have a problem with `SDL_GetMouseState`: I want to get the inital
mouse coords before the user moves the mouse, but the function only
returns 0 for the x and y coord.

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 coords.

I tried this example under Linux only.

I really appreciate any help you can provide.
Faluk
2016-11-11 11:30:52 UTC
Permalink
Hi Andre,

Do you have the event system initialized?

PS. Can't see anything attached.
Andre
2016-11-11 11:48:03 UTC
Permalink
Post by Faluk
Do you have the event system initialized?
Which function do you mean exactly? I called SDL_PumpEvents before
SDL_GetMouseState.
Post by Faluk
PS. Can't see anything attached.
Mailman separated the attachment from my email. See
http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20161110/13c00070/attachment.c
for my attachment.
Faluk
2016-11-11 12:57:24 UTC
Permalink
Hi Andre,

The problem is that if the mouse is outside the window there is no data to get. If the SDL_GetMouseState is called while the window is inside the window you will get data. Try creating a bigger where the mouse is inside the window.

:)
Andre
2016-11-11 13:09:28 UTC
Permalink
Post by Faluk
The problem is that if the mouse is outside the window there is no data
to get. If the SDL_GetMouseState is called while the window is inside
the window you will get data. Try creating a bigger where the mouse is
inside the window.
I'm not talking about the case where the mouse is outside the program.

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 inside the window.
Faluk
2016-11-11 13:57:22 UTC
Permalink
Post by Andre
Post by Faluk
The problem is that if the mouse is outside the window there is no data
to get. If the SDL_GetMouseState is called while the window is inside
the window you will get data. Try creating a bigger where the mouse is
inside the window.
I'm not talking about the case where the mouse is outside the program.
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 inside the window.
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Maybe is the library you are using. Your same code is is working perfectly for me:


Code:
init: 92, 120
move: 92, 120
move: 88, 114
move: 81, 103
move: 71, 89
move: 43, 52
move: 17, 23
move: 0, 0
Andre
2016-11-11 14:05:33 UTC
Permalink
Ok, then it's a bug.

Can you please tell me what operating system + DE + window manager you
are using, so I can provide this information in the bug report?
Faluk
2016-11-11 14:12:34 UTC
Permalink
I currently tested your code under windows 7. I will try it under linux during the weekend.
Andre
2016-11-11 14:32:38 UTC
Permalink
Thank you very much for your help so far.

I filed a bug under https://bugzilla.libsdl.org/show_bug.cgi?id=3487
Loading...