Merge pull request #56950 from timothyqiu/has-clipboard-3.x

This commit is contained in:
Rémi Verschelde 2022-01-20 12:09:53 +01:00 committed by GitHub
commit a9b10054b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 52 additions and 1 deletions

View File

@ -222,6 +222,10 @@ String _OS::get_clipboard() const {
return OS::get_singleton()->get_clipboard(); return OS::get_singleton()->get_clipboard();
} }
bool _OS::has_clipboard() const {
return OS::get_singleton()->has_clipboard();
}
int _OS::get_video_driver_count() const { int _OS::get_video_driver_count() const {
return OS::get_singleton()->get_video_driver_count(); return OS::get_singleton()->get_video_driver_count();
} }
@ -1227,6 +1231,7 @@ void _OS::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard); ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard);
ClassDB::bind_method(D_METHOD("get_clipboard"), &_OS::get_clipboard); ClassDB::bind_method(D_METHOD("get_clipboard"), &_OS::get_clipboard);
ClassDB::bind_method(D_METHOD("has_clipboard"), &_OS::has_clipboard);
//will not delete for now, just unexpose //will not delete for now, just unexpose
//ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0)); //ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));

View File

@ -164,6 +164,7 @@ public:
void set_clipboard(const String &p_text); void set_clipboard(const String &p_text);
String get_clipboard() const; String get_clipboard() const;
bool has_clipboard() const;
void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0); void set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen = 0);
Size2 get_video_mode(int p_screen = 0) const; Size2 get_video_mode(int p_screen = 0) const;

View File

@ -157,10 +157,15 @@ int OS::get_low_processor_usage_mode_sleep_usec() const {
void OS::set_clipboard(const String &p_text) { void OS::set_clipboard(const String &p_text) {
_local_clipboard = p_text; _local_clipboard = p_text;
} }
String OS::get_clipboard() const { String OS::get_clipboard() const {
return _local_clipboard; return _local_clipboard;
} }
bool OS::has_clipboard() const {
return !get_clipboard().empty();
}
String OS::get_executable_path() const { String OS::get_executable_path() const {
return _execpath; return _execpath;
} }

View File

@ -176,6 +176,7 @@ public:
virtual void set_clipboard(const String &p_text); virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const; virtual String get_clipboard() const;
virtual bool has_clipboard() const;
virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0) = 0; virtual void set_video_mode(const VideoMode &p_video_mode, int p_screen = 0) = 0;
virtual VideoMode get_video_mode(int p_screen = 0) const = 0; virtual VideoMode get_video_mode(int p_screen = 0) const = 0;

View File

@ -604,6 +604,12 @@
[b]Note:[/b] This method is implemented on macOS. [b]Note:[/b] This method is implemented on macOS.
</description> </description>
</method> </method>
<method name="has_clipboard" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if there is content on the clipboard.
</description>
</method>
<method name="has_environment" qualifiers="const"> <method name="has_environment" qualifiers="const">
<return type="bool" /> <return type="bool" />
<argument index="0" name="variable" type="String" /> <argument index="0" name="variable" type="String" />

View File

@ -786,10 +786,14 @@ public class Godot extends Fragment implements SensorEventListener, IDownloaderC
} }
} }
public boolean hasClipboard() {
return mClipboard.hasPrimaryClip();
}
public String getClipboard() { public String getClipboard() {
String copiedText = ""; String copiedText = "";
if (mClipboard.getPrimaryClip() != null) { if (mClipboard.hasPrimaryClip()) {
ClipData.Item item = mClipboard.getPrimaryClip().getItemAt(0); ClipData.Item item = mClipboard.getPrimaryClip().getItemAt(0);
copiedText = item.getText().toString(); copiedText = item.getText().toString();
} }

View File

@ -69,6 +69,7 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_
_get_GLES_version_code = p_env->GetMethodID(godot_class, "getGLESVersionCode", "()I"); _get_GLES_version_code = p_env->GetMethodID(godot_class, "getGLESVersionCode", "()I");
_get_clipboard = p_env->GetMethodID(godot_class, "getClipboard", "()Ljava/lang/String;"); _get_clipboard = p_env->GetMethodID(godot_class, "getClipboard", "()Ljava/lang/String;");
_set_clipboard = p_env->GetMethodID(godot_class, "setClipboard", "(Ljava/lang/String;)V"); _set_clipboard = p_env->GetMethodID(godot_class, "setClipboard", "(Ljava/lang/String;)V");
_has_clipboard = p_env->GetMethodID(godot_class, "hasClipboard", "()Z");
_request_permission = p_env->GetMethodID(godot_class, "requestPermission", "(Ljava/lang/String;)Z"); _request_permission = p_env->GetMethodID(godot_class, "requestPermission", "(Ljava/lang/String;)Z");
_request_permissions = p_env->GetMethodID(godot_class, "requestPermissions", "()Z"); _request_permissions = p_env->GetMethodID(godot_class, "requestPermissions", "()Z");
_get_granted_permissions = p_env->GetMethodID(godot_class, "getGrantedPermissions", "()[Ljava/lang/String;"); _get_granted_permissions = p_env->GetMethodID(godot_class, "getGrantedPermissions", "()[Ljava/lang/String;");
@ -270,6 +271,21 @@ void GodotJavaWrapper::set_clipboard(const String &p_text) {
} }
} }
bool GodotJavaWrapper::has_has_clipboard() {
return _has_clipboard != 0;
}
bool GodotJavaWrapper::has_clipboard() {
if (_has_clipboard) {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND_V(env == nullptr, false);
return env->CallBooleanMethod(godot_instance, _has_clipboard);
} else {
return false;
}
}
bool GodotJavaWrapper::request_permission(const String &p_name) { bool GodotJavaWrapper::request_permission(const String &p_name) {
if (_request_permission) { if (_request_permission) {
JNIEnv *env = get_jni_env(); JNIEnv *env = get_jni_env();

View File

@ -58,6 +58,7 @@ private:
jmethodID _get_GLES_version_code = 0; jmethodID _get_GLES_version_code = 0;
jmethodID _get_clipboard = 0; jmethodID _get_clipboard = 0;
jmethodID _set_clipboard = 0; jmethodID _set_clipboard = 0;
jmethodID _has_clipboard = 0;
jmethodID _request_permission = 0; jmethodID _request_permission = 0;
jmethodID _request_permissions = 0; jmethodID _request_permissions = 0;
jmethodID _get_granted_permissions = 0; jmethodID _get_granted_permissions = 0;
@ -95,6 +96,8 @@ public:
String get_clipboard(); String get_clipboard();
bool has_set_clipboard(); bool has_set_clipboard();
void set_clipboard(const String &p_text); void set_clipboard(const String &p_text);
bool has_has_clipboard();
bool has_clipboard();
bool request_permission(const String &p_name); bool request_permission(const String &p_name);
bool request_permissions(); bool request_permissions();
Vector<String> get_granted_permissions() const; Vector<String> get_granted_permissions() const;

View File

@ -423,6 +423,15 @@ String OS_Android::get_clipboard() const {
return OS_Unix::get_clipboard(); return OS_Unix::get_clipboard();
} }
bool OS_Android::has_clipboard() const {
// DO we really need the fallback to OS_Unix here?!
if (godot_java->has_has_clipboard()) {
return godot_java->has_clipboard();
}
return OS_Unix::has_clipboard();
}
String OS_Android::get_model_name() const { String OS_Android::get_model_name() const {
String model = godot_io_java->get_model(); String model = godot_io_java->get_model();
if (model != "") if (model != "")

View File

@ -151,6 +151,7 @@ public:
virtual String get_locale() const; virtual String get_locale() const;
virtual void set_clipboard(const String &p_text); virtual void set_clipboard(const String &p_text);
virtual String get_clipboard() const; virtual String get_clipboard() const;
virtual bool has_clipboard() const;
virtual String get_model_name() const; virtual String get_model_name() const;
virtual int get_screen_dpi(int p_screen = 0) const; virtual int get_screen_dpi(int p_screen = 0) const;