Display.setParent() - Canvas looses Focus - nSwapBuffers(ByteBuffer) blocks

Started by Nitram, August 11, 2009, 13:21:39

Previous topic - Next topic

Nitram

Hello,

so I have a small problem I yet failed to resolve. I'm a developer for a game client that uses LWJGL for the graphic, input and sound. Formerly we used the display native window to display the stuff we need and it work. But in order to get some improvements we switched to a JFrame along with a Canvas that is set as Parent of the display. The JFrame is simply set so the Canvas fits exactly in.

Now the problem that occures using Windows. When pressing ALT or F10, Windows usually sets the focus to the menubar. The JFrame does not have a menubar but the focus on the Canvas is lost how ever. Its clearly visible since the Canvas graps the mouse and that grapping is lost and the mouse cursor of Windows reappears. Also the main loop is blocked when this happend because
org.lwjgl.opengl.WindowsContextImplementation.nSwapBuffers(ByteBuffer peer_info_handle)
does not return before the focus on the Canvas is regained. To gain the focus again you just need to press ALT or F10 again or click into the Canvas. But since the game uses both keys in the regular binding, its a pretty bad situation.

I tried multiple things that came into my mind using the possibilities of java.awt and javax.swing, such as playing around with the focus values of the JFrame and the Canvas. Also I tried using a FocusListener, only to find out that the lost of the focus is not reported to the listener. Also I tried using a JDialog instead of a JFrame and I tried to set up a menubar that returns the focus instandly or rejects it. Everything failed.

But there has to be some way since the Display creates a window that works correctly in case there is not parent set.

Anyone has a idea on that?
Nitram

broumbroum

The longer the post maybe the shorter the answer is. LOL
I'm sure if you try AWTGLCanvas substituting Display.setParent() that you may find a solution for your focus issue. But you should take care that the AWTGLCanvas must update with Swing, that's your render loop must be a Swing Thread. Use SwingUtilities or a javax.swing.Timer to update.

Nitram

Thats a way but not possible in this case because I also need the possibility to switch to full screen mode that is only offered by display.

Nitram