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(!hasPointerCapture) {
requestFocus();
requestPointerCapture();
if(hasWindowFocus()) requestPointerCapture();
// Otherwise, onWindowFocusChanged() would get called.
}
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 */
public interface SurfaceReadyListener {
void isReady();