Fix[mousegrab]: edit mouse grab code to follow android guidelines

https://developer.android.com/develop/ui/views/touch-and-input/gestures/movement#pointer-capture
This commit is contained in:
artdeell 2023-11-18 15:12:09 +03:00
parent c773b92527
commit 540d8b5940

View File

@ -624,7 +624,8 @@ public class MinecraftGLSurface extends View implements GrabListener {
if(isGrabbing){ if(isGrabbing){
if(!hasPointerCapture) { if(!hasPointerCapture) {
requestFocus(); requestFocus();
requestPointerCapture(); if(hasWindowFocus()) requestPointerCapture();
// Otherwise, onWindowFocusChanged() would get called.
} }
return; return;
} }
@ -635,6 +636,13 @@ public class MinecraftGLSurface extends View implements GrabListener {
} }
} }
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
if(hasWindowFocus && CallbackBridge.isGrabbing() &&
MainActivity.isAndroid8OrHigher()) requestPointerCapture();
}
/** A small interface called when the listener is ready for the first time */ /** A small interface called when the listener is ready for the first time */
public interface SurfaceReadyListener { public interface SurfaceReadyListener {
void isReady(); void isReady();