mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-04 15:06:08 +00:00
Avoid unnecessary reinitialization of PS4/PS5 gamepads during stream exit
onInputDeviceChanged() is triggered by starting/stopping pointer capture, so we should unregister our callbacks before that happens to avoid triggering several gamepad context reinitializations right as the stream is exiting
This commit is contained in:
@@ -495,7 +495,6 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
||||
keyboardTranslator = new KeyboardTranslator();
|
||||
|
||||
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
inputManager.registerInputDeviceListener(controllerHandler, null);
|
||||
inputManager.registerInputDeviceListener(keyboardTranslator, null);
|
||||
|
||||
// Initialize touch contexts
|
||||
@@ -1079,12 +1078,11 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
if (controllerHandler != null) {
|
||||
inputManager.unregisterInputDeviceListener(controllerHandler);
|
||||
controllerHandler.destroy();
|
||||
}
|
||||
if (keyboardTranslator != null) {
|
||||
InputManager inputManager = (InputManager) getSystemService(Context.INPUT_SERVICE);
|
||||
inputManager.unregisterInputDeviceListener(keyboardTranslator);
|
||||
}
|
||||
|
||||
@@ -1104,6 +1102,21 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
||||
inputCaptureProvider.destroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
if (isFinishing()) {
|
||||
// Stop any further input device notifications before we lose focus (and pointer capture)
|
||||
if (controllerHandler != null) {
|
||||
controllerHandler.stop();
|
||||
}
|
||||
|
||||
// Ungrab input to prevent further input device notifications
|
||||
setInputGrabState(false);
|
||||
}
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
@@ -2310,6 +2323,9 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
||||
// Let the display go to sleep now
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
// Stop processing controller input
|
||||
controllerHandler.stop();
|
||||
|
||||
// Ungrab input
|
||||
setInputGrabState(false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user