diff --git a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java index 2df40f007..12ca84982 100644 --- a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java +++ b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java @@ -5,8 +5,12 @@ import android.os.Looper; import net.kdt.pojavlaunch.*; import android.content.*; +import android.view.Choreographer; public class CallbackBridge { + public static Choreographer sChoreographer = Choreographer.getInstance(); + private static boolean isGrabbing = false; + private static long lastGrabTime = System.currentTimeMillis(); public static final int ANDROID_TYPE_GRAB_STATE = 0; public static final int CLIPBOARD_COPY = 2000; @@ -21,12 +25,9 @@ public class CallbackBridge { public volatile static boolean holdingAlt, holdingCapslock, holdingCtrl, holdingNumlock, holdingShift; - public static void putMouseEventWithCoords(int button, float x, float y) { putMouseEventWithCoords(button, true, x, y); - Handler handler = new Handler(Looper.getMainLooper()); - handler.postDelayed(() -> putMouseEventWithCoords(button, false, x, y), 22); - + sChoreographer.postFrameCallbackDelayed(l -> putMouseEventWithCoords(button, false, x, y), 33); } public static void putMouseEventWithCoords(int button, boolean isDown, float x, float y /* , int dz, long nanos */) { @@ -119,8 +120,13 @@ public class CallbackBridge { } public static boolean isGrabbing() { - // return isGrabbing; - return nativeIsGrabbing(); + // Avoid going through the JNI each time. + long currentTime = System.currentTimeMillis(); + if (currentTime - lastGrabTime > 250){ + isGrabbing = nativeIsGrabbing(); + lastGrabTime = currentTime; + } + return isGrabbing; } // Called from JRE side