[FIXED] Mouse.setGrabbed still doesn't work right. I'd pay for it to work right.

Started by Notch, February 02, 2010, 14:00:40

Previous topic - Next topic

Notch

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.

princec

Hmm yes, I have just discovered too that the mouse and keyboard both completely stop working on the secondary monitor.

Cas :)

Matzon

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?

Notch

I haven't tried on mac, but I can do so tomorrow.

[edit:]
No, I can't. Oops. :-O

kappa

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?

Notch

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.

kappa

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.

kappa

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

Notch

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)

princec

Any ideas about the Windows problem with 2nd monitors? (No mouse / keyboard input at all when window is dragged to other monitor)

Cas :)

kappa

@notch the linux input problems should now be fixed in lwjgl nightly build >#393.

Just the windows input/grab problem left now.

spasi

Mouse grabbing on secondary monitor has been fixed on nightly. You owe me a beer Markus. ;D