Ungrab meta key capture when toggling input capture

This commit is contained in:
Cameron Gutman
2022-11-13 13:19:23 -06:00
parent 00415aac79
commit 4a64967b1f

View File

@@ -1126,17 +1126,25 @@ public class Game extends Activity implements SurfaceHolder.Callback,
finish();
}
private void setInputGrabState(boolean grab) {
// Grab/ungrab the mouse cursor
if (grab) {
inputCaptureProvider.disableCapture();
}
else {
inputCaptureProvider.enableCapture();
}
// Grab/ungrab system keyboard shortcuts
setMetaKeyCaptureState(grab);
grabbedInput = grab;
}
private final Runnable toggleGrab = new Runnable() {
@Override
public void run() {
if (grabbedInput) {
inputCaptureProvider.disableCapture();
}
else {
inputCaptureProvider.enableCapture();
}
grabbedInput = !grabbedInput;
setInputGrabState(!grabbedInput);
}
};
@@ -1881,11 +1889,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
// Let the display go to sleep now
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Enable cursor visibility again
inputCaptureProvider.disableCapture();
// Disable meta key capture
setMetaKeyCaptureState(false);
// Ungrab input
setInputGrabState(false);
if (!displayedFailureDialog) {
displayedFailureDialog = true;
@@ -1995,16 +2000,13 @@ public class Game extends Activity implements SurfaceHolder.Callback,
h.postDelayed(new Runnable() {
@Override
public void run() {
inputCaptureProvider.enableCapture();
setInputGrabState(true);
}
}, 500);
// Keep the display on
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// Enable meta key capture
setMetaKeyCaptureState(true);
// Update GameManager state to indicate we're in game
UiHelper.notifyStreamConnected(Game.this);