Linux Webstart App focus issue

Started by BatKid, November 06, 2010, 00:09:50

Previous topic - Next topic

BatKid

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
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

kappa

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.

BatKid

Thanks!  I'll try that and let you know.
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

BatKid

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
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment

kappa

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).

BatKid

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.
Projects: 
   Env3D (http://env3d.org): Learn Java in 3D
   WhaleChat (http://whalechat.com): A 3D social programming experiment