Hello Guest

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

  • 11 Replies
  • 23603 Views
*

Offline Notch

  • *
  • 38
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.

*

Offline princec

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

Cas :)

*

Offline Matzon

  • *****
  • 2242
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?

*

Offline Notch

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

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

*

Offline kappa

  • *****
  • 1319
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?

*

Offline Notch

  • *
  • 38
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.

*

Offline kappa

  • *****
  • 1319
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.

*

Offline kappa

  • *****
  • 1319
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

*

Offline Notch

  • *
  • 38
I don't run linux myself, so I can't verify it.. but here's some pseudocode that shows what my logic looks like:

Code: [Select]
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)

*

Offline princec

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

Cas :)

*

Offline kappa

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

Just the windows input/grab problem left now.

*

Offline spasi

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