Frame.isActive()

So I have a bit of code that detects whether the Frame is active (window.isActive()) to determine whether to tick my game loop. This works great on Windows and Mac OS, but on Linux, isActive() never returns true, even when it’s clearly the active window on the desktop. Can anybody enlighten me as to why this is the case?

Further info: it’s a Frame with a single Canvas inside it, and the Canvas has got a LWJGL Display.setParent() called on it.

Cas :slight_smile:

I’m guessing because the LWJGL native Display window grabs the activeness from AWT. Have you tried the Display.isActive() method ? It should give you the behaviour you’re looking for.

Yes, I’ve tried that too (in addition - so frame.isActive() || display.isActive() || canvas.isFocused() or whatever). Nothing works. LWJGL 2.7.1. Can’t upgrade to 2.8 yet because of all the other little troubles with it. (Need to figure out some way of getting some more formal testing for LWJGL I think)

Cas :slight_smile:

What if you added a focus listener to the frame; maybe you can track if it’s the active window that way.

Tried adding focus listeners to frame and canvas - no joy. Absolutely nothing works. I just can’t fathom it.

Cas :slight_smile:

Doubtful, but you could also try a WindowListener and listen on the ‘windowActivated’ method.

You could also check ‘isFocused’ on the frame, as the main focused window is also the active window.

If you can detect losing focus, then as a workaround you could just listen on keyboard/mouse events to know when the window regains focus. However I am not sure if it will work with alt+tab, but you could also try checking on when the frame is asked to repaint.

A second alternative could be to try to solve this using bash scripts, running silently in the background, which somehow call back to the window to notify it when it’s state has changed.

Just go for the current nightly builds of LWJGL 2.8.2. The above should be fixed in there (with Display.isActive() at least) and it also has fixes for all the major issues that have been reported for 2.8.1.

The official LWJGL 2.8.2 should be out any time now and will likely be identical to the current nightly.

I’ll take a punt on the 2.8.2 nightlies and see how it works out. The bugs in 2.8.1 just coincided really badly with my release schedule.

Cas :slight_smile:

… I wonder how Minecraft gets this working all right. Maybe using a much earlier version of LWJGL.

Cas :slight_smile:

Yeh, they’re still using LWJGL 2.4, its one of the most complained about MC issues. There are tons of users complaining about it. However there are a lots of guides, tools and mods out there for the game now that explain how to manually (or even automatically) update the LWJGL version to the latest.