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