LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: BatKid on November 06, 2010, 00:09:50

Title: Linux Webstart App focus issue
Post by: BatKid on November 06, 2010, 00:09:50
Hi all,

My lwjgl app is running inside a canvas using Display.setParent(), with lots of swing components around it.  It runs great on windows and os x.  On linux, the program also runs fine when it is launched.  However, if you use "alt-tab" on linux to switch to another app, and come back to my app, the 3d canvas can no longer receive focus.

Anything immediate that you guys can think of?

If you want to run the app, it is at http://whalechat.com.

Thanks
Title: Re: Linux Webstart App focus issue
Post by: kappa on November 06, 2010, 00:34:03
canvas.setFocasable(true);

use above to re-enable the Display window to be focused.

seems like ALT+Tab in this case might not be alerting the awt window properly that focus is lost.
Title: Re: Linux Webstart App focus issue
Post by: BatKid on November 06, 2010, 04:12:04
Thanks!  I'll try that and let you know.
Title: Re: Linux Webstart App focus issue
Post by: BatKid on November 07, 2010, 00:45:16
Ok, so I found out what the issue was.  Focus is not a problem when I check the canvas and the Display -- they are indeed getting focus.  The culprit is the Keyboard.isKeyDown() method.

On Linux, when the user perform an "alt-tab", the "alt" key is stuck when the focus leaves the app.  So Keyboard.isKeyDown(Keyboard.KEY_LMENU) is reporting true as the application loses focus.  When the lwjgl app gains focus again, it is NOT reset, so the Keyboard is stuck reporting that the LMENU key is still down.  The only way to get out of it is to press the ALT key again.

I'm not sure if it is a Java issue or a LWJGL issue. 

Thanks
Title: Re: Linux Webstart App focus issue
Post by: kappa on November 07, 2010, 13:26:41
hmm, odd issue, so if Keyboard.isKeyDown(Keyboard.KEY_LMENU) you can't refocus the window? or was that something specific to your program?

As for the behaviour, its normal with LWJGL, that if a key is pressed down and the window looses focus, it'll continue being reported as pressed down until pressed again. If this is to be changed it'll have to be done for all platforms (Windows, Linux and Mac).
Title: Re: Linux Webstart App focus issue
Post by: BatKid on November 08, 2010, 01:38:45
Hey kappa, thank you so much for your quick replies.

The issue with focus is in fact not a focusing issue at all,  it is really a consequence of the sticky isKeyDown() function.  On os x at least, it seems that after an "ALT-TAB" there is no issue at all with the isKeyDown being stuck on a particular key.

If this is expected behavior, I guess I have to find a workaround within my own code -- it should be doable. 

Once again, thank you for helping me narrow it down.