[FIXED] Display.isActive() false negatives on Mac OS X

Started by butaca, June 17, 2011, 00:34:27

Previous topic - Next topic

butaca

In Mac OS X, I found two situations in which Display.isActive() returns false when it is actually active.

1) When the Display is inactive at startup (for example, launching the application and immediately click like hell in other windows before the before the creation of the display...), Display.isActive() keeps returning false after activating it with Command+TAB, clicking the application Dock icon, or in the menu bar. However it reactivates normally clicking inside the window.

Here a code snippet to illustrate the situation. When the display is active I draw a blue background and red when it is inactive. I tested it on two Macs:

package test;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

public class DisplayActiveTest {

	public static void main(String[] args) throws LWJGLException {

		DisplayMode mode = new DisplayMode(800, 600);
		Display.setVSyncEnabled(false);
		Display.setDisplayMode(mode);
		Display.create();

		boolean running = true;

		while (running) {

			Display.update();
			Keyboard.poll();
			while (Keyboard.next()) {
				if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE && Keyboard.getEventKeyState()) {
					running = false;
				}
			}

			if (Display.isCloseRequested()) {
				running = false;
			}
			
			if(Display.isActive()) {
				GL11.glClearColor(0, 0, 1, 1);
				GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
			}
			else
			{
				GL11.glClearColor(1, 0, 0, 1);
				GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
			}

			try {
				// Give the OS as break and simulate work
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

		Display.destroy();
	}	
}


2) The false negative also happens *sometimes* when goinh from fullscreen to windows mode. I found a workaround for this by calling Display.update() immediately after the change of mode.

Hope I'm clear and this is helpful.

Greetings,
Butaca

Matzon

1) sounds like an interesting bug.
2) is expected behavior. LWJGL does now know the native state, until it has processed its message queue - which it does in Display.update - or the processMessages.


butaca

Hi Matzon,

Thanks for your response and the info. Good to know that 2) isn't a bug.

If you need something to resolve 1), please let me know.

Greetings,
Butaca

kappa