Hello Guest

[FIXED] setGrabbed(false) behavior

  • 12 Replies
  • 26714 Views
[FIXED] setGrabbed(false) behavior
« on: March 09, 2010, 02:13:07 »

Hey folks.  On different platforms, it appears that Mouse.setGrabbed does not work the same way...  On linux/osx, if I grab and then "ungrab" the mouse, the cursor does not change position, however if I do the same on windows, the cursor jumps to the middle of the screen.  Is there a way to get the windows version to behave in the same way (aside from using some platform based trick like Robot, etc.)  Is this something that is just not workable on windows and thus the platform difference?

*

Offline Matzon

  • *****
  • 2242
Re: setGrabbed(false) behavior
« Reply #1 on: March 09, 2010, 08:25:23 »
a quick glance through the code seems to reveal that there is definately centering going on, on windows - but also some cursor positioning on linux (didn't check mac).
technically, I think that ungrabbing the mouse should position the mouse at some defined location - but of course all platforms should do it the same place.
I dont have a fix for this right now, since I can't test all platforms.

Re: setGrabbed(false) behavior
« Reply #2 on: March 09, 2010, 09:23:47 »
I've run into this issue. After ungrabbing the mouse I want to position the cursor at the position the cursor was grabbed at. You can get this behavior through saving the cursor position at grab, and reset it at not_grabbed. But as you have to set the cursor position after setting not_grabbed (due to the centering happening at not_grabbed), the cursor can sometime flicker a bit at center and then to the "correct" position.

Any solution to get rid of the flickering would be awesome.

Re: setGrabbed(false) behavior
« Reply #3 on: March 17, 2010, 08:25:10 »
Any update on this?

*

Offline kappa

  • *****
  • 1319
Re: setGrabbed(false) behavior
« Reply #4 on: March 17, 2010, 09:30:55 »
there was some discussion regarding this on the #lwjgl irc channel on Sunday. We sort of came to the conclusion that the default behaviour should simply be that the mouse is centered on all platforms when the mouse is ungrabbed (as it is on windows atm). Not sure if any progress was made on actually implementing it yet.

Re: setGrabbed(false) behavior
« Reply #5 on: March 17, 2010, 10:18:56 »
Thanks for the update!

Sorry to hear about the conclusion. I need to implement this in the application level then. Thanks :)

Edit:

My issue with grab was that I want the cursor to be where it was when it was grabbed when you ungrab. If it is centered on ungrab, I have to move it to the old cursor postion after that. I get a flicker at center at each ungrab. Just to clarify why I would need to implement this in the application level. :)
« Last Edit: March 17, 2010, 10:23:17 by thecookie »

*

Offline kappa

  • *****
  • 1319
Re: setGrabbed(false) behavior
« Reply #6 on: March 17, 2010, 19:56:05 »
Thanks for the update!

Sorry to hear about the conclusion. I need to implement this in the application level then. Thanks :)

Edit:

My issue with grab was that I want the cursor to be where it was when it was grabbed when you ungrab. If it is centered on ungrab, I have to move it to the old cursor postion after that. I get a flicker at center at each ungrab. Just to clarify why I would need to implement this in the application level. :)

Well the only reason we decided to go for centering mouse on ungrab method was because it seems like the easiest method to implement. The method you mention (restoring the mouse where it was grabbed from) while not difficult to implement, it has a bit more to it for example when grabbing mouse outside the LWJGL Display do we restore it to the same place outside the Display?

As its still not implemented yet the issue is still up for discussion, if you have some good points on why we should position the mouse where we grab from on release or why centering the mouse on release is not good feel free to point them out.

Whichever method the majority of the LWJGL community prefers will likely get implemented.
« Last Edit: March 17, 2010, 19:57:36 by javalwjgl »

Re: setGrabbed(false) behavior
« Reply #7 on: March 17, 2010, 20:13:04 »
Can't it be settable some how? The behavior you would like. At least between centering and keep the cursor at same spot.

Is someone using grabbing outside of the display?

*

Offline kappa

  • *****
  • 1319
Re: setGrabbed(false) behavior
« Reply #8 on: March 17, 2010, 20:15:09 »
Is someone using grabbing outside of the display?

yes anyone who uses lwjgl in windowed mode and has keyboard input to grab the mouse.

Re: setGrabbed(false) behavior
« Reply #9 on: March 18, 2010, 09:36:15 »
I see. I would say that resetting the cursor to the grab position for that would work too, wouldn't it?

I have the window in focus, cursor outside, press space to go into grabbed mode, move around the camera a bit. Release space, and the cursor is back at where it was before. At least for me that's the most natural thing.

Re: setGrabbed(false) behavior
« Reply #10 on: March 18, 2010, 12:47:57 »
What about having the option on ungrabbed to set the location of the mouse to a specific point? This would, of course, need a new method, but it would handle both cases (center the mouse in normal circumstances, but have the option to ungrab at a specific location). This would allow for fancy mousework like grabbing the mouse to show a software cursor, then ungrabbing to show the hardware mouse at the same location (don't know why you would ever do that, though :P)
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D

*

Offline kappa

  • *****
  • 1319
Re: setGrabbed(false) behavior
« Reply #11 on: March 26, 2010, 20:47:12 »
this issue is now fixed and added to svn, it should be part of LWJGL 2.4. The mouse will now be at the same location as it was grabbed from when it is ungrabbed. Consistent on all platforms.

*

Offline kappa

  • *****
  • 1319
Re: setGrabbed(false) behavior
« Reply #12 on: March 27, 2010, 17:07:19 »
Further update on this, you can now set the location of where you want the mouse to be when its ungrabbed using Mouse.setCursorLocation(x,y) while mouse is grabbed. Default behaviour is still that the mouse will ungrab at the location it was grabbed. We now have the best of both worlds, users can have the mouse where ever he wants on ungrab without the need for any new api :)
« Last Edit: March 27, 2010, 17:12:15 by javalwjgl »