1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

[macOS] Process joypad input directly in the embedded process.

This commit is contained in:
Pāvels Nadtočajevs
2025-08-14 11:51:59 +03:00
parent cb850f7719
commit b9bafbd2ca
8 changed files with 12 additions and 71 deletions

View File

@@ -144,11 +144,6 @@ public:
virtual Point2i mouse_get_position() const override; virtual Point2i mouse_get_position() const override;
virtual BitField<MouseButtonMask> mouse_get_button_state() const override; virtual BitField<MouseButtonMask> 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 // MARK: - Window
virtual bool has_feature(Feature p_feature) const override; virtual bool has_feature(Feature p_feature) const override;

View File

@@ -389,36 +389,8 @@ void DisplayServerEmbedded::window_set_drop_files_callback(const Callable &p_cal
// Not supported // 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() { void DisplayServerEmbedded::process_events() {
Input *input = Input::get_singleton(); Input *input = Input::get_singleton();
for (KeyValue<int, Joy> &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(); input->flush_buffered_events();
} }

View File

@@ -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: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_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: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; parse_message_handlers["game_view:warp_mouse"] = &GameViewDebuggerMacOS::_msg_warp_mouse;
} }

View File

@@ -93,7 +93,6 @@ class EmbeddedProcessMacOS final : public EmbeddedProcessBase {
void _try_embed_process(); void _try_embed_process();
void update_embedded_process(); void update_embedded_process();
void _joy_connection_changed(int p_index, bool p_connected) const;
protected: protected:
void _notification(int p_what); void _notification(int p_what);

View File

@@ -97,19 +97,6 @@ void EmbeddedProcessMacOS::embed_process(OS::ProcessID p_pid) {
_try_embed_process(); _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() { void EmbeddedProcessMacOS::reset() {
if (!ds) { if (!ds) {
ds = static_cast<DisplayServerMacOS *>(DisplayServer::get_singleton()); ds = static_cast<DisplayServerMacOS *>(DisplayServer::get_singleton());
@@ -218,9 +205,6 @@ EmbeddedProcessMacOS::EmbeddedProcessMacOS() :
layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT); layer_host->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
layer_host->set_custom_minimum_size(Size2(100, 100)); 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 // 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. // the embedded process has implemented support to release the cursor.
ED_SHORTCUT("game_view/release_mouse", TTRC("Release Mouse"), KeyModifierMask::ALT | Key::ESCAPE); ED_SHORTCUT("game_view/release_mouse", TTRC("Release Mouse"), KeyModifierMask::ALT | Key::ESCAPE);
@@ -339,6 +323,13 @@ void LayerHost::gui_input(const Ref<InputEvent> &p_event) {
} }
} }
Ref<InputEventJoypadMotion> jm = p_event;
Ref<InputEventJoypadButton> jb = p_event;
if (jm.is_valid() || jb.is_valid()) {
accept_event();
return;
}
PackedByteArray data; PackedByteArray data;
if (encode_input_event(p_event, data)) { if (encode_input_event(p_event, data)) {
script_debugger->send_message("embed:event", { data }); script_debugger->send_message("embed:event", { data });

View File

@@ -62,8 +62,6 @@ private:
Error _msg_win_event(const Array &p_args); Error _msg_win_event(const Array &p_args);
Error _msg_notification(const Array &p_args); Error _msg_notification(const Array &p_args);
Error _msg_ime_update(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); Error _msg_ds_state(const Array &p_args);
public: public:

View File

@@ -75,8 +75,6 @@ void EmbeddedDebugger::_init_parse_message_handlers() {
parse_message_handlers["win_event"] = &EmbeddedDebugger::_msg_win_event; parse_message_handlers["win_event"] = &EmbeddedDebugger::_msg_win_event;
parse_message_handlers["notification"] = &EmbeddedDebugger::_msg_notification; parse_message_handlers["notification"] = &EmbeddedDebugger::_msg_notification;
parse_message_handlers["ime_update"] = &EmbeddedDebugger::_msg_ime_update; 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; parse_message_handlers["ds_state"] = &EmbeddedDebugger::_msg_ds_state;
} }
@@ -161,21 +159,6 @@ Error EmbeddedDebugger::_msg_notification(const Array &p_args) {
return OK; 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) { 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."); 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]; PackedByteArray data = p_args[0];

View File

@@ -1263,6 +1263,11 @@ void OS_MacOS_Embedded::run() {
@try { @try {
ds->process_events(); ds->process_events();
#ifdef SDL_ENABLED
if (joypad_sdl) {
joypad_sdl->process_events();
}
#endif
if (Main::iteration()) { if (Main::iteration()) {
break; break;
} }