From 4214cb6eb8828e319b90cfde6604cc36eb236f19 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Tue, 13 May 2025 16:55:48 +0200 Subject: Android: Make input state changes observable --- Source/Core/InputCommon/ControllerInterface/Android/Android.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/InputCommon/ControllerInterface/Android/Android.cpp') diff --git a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp index b6e03e73a0..72d7239f9a 100644 --- a/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Android/Android.cpp @@ -1002,7 +1002,7 @@ void InputBackend::PopulateDevices() extern "C" { JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchKeyEvent( +Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchKeyEventNative( JNIEnv* env, jclass, jobject key_event) { const jint action = env->CallIntMethod(key_event, s_key_event_get_action); @@ -1046,7 +1046,7 @@ Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatch } JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchGenericMotionEvent( +Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchGenericMotionEventNative( JNIEnv* env, jclass, jobject motion_event) { const jint device_id = env->CallIntMethod(motion_event, s_input_event_get_device_id); @@ -1090,7 +1090,7 @@ Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatch } JNIEXPORT jboolean JNICALL -Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchSensorEvent( +Java_org_dolphinemu_dolphinemu_features_input_model_ControllerInterface_dispatchSensorEventNative( JNIEnv* env, jclass, jstring j_device_qualifier, jstring j_axis_name, jfloat value) { ciface::Core::DeviceQualifier device_qualifier; -- cgit v1.2.3 From 43b254aaad5add867b719857d6f8b4fe2d6b750d Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 16 May 2025 18:12:21 +0200 Subject: 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. --- .../ControllerInterface/Android/Android.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'Source/Core/InputCommon/ControllerInterface/Android/Android.cpp') 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 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(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() -- cgit v1.2.3