diff options
Diffstat (limited to 'platform/web')
-rw-r--r-- | platform/web/detect.py | 2 | ||||
-rw-r--r-- | platform/web/display_server_web.cpp | 76 | ||||
-rw-r--r-- | platform/web/display_server_web.h | 1 | ||||
-rw-r--r-- | platform/web/emscripten_helpers.py | 1 | ||||
-rw-r--r-- | platform/web/javascript_bridge_singleton.cpp | 2 | ||||
-rw-r--r-- | platform/web/js/libs/library_godot_input.js | 17 |
6 files changed, 61 insertions, 38 deletions
diff --git a/platform/web/detect.py b/platform/web/detect.py index 3df8cbad7c..c6568625c1 100644 --- a/platform/web/detect.py +++ b/platform/web/detect.py @@ -181,7 +181,7 @@ def configure(env: "SConsEnvironment"): # Use TempFileMunge since some AR invocations are too long for cmd.exe. # Use POSIX-style paths, required with TempFileMunge. env["ARCOM_POSIX"] = env["ARCOM"].replace("$TARGET", "$TARGET.posix").replace("$SOURCES", "$SOURCES.posix") - env["ARCOM"] = "${TEMPFILE(ARCOM_POSIX)}" + env["ARCOM"] = "${TEMPFILE('$ARCOM_POSIX','$ARCOMSTR')}" # All intermediate files are just object files. env["OBJPREFIX"] = "" diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index 0420a01533..fab92b1894 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -70,7 +70,7 @@ bool DisplayServerWeb::check_size_force_redraw() { void DisplayServerWeb::fullscreen_change_callback(int p_fullscreen) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_fullscreen_change_callback).bind(p_fullscreen).call_deferred(); + callable_mp_static(DisplayServerWeb::_fullscreen_change_callback).call_deferred(p_fullscreen); return; } #endif @@ -96,7 +96,7 @@ void DisplayServerWeb::drop_files_js_callback(const char **p_filev, int p_filec) #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_drop_files_js_callback).bind(files).call_deferred(); + callable_mp_static(DisplayServerWeb::_drop_files_js_callback).call_deferred(files); return; } #endif @@ -112,7 +112,14 @@ void DisplayServerWeb::_drop_files_js_callback(const Vector<String> &p_files) { if (!ds->drop_files_callback.is_valid()) { return; } - ds->drop_files_callback.call(p_files); + Variant v_files = p_files; + const Variant *v_args[1] = { &v_files }; + Variant ret; + Callable::CallError ce; + ds->drop_files_callback.callp((const Variant **)&v_args, 1, ret, ce); + if (ce.error != Callable::CallError::CALL_OK) { + ERR_PRINT(vformat("Failed to execute drop files callback: %s.", Variant::get_callable_error_text(ds->drop_files_callback, v_args, 1, ce))); + } } // Web quit request callback. @@ -161,7 +168,7 @@ void DisplayServerWeb::key_callback(int p_pressed, int p_repeat, int p_modifiers #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_key_callback).bind(code, key, p_pressed, p_repeat, p_modifiers).call_deferred(); + callable_mp_static(DisplayServerWeb::_key_callback).call_deferred(code, key, p_pressed, p_repeat, p_modifiers); return; } #endif @@ -214,7 +221,7 @@ void DisplayServerWeb::_key_callback(const String &p_key_event_code, const Strin int DisplayServerWeb::mouse_button_callback(int p_pressed, int p_button, double p_x, double p_y, int p_modifiers) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_mouse_button_callback).bind(p_pressed, p_button, p_x, p_y, p_modifiers).call_deferred(); + callable_mp_static(DisplayServerWeb::_mouse_button_callback).call_deferred(p_pressed, p_button, p_x, p_y, p_modifiers); return true; } #endif @@ -301,7 +308,7 @@ int DisplayServerWeb::_mouse_button_callback(int p_pressed, int p_button, double void DisplayServerWeb::mouse_move_callback(double p_x, double p_y, double p_rel_x, double p_rel_y, int p_modifiers) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_mouse_move_callback).bind(p_x, p_y, p_rel_x, p_rel_y, p_modifiers).call_deferred(); + callable_mp_static(DisplayServerWeb::_mouse_move_callback).call_deferred(p_x, p_y, p_rel_x, p_rel_y, p_modifiers); return; } #endif @@ -394,7 +401,7 @@ void DisplayServerWeb::update_voices_callback(int p_size, const char **p_voice) #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_update_voices_callback).bind(voices).call_deferred(); + callable_mp_static(DisplayServerWeb::_update_voices_callback).call_deferred(voices); return; } #endif @@ -461,7 +468,7 @@ void DisplayServerWeb::tts_stop() { void DisplayServerWeb::js_utterance_callback(int p_event, int p_id, int p_pos) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_js_utterance_callback).bind(p_event, p_id, p_pos).call_deferred(); + callable_mp_static(DisplayServerWeb::_js_utterance_callback).call_deferred(p_event, p_id, p_pos); return; } #endif @@ -591,7 +598,7 @@ Point2i DisplayServerWeb::mouse_get_position() const { int DisplayServerWeb::mouse_wheel_callback(double p_delta_x, double p_delta_y) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_mouse_wheel_callback).bind(p_delta_x, p_delta_y).call_deferred(); + callable_mp_static(DisplayServerWeb::_mouse_wheel_callback).call_deferred(p_delta_x, p_delta_y); return true; } #endif @@ -654,7 +661,7 @@ int DisplayServerWeb::_mouse_wheel_callback(double p_delta_x, double p_delta_y) void DisplayServerWeb::touch_callback(int p_type, int p_count) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_touch_callback).bind(p_type, p_count).call_deferred(); + callable_mp_static(DisplayServerWeb::_touch_callback).call_deferred(p_type, p_count); return; } #endif @@ -712,7 +719,7 @@ void DisplayServerWeb::vk_input_text_callback(const char *p_text, int p_cursor) #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_vk_input_text_callback).bind(text, p_cursor).call_deferred(); + callable_mp_static(DisplayServerWeb::_vk_input_text_callback).call_deferred(text, p_cursor); return; } #endif @@ -774,7 +781,7 @@ void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_gamepad_callback).bind(p_index, p_connected, id, guid).call_deferred(); + callable_mp_static(DisplayServerWeb::_gamepad_callback).call_deferred(p_index, p_connected, id, guid); return; } #endif @@ -797,7 +804,7 @@ void DisplayServerWeb::ime_callback(int p_type, const char *p_text) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_ime_callback).bind(p_type, text).call_deferred(); + callable_mp_static(DisplayServerWeb::_ime_callback).call_deferred(p_type, text); return; } #endif @@ -866,6 +873,9 @@ void DisplayServerWeb::_ime_callback(int p_type, const String &p_text) { default: break; } + + ds->process_keys(); + Input::get_singleton()->flush_buffered_events(); } void DisplayServerWeb::window_set_ime_active(const bool p_active, WindowID p_window) { @@ -927,7 +937,7 @@ void DisplayServerWeb::update_clipboard_callback(const char *p_text) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_update_clipboard_callback).bind(text).call_deferred(); + callable_mp_static(DisplayServerWeb::_update_clipboard_callback).call_deferred(text); return; } #endif @@ -953,7 +963,7 @@ String DisplayServerWeb::clipboard_get() const { void DisplayServerWeb::send_window_event_callback(int p_notification) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(DisplayServerWeb::_send_window_event_callback).bind(p_notification).call_deferred(); + callable_mp_static(DisplayServerWeb::_send_window_event_callback).call_deferred(p_notification); return; } #endif @@ -1353,29 +1363,33 @@ DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsyn } void DisplayServerWeb::process_events() { + process_keys(); Input::get_singleton()->flush_buffered_events(); if (godot_js_input_gamepad_sample() == OK) { process_joypads(); - for (int i = 0; i < key_event_pos; i++) { - const DisplayServerWeb::KeyEvent &ke = key_event_buffer[i]; + } +} - Ref<InputEventKey> ev; - ev.instantiate(); - ev->set_pressed(ke.pressed); - ev->set_echo(ke.echo); - ev->set_keycode(ke.keycode); - ev->set_physical_keycode(ke.physical_keycode); - ev->set_key_label(ke.key_label); - ev->set_unicode(ke.unicode); - ev->set_location(ke.location); - if (ke.raw) { - dom2godot_mod(ev, ke.mod, ke.keycode); - } +void DisplayServerWeb::process_keys() { + for (int i = 0; i < key_event_pos; i++) { + const DisplayServerWeb::KeyEvent &ke = key_event_buffer[i]; - Input::get_singleton()->parse_input_event(ev); + Ref<InputEventKey> ev; + ev.instantiate(); + ev->set_pressed(ke.pressed); + ev->set_echo(ke.echo); + ev->set_keycode(ke.keycode); + ev->set_physical_keycode(ke.physical_keycode); + ev->set_key_label(ke.key_label); + ev->set_unicode(ke.unicode); + ev->set_location(ke.location); + if (ke.raw) { + dom2godot_mod(ev, ke.mod, ke.keycode); } - key_event_pos = 0; + + Input::get_singleton()->parse_input_event(ev); } + key_event_pos = 0; } int DisplayServerWeb::get_current_video_driver() const { diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h index 276ca5210c..352b3fe523 100644 --- a/platform/web/display_server_web.h +++ b/platform/web/display_server_web.h @@ -145,6 +145,7 @@ private: static void _drop_files_js_callback(const Vector<String> &p_files); void process_joypads(); + void process_keys(); static Vector<String> get_rendering_drivers_func(); static DisplayServer *create_func(const String &p_rendering_driver, WindowMode p_window_mode, VSyncMode p_vsync_mode, uint32_t p_flags, const Vector2i *p_position, const Vector2i &p_resolution, int p_screen, Context p_context, Error &r_error); diff --git a/platform/web/emscripten_helpers.py b/platform/web/emscripten_helpers.py index 745b2457fa..2cee3e8110 100644 --- a/platform/web/emscripten_helpers.py +++ b/platform/web/emscripten_helpers.py @@ -123,7 +123,6 @@ def create_template_zip(env, js, wasm, worker, side): zip_files, ZIPROOT=zip_dir, ZIPSUFFIX="${PROGSUFFIX}${ZIPSUFFIX}", - ZIPCOMSTR="Archiving $SOURCES as $TARGET", ) diff --git a/platform/web/javascript_bridge_singleton.cpp b/platform/web/javascript_bridge_singleton.cpp index a2c83d2f2b..c4dbb405a3 100644 --- a/platform/web/javascript_bridge_singleton.cpp +++ b/platform/web/javascript_bridge_singleton.cpp @@ -262,7 +262,7 @@ void JavaScriptObjectImpl::callback(void *p_ref, int p_args_id, int p_argc) { #ifdef PROXY_TO_PTHREAD_ENABLED if (!Thread::is_main_thread()) { - callable_mp_static(JavaScriptObjectImpl::_callback).bind(obj, arg).call_deferred(); + callable_mp_static(JavaScriptObjectImpl::_callback).call_deferred(obj, arg); return; } #endif diff --git a/platform/web/js/libs/library_godot_input.js b/platform/web/js/libs/library_godot_input.js index 1292c468f5..7ea89d553f 100644 --- a/platform/web/js/libs/library_godot_input.js +++ b/platform/web/js/libs/library_godot_input.js @@ -63,8 +63,15 @@ const GodotIME = { ime_position: function (x, y) { if (GodotIME.ime) { - GodotIME.ime.style.left = `${x}px`; - GodotIME.ime.style.top = `${y}px`; + const canvas = GodotConfig.canvas; + const rect = canvas.getBoundingClientRect(); + const rw = canvas.width / rect.width; + const rh = canvas.height / rect.height; + const clx = (x / rw) + rect.x; + const cly = (y / rh) + rect.y; + + GodotIME.ime.style.left = `${clx}px`; + GodotIME.ime.style.top = `${cly}px`; } }, @@ -99,10 +106,12 @@ const GodotIME = { ime.style.background = 'none'; ime.style.opacity = 0.0; ime.style.position = 'fixed'; + ime.style.textAlign = 'left'; + ime.style.fontSize = '1px'; ime.style.left = '0px'; ime.style.top = '0px'; - ime.style.width = '2px'; - ime.style.height = '2px'; + ime.style.width = '100%'; + ime.style.height = '40px'; ime.style.display = 'none'; ime.contentEditable = 'true'; |