LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: Notch on February 02, 2010, 14:00:40

Title: [FIXED] Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: Notch on February 02, 2010, 14:00:40
I frequently grab/ungrab the mouse in my game. It works great under the right circumstances, but it has a few major disadvantages.

For example, it doesn't work at all if the game is on a secondary monitor. The game just locks up until I release the mouse.
On linux, it sometimes causes the game to not receive any more keyboard events, ever. The actual mouse grabbing problem seems to have been fixed in 2.2.2, though.
Since the mouse is released on a keyboard event, not getting keyboard focus is a bit of a problem.

I switched back to using Robot and MousePointerInfo, but that doesn't play well since it's multithreaded and unpredictable (it sometimes leaks coordinates because it's not synchronized), and it's really slow on some systems.

I'd pay to get this fixed.
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: princec on February 02, 2010, 16:50:43
Hmm yes, I have just discovered too that the mouse and keyboard both completely stop working on the secondary monitor.

Cas :)
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: Matzon on February 02, 2010, 16:57:32
Quote from: princec on February 02, 2010, 16:50:43
Hmm yes, I have just discovered too that the mouse and keyboard both completely stop working on the secondary monitor.

Cas :)

so this is a windows and linux issue - what about mac?
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: Notch on February 02, 2010, 17:03:05
I haven't tried on mac, but I can do so tomorrow.

[edit:]
No, I can't. Oops. :-O
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: kappa on February 02, 2010, 19:53:07
From what i can tell this seems like two separate bugs rather then one, since internally they are done pretty differently. (talking about linux and windows only atm)

@Notch can you just clarify a bit:

1) Mouse grab total fails on windows when using second screen.
2) When using linux + second screen it works fine, just that sometimes you are unable to get keyboard focus back.

can i assume that is correct?
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: Notch on February 02, 2010, 19:56:51
Quote from: javalwjgl on February 02, 2010, 19:53:07
From what i can tell this seems like two separate bugs rather then one, since internally they are done pretty differently. (talking about linux and windows only atm)

@Notch can you just clarify a bit:

1) Mouse grab total fails on windows when using second screen.
2) When using linux + second screen it works fine, just that sometimes you are unable to get keyboard focus back.

can i assume that is correct?

1) It grabs the mouse, but nothing gets rendered until the mouse gets released. If the mouse is ungrabbed, the game runs fine on the secondary monitor.
2) I don't know if secondary monitors works on linux. I thought it didn't, but I don't know for sure. When it loses focus by "weird" ways such as task switching while the mouse is grabbed or, in this case, opening an AWT dialog window, it seems to fail to ever get KB focus back.
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: kappa on February 02, 2010, 20:06:56
Quote from: Notch on February 02, 2010, 19:56:51
1) It grabs the mouse, but nothing gets rendered until the mouse gets released. If the mouse is ungrabbed, the game runs fine on the secondary monitor.
2) I don't know if secondary monitors works on linux. I thought it didn't, but I don't know for sure. When it loses focus by "weird" ways such as task switching while the mouse is grabbed or, in this case, opening an AWT dialog window, it seems to fail to ever get KB focus back.

Ah excellent and most useful information. Unfortunately can't help you with the second screen monitor problem (since don't have two screens) but i was aware of the linux mouse issue, just couldn't reproduce it, seemed to just happen randomly. I'll try runs some tests (maybe on the weekend but hopefully will get time before that) and see if i can reproduce it using the grabbing thing, hopefully can then try find a fix and patch it.
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: kappa on February 06, 2010, 18:16:56
Quote from: Notch on February 02, 2010, 14:00:40
On linux, it sometimes causes the game to not receive any more keyboard events, ever. ...
Since the mouse is released on a keyboard event, not getting keyboard focus is a bit of a problem.

@Notch I investigated this today, think I have a rough idea what it might be but can't be sure, problem is I can't reproduce the bug, been trying to do various things to get the bug to show itself but only got it to trigger once (no idea how it happend). If I had a working version of the bug I could then add debug info to LWJGL source and fix it, would it be possible for you to create a small test case which reproduces this bug?

thx
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: Notch on February 06, 2010, 21:14:48
I don't run linux myself, so I can't verify it.. but here's some pseudocode that shows what my logic looks like:

boolean grabbed;
Mouse.setGrabbed(grabbed = true);

while (true) {
    if (Keyboard.isDown(Keyboard.KEY_ESCAPE) && grabbed) Mouse.setGrabbed(grabbed = false);
    if (!Display.isActive() && grabbed) Mouse.setGrabbed(grabbed = false);
    if (isWindowClicked() && !grabbed) Mouse.setGrabbed(grabbed = true);
    Display.update();
}


From what I can piece together (and this might be incorrect), it works when pressing escape, but when you task switch directly so it loses focus, it doesn't work. (ie the Keyboard class stops working, like it doesn't have keyboard focus)
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: princec on February 08, 2010, 12:28:59
Any ideas about the Windows problem with 2nd monitors? (No mouse / keyboard input at all when window is dragged to other monitor)

Cas :)
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: kappa on February 14, 2010, 17:11:08
@notch the linux input problems should now be fixed in lwjgl nightly build >#393.

Just the windows input/grab problem left now.
Title: Re: Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.
Post by: spasi on April 01, 2010, 00:14:58
Mouse grabbing on secondary monitor has been fixed on nightly. You owe me a beer Markus. ;D