[FIXED] MacOSX - isMouseInside and cursor bug

Started by mattdesl, October 16, 2012, 22:03:25

Previous topic - Next topic

mattdesl

Two bugs:

1. Mouse.isInsideWindow() always returns true on my Mac.

2. Mouse.setNativeCursor doesn't work after Alt + Tabbing or losing window focus, even when called every frame. For example: open a Finder window which will make your game lose focus. With the LWJGL app still visible behind the Finder window, click inside the app. The Mac mouse will persist even though it should not. Once you move the mouse outside the app window and back, it will work correctly again.

Mac OSX 10.6.6 using LWJGL 2.8.5.

A hack/workaround is to set the cursor to null whenever the app gains focus. Here is some code demonstrating the above bugs and a workaround.

package slim.test;

import java.nio.IntBuffer;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.input.Cursor;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class TestBug {

	public static void main(String[] args) throws LWJGLException {
		Display.setDisplayMode(new DisplayMode(800, 600));
		Display.create();

		int min = org.lwjgl.input.Cursor.getMinCursorSize();
		IntBuffer tmp = BufferUtils.createIntBuffer(min * min);
		Cursor cursor = new Cursor(min, min, min / 2, min / 2, 1, tmp, null);

		boolean inFocus = false;
		while (!Display.isCloseRequested()) {
			boolean inFocusOld = inFocus;
			inFocus = Display.isActive();
			
			if (Mouse.isInsideWindow()) {
				//BUG 1: always called, even when window is not active
				System.out.println("Mouse is inside window.."+Sys.getTime());
				
				//BUG 2: Sometimes the hardware cursor is not set...
				// --- WORKAROUND: clear cursor when app gains focus
				if (!inFocusOld && inFocus)
					Mouse.setNativeCursor(null);
				// ---
				
				//Set our hardware cursor
				Mouse.setNativeCursor(cursor);
			}
				
			Display.update();
		}

		Display.destroy();
	}
}

kappa

there is little point to fix this in the current OS X code base, once we get the OS X rewritten code (as per this thread),  then it might already be fixed or worth attempting to fix.

kappa