Infdev cursor grab: the Pojav part

Also featuring:
Window resize on first key even poll
This commit is contained in:
artdeell 2023-01-29 22:17:24 +03:00
parent 328581c2a9
commit 693cff45b0
9 changed files with 98 additions and 5 deletions

View File

@ -1 +1 @@
HEllo PeoplE HEllo PeopLE

View File

@ -252,11 +252,14 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeClipboard(JNI
return pasteDst; return pasteDst;
} }
void Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(JNIEnv* env, jclass clazz, jint width, jint height);
JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(JNIEnv* env, jclass clazz, jboolean inputReady) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetInputReady(JNIEnv* env, jclass clazz, jboolean inputReady) {
#ifdef DEBUG #ifdef DEBUG
LOGD("Debug: Changing input state, isReady=%d, isUseStackQueueCall=%d\n", inputReady, isUseStackQueueCall); LOGD("Debug: Changing input state, isReady=%d, isUseStackQueueCall=%d\n", inputReady, isUseStackQueueCall);
#endif #endif
isInputReady = inputReady; isInputReady = inputReady;
if(isInputReady) Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(NULL, NULL, savedWidth, savedHeight);
return isUseStackQueueCall; return isUseStackQueueCall;
} }

View File

@ -20,6 +20,7 @@ jar {
it.isDirectory() ? it : zipTree(it) it.isDirectory() ? it : zipTree(it)
} }
} }
exclude 'net/java/openjdk/cacio/ctc/**'
} }
java { java {

View File

@ -0,0 +1,6 @@
package net.java.openjdk.cacio.ctc;
public interface ExternalMouseReader {
int getX();
int getY();
}

View File

@ -0,0 +1,10 @@
package net.java.openjdk.cacio.ctc;
public class InfdevGrabHandler {
public static void setMouseReader(ExternalMouseReader reader) {
}
public static void setGrabbed(boolean grabbed) {
}
}

View File

@ -29,6 +29,9 @@ public class Cursor {
/** Flag set when the cursor has been destroyed */ /** Flag set when the cursor has been destroyed */
private boolean 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 * Constructs a new Cursor, with the given parameters. Mouse must have been
* created before you can create Cursor objects. Cursor images are in ARGB * 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) public Cursor(int width, int height, int xHotspot, int yHotspot, int numImages, IntBuffer images, IntBuffer delays)
throws LWJGLException { throws LWJGLException {
cursors = new CursorElement[numImages]; cursors = new CursorElement[numImages];
IntBuffer flippedImages = BufferUtils.createIntBuffer(images.limit()); IntBuffer flippedImages = BufferUtils.createIntBuffer(images.limit());
flipImages(width, height, numImages, images, flippedImages); flipImages(width, height, numImages, images, flippedImages);
ByteBuffer pixels = convertARGBIntBuffertoRGBAByteBuffer(width, height, 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++) { for (int i = 0; i < numImages; i++) {
int size = width * height; int size = width * height;
ByteBuffer image = BufferUtils.createByteBuffer(size); ByteBuffer image = BufferUtils.createByteBuffer(size);
@ -248,6 +256,14 @@ public class Cursor {
index = ++index % cursors.length; 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 * A single cursor element, used when animating
*/ */
@ -266,5 +282,4 @@ public class Cursor {
throw new RuntimeException("Error creating GLFW cursor"); throw new RuntimeException("Error creating GLFW cursor");
} }
} }
} }

View File

@ -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);
}
}

View File

@ -31,6 +31,7 @@
*/ */
package org.lwjgl.input; package org.lwjgl.input;
import java.lang.reflect.Constructor;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.security.AccessController; import java.security.AccessController;
@ -144,6 +145,7 @@ public class Mouse {
private static boolean isGrabbed; private static boolean isGrabbed;
private static InputImplementation implementation; private static InputImplementation implementation;
private static EmptyCursorGrabListener grabListener = null;
/** Whether we need cursor animation emulation */ /** Whether we need cursor animation emulation */
private static final boolean emulateCursorAnimation = LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_WINDOWS || 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"); 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. * Mouse cannot be constructed.
*/ */
@ -164,7 +176,6 @@ public class Mouse {
*/ */
public static Cursor getNativeCursor() { public static Cursor getNativeCursor() {
return currentCursor; return currentCursor;
} }
/** /**
@ -181,6 +192,14 @@ public class Mouse {
*/ */
public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException { public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException {
//dummy //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; currentCursor = cursor;
return currentCursor; return currentCursor;
} }
@ -625,4 +644,18 @@ public class Mouse {
public static boolean isInsideWindow() { public static boolean isInsideWindow() {
return implementation.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);
}
} }