From b9bafbd2caa962848ca6c3b96d2f771015ce680a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Thu, 14 Aug 2025 11:51:59 +0300 Subject: [PATCH] [macOS] Process joypad input directly in the embedded process. --- platform/macos/display_server_embedded.h | 5 ---- platform/macos/display_server_embedded.mm | 28 ------------------- .../macos/editor/embedded_game_view_plugin.mm | 2 -- .../macos/editor/embedded_process_macos.h | 1 - .../macos/editor/embedded_process_macos.mm | 23 +++++---------- platform/macos/embedded_debugger.h | 2 -- platform/macos/embedded_debugger.mm | 17 ----------- platform/macos/os_macos.mm | 5 ++++ 8 files changed, 12 insertions(+), 71 deletions(-) diff --git a/platform/macos/display_server_embedded.h b/platform/macos/display_server_embedded.h index 2d861428b33..39f22f255c2 100644 --- a/platform/macos/display_server_embedded.h +++ b/platform/macos/display_server_embedded.h @@ -144,11 +144,6 @@ public: virtual Point2i mouse_get_position() const override; virtual BitField mouse_get_button_state() const override; - // MARK: - Joystick - - void joy_add(int p_idx, const String &p_name); - void joy_del(int p_idx); - // MARK: - Window virtual bool has_feature(Feature p_feature) const override; diff --git a/platform/macos/display_server_embedded.mm b/platform/macos/display_server_embedded.mm index 8693da87ef5..916c681dcb9 100644 --- a/platform/macos/display_server_embedded.mm +++ b/platform/macos/display_server_embedded.mm @@ -389,36 +389,8 @@ void DisplayServerEmbedded::window_set_drop_files_callback(const Callable &p_cal // Not supported } -void DisplayServerEmbedded::joy_add(int p_idx, const String &p_name) { - Joy *joy = joysticks.getptr(p_idx); - if (joy == nullptr) { - joysticks[p_idx] = Joy(p_name); - Input::get_singleton()->joy_connection_changed(p_idx, true, p_name); - } -} - -void DisplayServerEmbedded::joy_del(int p_idx) { - if (joysticks.erase(p_idx)) { - Input::get_singleton()->joy_connection_changed(p_idx, false, String()); - } -} - void DisplayServerEmbedded::process_events() { Input *input = Input::get_singleton(); - for (KeyValue &kv : joysticks) { - uint64_t ts = input->get_joy_vibration_timestamp(kv.key); - if (ts > kv.value.timestamp) { - kv.value.timestamp = ts; - Vector2 strength = input->get_joy_vibration_strength(kv.key); - if (strength == Vector2()) { - EngineDebugger::get_singleton()->send_message("game_view:joy_stop", { kv.key }); - } else { - float duration = input->get_joy_vibration_duration(kv.key); - EngineDebugger::get_singleton()->send_message("game_view:joy_start", { kv.key, duration, strength }); - } - } - } - input->flush_buffered_events(); } diff --git a/platform/macos/editor/embedded_game_view_plugin.mm b/platform/macos/editor/embedded_game_view_plugin.mm index 3ec74421679..ec0166256cd 100644 --- a/platform/macos/editor/embedded_game_view_plugin.mm +++ b/platform/macos/editor/embedded_game_view_plugin.mm @@ -131,8 +131,6 @@ void GameViewDebuggerMacOS::_init_capture_message_handlers() { parse_message_handlers["game_view:mouse_set_mode"] = &GameViewDebuggerMacOS::_msg_mouse_set_mode; parse_message_handlers["game_view:window_set_ime_active"] = &GameViewDebuggerMacOS::_msg_window_set_ime_active; parse_message_handlers["game_view:window_set_ime_position"] = &GameViewDebuggerMacOS::_msg_window_set_ime_position; - parse_message_handlers["game_view:joy_start"] = &GameViewDebuggerMacOS::_msg_joy_start; - parse_message_handlers["game_view:joy_stop"] = &GameViewDebuggerMacOS::_msg_joy_stop; parse_message_handlers["game_view:warp_mouse"] = &GameViewDebuggerMacOS::_msg_warp_mouse; } diff --git a/platform/macos/editor/embedded_process_macos.h b/platform/macos/editor/embedded_process_macos.h index 3da6bbdd574..82359fe86b9 100644 --- a/platform/macos/editor/embedded_process_macos.h +++ b/platform/macos/editor/embedded_process_macos.h @@ -93,7 +93,6 @@ class EmbeddedProcessMacOS final : public EmbeddedProcessBase { void _try_embed_process(); void update_embedded_process(); - void _joy_connection_changed(int p_index, bool p_connected) const; protected: void _notification(int p_what); diff --git a/platform/macos/editor/embedded_process_macos.mm b/platform/macos/editor/embedded_process_macos.mm index f780d6d039f..7cd4fb13603 100644 --- a/platform/macos/editor/embedded_process_macos.mm +++ b/platform/macos/editor/embedded_process_macos.mm @@ -97,19 +97,6 @@ void EmbeddedProcessMacOS::embed_process(OS::ProcessID p_pid) { _try_embed_process(); } -void EmbeddedProcessMacOS::_joy_connection_changed(int p_index, bool p_connected) const { - if (!script_debugger) { - return; - } - - if (p_connected) { - String name = Input::get_singleton()->get_joy_name(p_index); - script_debugger->send_message("embed:joy_add", { p_index, name }); - } else { - script_debugger->send_message("embed:joy_del", { p_index }); - } -} - void EmbeddedProcessMacOS::reset() { if (!ds) { ds = static_cast(DisplayServer::get_singleton()); @@ -218,9 +205,6 @@ EmbeddedProcessMacOS::EmbeddedProcessMacOS() : layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT); layer_host->set_custom_minimum_size(Size2(100, 100)); - Input *input = Input::get_singleton(); - input->connect(SNAME("joy_connection_changed"), callable_mp(this, &EmbeddedProcessMacOS::_joy_connection_changed)); - // This shortcut allows a user to forcibly release a captured mouse from within the editor, regardless of whether // the embedded process has implemented support to release the cursor. ED_SHORTCUT("game_view/release_mouse", TTRC("Release Mouse"), KeyModifierMask::ALT | Key::ESCAPE); @@ -339,6 +323,13 @@ void LayerHost::gui_input(const Ref &p_event) { } } + Ref jm = p_event; + Ref jb = p_event; + if (jm.is_valid() || jb.is_valid()) { + accept_event(); + return; + } + PackedByteArray data; if (encode_input_event(p_event, data)) { script_debugger->send_message("embed:event", { data }); diff --git a/platform/macos/embedded_debugger.h b/platform/macos/embedded_debugger.h index 6d0ff0612f2..74217b2f20e 100644 --- a/platform/macos/embedded_debugger.h +++ b/platform/macos/embedded_debugger.h @@ -62,8 +62,6 @@ private: Error _msg_win_event(const Array &p_args); Error _msg_notification(const Array &p_args); Error _msg_ime_update(const Array &p_args); - Error _msg_joy_add(const Array &p_args); - Error _msg_joy_del(const Array &p_args); Error _msg_ds_state(const Array &p_args); public: diff --git a/platform/macos/embedded_debugger.mm b/platform/macos/embedded_debugger.mm index 748d94a0360..d89f8981d67 100644 --- a/platform/macos/embedded_debugger.mm +++ b/platform/macos/embedded_debugger.mm @@ -75,8 +75,6 @@ void EmbeddedDebugger::_init_parse_message_handlers() { parse_message_handlers["win_event"] = &EmbeddedDebugger::_msg_win_event; parse_message_handlers["notification"] = &EmbeddedDebugger::_msg_notification; parse_message_handlers["ime_update"] = &EmbeddedDebugger::_msg_ime_update; - parse_message_handlers["joy_add"] = &EmbeddedDebugger::_msg_joy_add; - parse_message_handlers["joy_del"] = &EmbeddedDebugger::_msg_joy_del; parse_message_handlers["ds_state"] = &EmbeddedDebugger::_msg_ds_state; } @@ -161,21 +159,6 @@ Error EmbeddedDebugger::_msg_notification(const Array &p_args) { return OK; } -Error EmbeddedDebugger::_msg_joy_add(const Array &p_args) { - ERR_FAIL_COND_V_MSG(p_args.size() != 2, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'joy_add' message."); - int idx = p_args[0]; - String name = p_args[1]; - ds->joy_add(idx, name); - return OK; -} - -Error EmbeddedDebugger::_msg_joy_del(const Array &p_args) { - ERR_FAIL_COND_V_MSG(p_args.size() != 1, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'joy_del' message."); - int idx = p_args[0]; - ds->joy_del(idx); - return OK; -} - Error EmbeddedDebugger::_msg_ds_state(const Array &p_args) { ERR_FAIL_COND_V_MSG(p_args.size() != 1, ERR_INVALID_PARAMETER, "Invalid number of arguments for 'ds_state' message."); PackedByteArray data = p_args[0]; diff --git a/platform/macos/os_macos.mm b/platform/macos/os_macos.mm index 6a6eae96878..0909329bac5 100644 --- a/platform/macos/os_macos.mm +++ b/platform/macos/os_macos.mm @@ -1263,6 +1263,11 @@ void OS_MacOS_Embedded::run() { @try { ds->process_events(); +#ifdef SDL_ENABLED + if (joypad_sdl) { + joypad_sdl->process_events(); + } +#endif if (Main::iteration()) { break; }