From 6b3307410e9511b84dcb6469e5f67544803d3ae7 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 3 Aug 2023 10:02:13 +0100 Subject: [PATCH] GameActivity PATCH: Don't read unicode via getUnicodeChar The `unicodeChar` in `GameActivityKeyEvent` wasn't being exposed by `android-activity` because we couldn't expose the unicode character in the same way with the native-activity backend - due to how events are received via an `InputQueue` that doesn't expose the underlying Java references for the key events. Now that we have a consistent way of supporting unicode character mapping via `KeyCharacterMap` bindings it's redundant for the `GameActivity` backend to call `getUnicodeChar` automatically for each key press. --- .../game-activity/GameActivityEvents.cpp | 11 ++++++----- .../game-activity/GameActivityEvents.h | 2 +- android-activity/src/game_activity/ffi_aarch64.rs | 13 +------------ android-activity/src/game_activity/ffi_arm.rs | 13 +------------ android-activity/src/game_activity/ffi_i686.rs | 13 +------------ android-activity/src/game_activity/ffi_x86_64.rs | 13 +------------ 6 files changed, 11 insertions(+), 54 deletions(-) diff --git a/android-activity/game-activity-csrc/game-activity/GameActivityEvents.cpp b/android-activity/game-activity-csrc/game-activity/GameActivityEvents.cpp index 4142601..028b55e 100644 --- a/android-activity/game-activity-csrc/game-activity/GameActivityEvents.cpp +++ b/android-activity/game-activity-csrc/game-activity/GameActivityEvents.cpp @@ -345,7 +345,7 @@ static struct { jmethodID getRepeatCount; jmethodID getKeyCode; jmethodID getScanCode; - jmethodID getUnicodeChar; + //jmethodID getUnicodeChar; } gKeyEventClassInfo; extern "C" void GameActivityKeyEvent_fromJava(JNIEnv *env, jobject keyEvent, @@ -379,8 +379,8 @@ extern "C" void GameActivityKeyEvent_fromJava(JNIEnv *env, jobject keyEvent, env->GetMethodID(keyEventClass, "getKeyCode", "()I"); gKeyEventClassInfo.getScanCode = env->GetMethodID(keyEventClass, "getScanCode", "()I"); - gKeyEventClassInfo.getUnicodeChar = - env->GetMethodID(keyEventClass, "getUnicodeChar", "()I"); + //gKeyEventClassInfo.getUnicodeChar = + // env->GetMethodID(keyEventClass, "getUnicodeChar", "()I"); gKeyEventClassInfoInitialized = true; } @@ -407,7 +407,8 @@ extern "C" void GameActivityKeyEvent_fromJava(JNIEnv *env, jobject keyEvent, /*keyCode=*/ env->CallIntMethod(keyEvent, gKeyEventClassInfo.getKeyCode), /*scanCode=*/ - env->CallIntMethod(keyEvent, gKeyEventClassInfo.getScanCode), + env->CallIntMethod(keyEvent, gKeyEventClassInfo.getScanCode) /*unicodeChar=*/ - env->CallIntMethod(keyEvent, gKeyEventClassInfo.getUnicodeChar)}; + //env->CallIntMethod(keyEvent, gKeyEventClassInfo.getUnicodeChar) + }; } diff --git a/android-activity/game-activity-csrc/game-activity/GameActivityEvents.h b/android-activity/game-activity-csrc/game-activity/GameActivityEvents.h index 183c72f..015ffbe 100644 --- a/android-activity/game-activity-csrc/game-activity/GameActivityEvents.h +++ b/android-activity/game-activity-csrc/game-activity/GameActivityEvents.h @@ -312,7 +312,7 @@ typedef struct GameActivityKeyEvent { int32_t repeatCount; int32_t keyCode; int32_t scanCode; - int32_t unicodeChar; + //int32_t unicodeChar; } GameActivityKeyEvent; /** diff --git a/android-activity/src/game_activity/ffi_aarch64.rs b/android-activity/src/game_activity/ffi_aarch64.rs index 0d5c320..cd3fabd 100644 --- a/android-activity/src/game_activity/ffi_aarch64.rs +++ b/android-activity/src/game_activity/ffi_aarch64.rs @@ -2686,7 +2686,6 @@ pub struct GameActivityKeyEvent { pub repeatCount: i32, pub keyCode: i32, pub scanCode: i32, - pub unicodeChar: i32, } #[test] fn bindgen_test_layout_GameActivityKeyEvent() { @@ -2694,7 +2693,7 @@ fn bindgen_test_layout_GameActivityKeyEvent() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 64usize, + 56usize, concat!("Size of: ", stringify!(GameActivityKeyEvent)) ); assert_eq!( @@ -2812,16 +2811,6 @@ fn bindgen_test_layout_GameActivityKeyEvent() { stringify!(scanCode) ) ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).unicodeChar) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(GameActivityKeyEvent), - "::", - stringify!(unicodeChar) - ) - ); } extern "C" { #[doc = " \\brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.\n\n This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`\n to set a callback to consume the received events.\n This function can be used if you re-implement events handling in your own\n activity.\n Ownership of out_event is maintained by the caller."] diff --git a/android-activity/src/game_activity/ffi_arm.rs b/android-activity/src/game_activity/ffi_arm.rs index f33e4bc..8933437 100644 --- a/android-activity/src/game_activity/ffi_arm.rs +++ b/android-activity/src/game_activity/ffi_arm.rs @@ -2716,7 +2716,6 @@ pub struct GameActivityKeyEvent { pub repeatCount: i32, pub keyCode: i32, pub scanCode: i32, - pub unicodeChar: i32, } #[test] fn bindgen_test_layout_GameActivityKeyEvent() { @@ -2724,7 +2723,7 @@ fn bindgen_test_layout_GameActivityKeyEvent() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 64usize, + 56usize, concat!("Size of: ", stringify!(GameActivityKeyEvent)) ); assert_eq!( @@ -2842,16 +2841,6 @@ fn bindgen_test_layout_GameActivityKeyEvent() { stringify!(scanCode) ) ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).unicodeChar) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(GameActivityKeyEvent), - "::", - stringify!(unicodeChar) - ) - ); } extern "C" { #[doc = " \\brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.\n\n This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`\n to set a callback to consume the received events.\n This function can be used if you re-implement events handling in your own\n activity.\n Ownership of out_event is maintained by the caller."] diff --git a/android-activity/src/game_activity/ffi_i686.rs b/android-activity/src/game_activity/ffi_i686.rs index ed9075f..d18082f 100644 --- a/android-activity/src/game_activity/ffi_i686.rs +++ b/android-activity/src/game_activity/ffi_i686.rs @@ -2637,7 +2637,6 @@ pub struct GameActivityKeyEvent { pub repeatCount: i32, pub keyCode: i32, pub scanCode: i32, - pub unicodeChar: i32, } #[test] fn bindgen_test_layout_GameActivityKeyEvent() { @@ -2645,7 +2644,7 @@ fn bindgen_test_layout_GameActivityKeyEvent() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 56usize, + 52usize, concat!("Size of: ", stringify!(GameActivityKeyEvent)) ); assert_eq!( @@ -2763,16 +2762,6 @@ fn bindgen_test_layout_GameActivityKeyEvent() { stringify!(scanCode) ) ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).unicodeChar) as usize - ptr as usize }, - 52usize, - concat!( - "Offset of field: ", - stringify!(GameActivityKeyEvent), - "::", - stringify!(unicodeChar) - ) - ); } extern "C" { #[doc = " \\brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.\n\n This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`\n to set a callback to consume the received events.\n This function can be used if you re-implement events handling in your own\n activity.\n Ownership of out_event is maintained by the caller."] diff --git a/android-activity/src/game_activity/ffi_x86_64.rs b/android-activity/src/game_activity/ffi_x86_64.rs index 852e212..1e9d92a 100644 --- a/android-activity/src/game_activity/ffi_x86_64.rs +++ b/android-activity/src/game_activity/ffi_x86_64.rs @@ -2666,7 +2666,6 @@ pub struct GameActivityKeyEvent { pub repeatCount: i32, pub keyCode: i32, pub scanCode: i32, - pub unicodeChar: i32, } #[test] fn bindgen_test_layout_GameActivityKeyEvent() { @@ -2674,7 +2673,7 @@ fn bindgen_test_layout_GameActivityKeyEvent() { let ptr = UNINIT.as_ptr(); assert_eq!( ::std::mem::size_of::(), - 64usize, + 56usize, concat!("Size of: ", stringify!(GameActivityKeyEvent)) ); assert_eq!( @@ -2792,16 +2791,6 @@ fn bindgen_test_layout_GameActivityKeyEvent() { stringify!(scanCode) ) ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).unicodeChar) as usize - ptr as usize }, - 56usize, - concat!( - "Offset of field: ", - stringify!(GameActivityKeyEvent), - "::", - stringify!(unicodeChar) - ) - ); } extern "C" { #[doc = " \\brief Convert a Java `KeyEvent` to a `GameActivityKeyEvent`.\n\n This is done automatically by the GameActivity: see `onKeyUp` and `onKeyDown`\n to set a callback to consume the received events.\n This function can be used if you re-implement events handling in your own\n activity.\n Ownership of out_event is maintained by the caller."]