diff options
| author | JosJuice <josjuice@gmail.com> | 2025-05-16 18:12:21 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2025-06-07 10:20:21 +0200 |
| commit | 43b254aaad5add867b719857d6f8b4fe2d6b750d (patch) | |
| tree | dafdbc53eb3a115d0c9532b2704bb8fa53e57c80 /Source/Core/InputCommon/ControllerInterface | |
| parent | 1002f296918153c55dca674b3d70a54485f00306 (diff) | |
Android: Update advanced mapping dialog when devices change
Without this, there was a bug where if you turned the device's screen
off and on again while in the advanced mapping dialog, the input
indicators would stop updating. This is because turning the screen on
again causes devices to refresh, which causes all devices to be
recreated, leaving the AdvancedMappingControlViewHolders stuck
referencing controls belonging to devices that are no longer being
updated.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Android/Android.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index 72d7239f9a..476aaa5537 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -442,6 +442,25 @@ std::shared_ptr<ciface::Core::Device> FindDevice(jint device_id) return device; } +void RegisterDevicesChangedCallbackIfNeeded(JNIEnv* env, jclass controller_interface_class) +{ + static bool registered = false; + if (registered) + return; + registered = true; + + const jclass global_controller_interface_class = + reinterpret_cast<jclass>(env->NewGlobalRef(controller_interface_class)); + const jmethodID controller_interface_on_devices_changed = + env->GetStaticMethodID(global_controller_interface_class, "onDevicesChanged", "()V"); + + g_controller_interface.RegisterDevicesChangedCallback( + [global_controller_interface_class, controller_interface_on_devices_changed] { + IDCache::GetEnvForThread()->CallStaticVoidMethod(global_controller_interface_class, + controller_interface_on_devices_changed); + }); +} + } // namespace namespace ciface::Android @@ -903,6 +922,8 @@ InputBackend::InputBackend(ControllerInterface* controller_interface) env->CallStaticVoidMethod(s_controller_interface_class, s_controller_interface_register_input_device_listener); + + RegisterDevicesChangedCallbackIfNeeded(env, s_controller_interface_class); } InputBackend::~InputBackend() |
