diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-10-02 20:01:27 +0300 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2024-10-02 20:09:48 +0300 |
commit | 25f439c573eefbc7cff2ea92952c9c68f1f0744a (patch) | |
tree | 3ee3dec438a97926280f7d6c6f1d3621beb55545 /platform | |
parent | 1917bc3454e58fc56750b00e04aa25cb94d8d266 (diff) | |
download | redot-engine-25f439c573eefbc7cff2ea92952c9c68f1f0744a.tar.gz |
[DisplayServer] Implement has_hardware_keyboard method for Android and iOS.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/display_server_android.cpp | 7 | ||||
-rw-r--r-- | platform/android/display_server_android.h | 1 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/GodotIO.java | 8 | ||||
-rw-r--r-- | platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java | 2 | ||||
-rw-r--r-- | platform/android/java_godot_io_wrapper.cpp | 11 | ||||
-rw-r--r-- | platform/android/java_godot_io_wrapper.h | 2 | ||||
-rw-r--r-- | platform/ios/display_server_ios.h | 1 | ||||
-rw-r--r-- | platform/ios/display_server_ios.mm | 10 |
8 files changed, 41 insertions, 1 deletions
diff --git a/platform/android/display_server_android.cpp b/platform/android/display_server_android.cpp index c1053215c6..fa5b970a96 100644 --- a/platform/android/display_server_android.cpp +++ b/platform/android/display_server_android.cpp @@ -304,6 +304,13 @@ int DisplayServerAndroid::virtual_keyboard_get_height() const { return godot_io_java->get_vk_height(); } +bool DisplayServerAndroid::has_hardware_keyboard() const { + GodotIOJavaWrapper *godot_io_java = OS_Android::get_singleton()->get_godot_io_java(); + ERR_FAIL_NULL_V(godot_io_java, false); + + return godot_io_java->has_hardware_keyboard(); +} + void DisplayServerAndroid::window_set_window_event_callback(const Callable &p_callable, DisplayServer::WindowID p_window) { window_event_callback = p_callable; } diff --git a/platform/android/display_server_android.h b/platform/android/display_server_android.h index 90bda18cfa..65c6a53446 100644 --- a/platform/android/display_server_android.h +++ b/platform/android/display_server_android.h @@ -138,6 +138,7 @@ public: virtual void virtual_keyboard_show(const String &p_existing_text, const Rect2 &p_screen_rect = Rect2(), VirtualKeyboardType p_type = KEYBOARD_TYPE_DEFAULT, int p_max_length = -1, int p_cursor_start = -1, int p_cursor_end = -1) override; virtual void virtual_keyboard_hide() override; virtual int virtual_keyboard_get_height() const override; + virtual bool has_hardware_keyboard() const override; virtual void window_set_window_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override; virtual void window_set_input_event_callback(const Callable &p_callable, WindowID p_window = MAIN_WINDOW_ID) override; diff --git a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java index 219631284a..f060c7aaff 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java +++ b/platform/android/java/lib/src/org/godotengine/godot/GodotIO.java @@ -216,6 +216,14 @@ public class GodotIO { return result; } + public boolean hasHardwareKeyboard() { + if (edit != null) { + return edit.hasHardwareKeyboard(); + } else { + return false; + } + } + public void showKeyboard(String p_existing_text, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) { if (edit != null) { edit.showKeyboard(p_existing_text, GodotEditText.VirtualKeyboardType.values()[p_type], p_max_input_length, p_cursor_start, p_cursor_end); diff --git a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java index c085bb8886..cacc1643e3 100644 --- a/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java +++ b/platform/android/java/lib/src/org/godotengine/godot/input/GodotEditText.java @@ -264,7 +264,7 @@ public class GodotEditText extends EditText { isModifiedKey; } - boolean hasHardwareKeyboard() { + public boolean hasHardwareKeyboard() { Configuration config = getResources().getConfiguration(); boolean hasHardwareKeyboardConfig = config.keyboard != Configuration.KEYBOARD_NOKEYS && config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO; diff --git a/platform/android/java_godot_io_wrapper.cpp b/platform/android/java_godot_io_wrapper.cpp index 49913b9c30..623db39985 100644 --- a/platform/android/java_godot_io_wrapper.cpp +++ b/platform/android/java_godot_io_wrapper.cpp @@ -63,6 +63,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc _get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;"); _show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;IIII)V"); _hide_keyboard = p_env->GetMethodID(cls, "hideKeyboard", "()V"); + _has_hardware_keyboard = p_env->GetMethodID(cls, "hasHardwareKeyboard", "()Z"); _set_screen_orientation = p_env->GetMethodID(cls, "setScreenOrientation", "(I)V"); _get_screen_orientation = p_env->GetMethodID(cls, "getScreenOrientation", "()I"); _get_system_dir = p_env->GetMethodID(cls, "getSystemDir", "(IZ)Ljava/lang/String;"); @@ -220,6 +221,16 @@ bool GodotIOJavaWrapper::has_vk() { return (_show_keyboard != nullptr) && (_hide_keyboard != nullptr); } +bool GodotIOJavaWrapper::has_hardware_keyboard() { + if (_has_hardware_keyboard) { + JNIEnv *env = get_jni_env(); + ERR_FAIL_NULL_V(env, false); + return env->CallBooleanMethod(godot_io_instance, _has_hardware_keyboard); + } else { + return false; + } +} + void GodotIOJavaWrapper::show_vk(const String &p_existing, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) { if (_show_keyboard) { JNIEnv *env = get_jni_env(); diff --git a/platform/android/java_godot_io_wrapper.h b/platform/android/java_godot_io_wrapper.h index c113a13040..0a372641cb 100644 --- a/platform/android/java_godot_io_wrapper.h +++ b/platform/android/java_godot_io_wrapper.h @@ -58,6 +58,7 @@ private: jmethodID _get_unique_id = 0; jmethodID _show_keyboard = 0; jmethodID _hide_keyboard = 0; + jmethodID _has_hardware_keyboard = 0; jmethodID _set_screen_orientation = 0; jmethodID _get_screen_orientation = 0; jmethodID _get_system_dir = 0; @@ -80,6 +81,7 @@ public: Rect2i get_display_safe_area(); String get_unique_id(); bool has_vk(); + bool has_hardware_keyboard(); void show_vk(const String &p_existing, int p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end); void hide_vk(); int get_vk_height(); diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h index 0631b50f0a..7f199db997 100644 --- a/platform/ios/display_server_ios.h +++ b/platform/ios/display_server_ios.h @@ -224,6 +224,7 @@ public: void virtual_keyboard_set_height(int height); virtual int virtual_keyboard_get_height() const override; + virtual bool has_hardware_keyboard() const override; virtual void clipboard_set(const String &p_text) override; virtual String clipboard_get() const override; diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index e51d43bd89..dcc6ce9218 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -45,6 +45,8 @@ #import <sys/utsname.h> +#import <GameController/GameController.h> + static const float kDisplayServerIOSAcceleration = 1.f; DisplayServerIOS *DisplayServerIOS::get_singleton() { @@ -756,6 +758,14 @@ int DisplayServerIOS::virtual_keyboard_get_height() const { return virtual_keyboard_height; } +bool DisplayServerIOS::has_hardware_keyboard() const { + if (@available(iOS 14.0, *)) { + return [GCKeyboard coalescedKeyboard]; + } else { + return false; + } +} + void DisplayServerIOS::clipboard_set(const String &p_text) { [UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:p_text.utf8()]; } |