Fix: Ensure the mouse grab state.

This is also accompagnied with a slight optimisation of the updateGrabbingState function, since it will be called quite a high number of times
This commit is contained in:
Mathias-Boulay 2022-12-25 17:43:07 +01:00
parent 63e822325c
commit e566dd143e

View File

@ -409,6 +409,10 @@ public class MinecraftGLSurface extends View implements GrabListener{
break;
}
if(mouseCursorIndex == -1) return false; // we cant consoom that, theres no mice!
// Make sure we grabbed the mouse if necessary
updateGrabState(CallbackBridge.isGrabbing());
switch(event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_MOVE:
CallbackBridge.mouseX = (event.getX(mouseCursorIndex) * mScaleFactor);
@ -650,16 +654,20 @@ public class MinecraftGLSurface extends View implements GrabListener{
}
private void updateGrabState(boolean isGrabbing) {
if(MainActivity.isAndroid8OrHigher()) {
if (isGrabbing && !hasPointerCapture()) {
if(!MainActivity.isAndroid8OrHigher()) return;
boolean hasPointerCapture = hasPointerCapture();
if(isGrabbing){
if(!hasPointerCapture) {
requestFocus();
requestPointerCapture();
}
return;
}
if (!isGrabbing && hasPointerCapture()) {
releasePointerCapture();
clearFocus();
}
if(hasPointerCapture) {
releasePointerCapture();
clearFocus();
}
}