Better mouse timing, reduced JNI calls to isGrabbing

This commit is contained in:
Boulay Mathias 2022-07-16 17:00:52 +02:00
parent b9529a5f59
commit 2aafb3bbfc

View File

@ -5,8 +5,12 @@ import android.os.Looper;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import android.content.*; import android.content.*;
import android.view.Choreographer;
public class CallbackBridge { 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 ANDROID_TYPE_GRAB_STATE = 0;
public static final int CLIPBOARD_COPY = 2000; public static final int CLIPBOARD_COPY = 2000;
@ -21,12 +25,9 @@ public class CallbackBridge {
public volatile static boolean holdingAlt, holdingCapslock, holdingCtrl, public volatile static boolean holdingAlt, holdingCapslock, holdingCtrl,
holdingNumlock, holdingShift; holdingNumlock, holdingShift;
public static void putMouseEventWithCoords(int button, float x, float y) { public static void putMouseEventWithCoords(int button, float x, float y) {
putMouseEventWithCoords(button, true, x, y); putMouseEventWithCoords(button, true, x, y);
Handler handler = new Handler(Looper.getMainLooper()); sChoreographer.postFrameCallbackDelayed(l -> putMouseEventWithCoords(button, false, x, y), 33);
handler.postDelayed(() -> putMouseEventWithCoords(button, false, x, y), 22);
} }
public static void putMouseEventWithCoords(int button, boolean isDown, float x, float y /* , int dz, long nanos */) { 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() { public static boolean isGrabbing() {
// return isGrabbing; // Avoid going through the JNI each time.
return nativeIsGrabbing(); long currentTime = System.currentTimeMillis();
if (currentTime - lastGrabTime > 250){
isGrabbing = nativeIsGrabbing();
lastGrabTime = currentTime;
}
return isGrabbing;
} }
// Called from JRE side // Called from JRE side