diff --git a/JavaApp/libs_caciocavallo/cacio-androidnw-1.10-SNAPSHOT.jar b/JavaApp/libs_caciocavallo/cacio-androidnw-1.10-SNAPSHOT.jar index d9313f77..4fdaa9c7 100644 Binary files a/JavaApp/libs_caciocavallo/cacio-androidnw-1.10-SNAPSHOT.jar and b/JavaApp/libs_caciocavallo/cacio-androidnw-1.10-SNAPSHOT.jar differ diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java index 791a7bd9..464e0f8d 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java @@ -509,8 +509,8 @@ public class GLFW } // Minecraft triggers a glfwPollEvents() on splash screen, so update window size there. - CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE, Tools.mGLFWWindowWidth, Tools.mGLFWWindowHeight, 0, 0); - CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_WINDOW_SIZE, Tools.mGLFWWindowWidth, Tools.mGLFWWindowHeight, 0, 0); + // CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_FRAMEBUFFER_SIZE, Tools.mGLFWWindowWidth, Tools.mGLFWWindowHeight, 0, 0); + // CallbackBridge.receiveCallback(CallbackBridge.EVENT_TYPE_WINDOW_SIZE, Tools.mGLFWWindowWidth, Tools.mGLFWWindowHeight, 0, 0); mGLFWErrorCallback = GLFWErrorCallback.createPrint(); mGLFWKeyCodes = new ArrayMap<>(); diff --git a/JavaApp/src/main/java/org/lwjgl/input/Cursor.java b/JavaApp/src/main/java/org/lwjgl/input/Cursor.java index 9604aea4..b59e322d 100644 --- a/JavaApp/src/main/java/org/lwjgl/input/Cursor.java +++ b/JavaApp/src/main/java/org/lwjgl/input/Cursor.java @@ -29,6 +29,9 @@ public class Cursor { /** Flag set when the cursor has been destroyed */ private boolean destroyed; + /** Flag set if the cursor is empty */ + private boolean isEmpty; + /** * Constructs a new Cursor, with the given parameters. Mouse must have been * created before you can create Cursor objects. Cursor images are in ARGB @@ -59,14 +62,19 @@ public class Cursor { */ public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays) throws LWJGLException { - cursors = new CursorElement[numImages]; IntBuffer flippedImages = BufferUtils.createIntBuffer(images.limit()); flipImages(width, height, numImages, images, flippedImages); ByteBuffer pixels = convertARGBIntBuffertoRGBAByteBuffer(width, height, flippedImages); - + if(numImages == 1) { + isEmpty = true; + for(int i = 0; i < width*height; i++) if(pixels.get(i) != 0) { + System.out.println("Encountered non-zero byte at "+i+", custom cursor is not empty!"); + isEmpty = false; + } + } for (int i = 0; i < numImages; i++) { int size = width * height; ByteBuffer image = BufferUtils.createByteBuffer(size); @@ -248,6 +256,14 @@ public class Cursor { index = ++index % cursors.length; } + /** + /* Returns wheteher the cursor image is empty or not + */ + + /*package-private*/ boolean isEmpty() { + return isEmpty; + } + /** * A single cursor element, used when animating */ @@ -266,5 +282,4 @@ public class Cursor { throw new RuntimeException("Error creating GLFW cursor"); } } - } diff --git a/JavaApp/src/main/java/org/lwjgl/input/InfdevMouse.java b/JavaApp/src/main/java/org/lwjgl/input/InfdevMouse.java new file mode 100644 index 00000000..51ad9f7c --- /dev/null +++ b/JavaApp/src/main/java/org/lwjgl/input/InfdevMouse.java @@ -0,0 +1,25 @@ +package org.lwjgl.input; + +import net.java.openjdk.cacio.ctc.ExternalMouseReader; +import net.java.openjdk.cacio.ctc.InfdevGrabHandler; + +public class InfdevMouse implements ExternalMouseReader, Mouse.EmptyCursorGrabListener { + static { + InfdevGrabHandler.setMouseReader(new InfdevMouse()); + } + + @Override + public int getX() { + return Mouse.getAbsoluteX(); + } + + @Override + public int getY() { + return Mouse.getAbsoluteY(); + } + + @Override + public void onGrab(boolean grabbing) { + InfdevGrabHandler.setGrabbed(grabbing); + } +} diff --git a/JavaApp/src/main/java/org/lwjgl/input/Mouse.java b/JavaApp/src/main/java/org/lwjgl/input/Mouse.java index b933a3f6..2cfd05a7 100644 --- a/JavaApp/src/main/java/org/lwjgl/input/Mouse.java +++ b/JavaApp/src/main/java/org/lwjgl/input/Mouse.java @@ -31,6 +31,7 @@ */ package org.lwjgl.input; +import java.lang.reflect.Constructor; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.security.AccessController; @@ -144,6 +145,7 @@ public class Mouse { private static boolean isGrabbed; private static InputImplementation implementation; + private static EmptyCursorGrabListener grabListener = null; /** Whether we need cursor animation emulation */ private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS || @@ -151,6 +153,16 @@ public class Mouse { private static boolean clipMouseCoordinatesToWindow = !getPrivilegedBoolean("org.lwjgl.input.Mouse.allowNegativeMouseCoords"); + static { + try { + Class infdevMouse = Class.forName("org.lwjgl.input.InfdevMouse"); + Constructor constructor = infdevMouse.getConstructor(); + grabListener = (EmptyCursorGrabListener) constructor.newInstance(); + }catch (Throwable e) { + e.printStackTrace(); + } + } + /** * Mouse cannot be constructed. */ @@ -164,7 +176,6 @@ public class Mouse { */ public static Cursor getNativeCursor() { return currentCursor; - } /** @@ -181,6 +192,14 @@ public class Mouse { */ public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException { //dummy + if(cursor == null && currentCursor.isEmpty()) { + Mouse.setGrabbed(false); + if(grabListener != null) grabListener.onGrab(false); + } + if(cursor != null && cursor.isEmpty()) { + Mouse.setGrabbed(true); + if(grabListener != null) grabListener.onGrab(true); + } currentCursor = cursor; return currentCursor; } @@ -625,4 +644,18 @@ public class Mouse { public static boolean isInsideWindow() { return implementation.isInsideWindow(); } + + /* + * Package private methods to get the absolute unclipped X/Y coordiates + */ + /*package-private*/ static int getAbsoluteX() { + return absolute_x; + } + /*package-private*/ static int getAbsoluteY() { + return absolute_y; + } + + interface EmptyCursorGrabListener { + void onGrab(boolean grabbing); + } } \ No newline at end of file diff --git a/JavaApp/src/main/java/org/lwjgl/opengl/AWTGLCanvas.java b/JavaApp/src/main/java/org/lwjgl/opengl/AWTGLCanvas.java index e97e97de..797b6821 100644 --- a/JavaApp/src/main/java/org/lwjgl/opengl/AWTGLCanvas.java +++ b/JavaApp/src/main/java/org/lwjgl/opengl/AWTGLCanvas.java @@ -79,7 +79,8 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, } public AWTGLCanvas() throws LWJGLException { - Display.create(); + System.out.println("AWTGLCanvas constructor called on thread:"+Thread.currentThread().getName()); + //Display.create(); } public AWTGLCanvas(PixelFormat pixel_format) throws LWJGLException { diff --git a/Natives/input_bridge_v3.m b/Natives/input_bridge_v3.m index e466c17b..54b6ba50 100644 --- a/Natives/input_bridge_v3.m +++ b/Natives/input_bridge_v3.m @@ -277,6 +277,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputRead } JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(JNIEnv* env, jclass clazz, jboolean grabbing, jfloat xset, jfloat yset) { + CallbackBridge_nativeSendScreenSize(windowWidth, windowHeight); isGrabbing = grabbing; if (isGrabbing == JNI_TRUE) { grabCursorX = xset; // savedWidth / 2;