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 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