From c7a7db3bbe6d2f8aa91c300240a78ca2c464d857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 26 Jan 2026 11:44:30 +0100 Subject: [PATCH] iOS: Track controller connect/disconnect, reset controls on disconnect. --- UI/ChatScreen.cpp | 2 +- ios/Controls.mm | 44 +++++++++++++++++++++++++++++++++++++ ios/ViewControllerCommon.mm | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 7a54038305..01d29b0b25 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -42,7 +42,7 @@ void ChatMenu::CreateContents(UI::ViewGroup *parent) { LinearLayout *quickChat = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); for (int i = 0; i < 5; i++) { std::string name = std::to_string(i + 1); - quickChat->Add(new Button(name, new LinearLayoutParams(1.0)))->OnClick.Add([this, i](UI::EventParams &e) { + quickChat->Add(new Button(name, new LinearLayoutParams(1.0)))->OnClick.Add([i](UI::EventParams &e) { sendChat(g_Config.sQuickChat[i]); }); } diff --git a/ios/Controls.mm b/ios/Controls.mm index daf133e22d..5784f372ae 100644 --- a/ios/Controls.mm +++ b/ios/Controls.mm @@ -36,6 +36,9 @@ bool InitController(GCController *controller) { } } + const std::string controllerName = [controller.vendorName ?: @"Gamepad" UTF8String]; + KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0, controllerName); + extendedProfile.buttonA.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) { controllerButtonPressed(pressed, NKCODE_BUTTON_2); // Cross }; @@ -159,6 +162,47 @@ void ShutdownController(GCController *controller) { element.preferredSystemGestureState = GCSystemGestureStateEnabled; } } + static const InputKeyCode keycodes[] = { + NKCODE_BUTTON_1, + NKCODE_BUTTON_2, + NKCODE_BUTTON_3, + NKCODE_BUTTON_4, + NKCODE_BUTTON_L1, + NKCODE_BUTTON_R1, + NKCODE_DPAD_UP, + NKCODE_DPAD_DOWN, + NKCODE_DPAD_LEFT, + NKCODE_DPAD_RIGHT, + NKCODE_BUTTON_THUMBL, + NKCODE_BUTTON_THUMBR, + NKCODE_BUTTON_SELECT, + NKCODE_BUTTON_START, + NKCODE_HOME + }; + for (InputKeyCode keyCode : keycodes) { + KeyInput key; + key.deviceId = DEVICE_ID_PAD_0; + key.flags = KeyInputFlags::UP; + key.keyCode = keyCode; + NativeKey(key); + } + + static const InputAxis axes[] = { + JOYSTICK_AXIS_X, + JOYSTICK_AXIS_Y, + JOYSTICK_AXIS_Z, + JOYSTICK_AXIS_RZ, + JOYSTICK_AXIS_LTRIGGER, + JOYSTICK_AXIS_RTRIGGER + }; + AxisInput axisInput; + axisInput.deviceId = DEVICE_ID_PAD_0; + for (InputAxis axis : axes) { + axisInput.axisId = axis; + axisInput.value = 0.0f; + NativeAxis(&axisInput, 1); + } + KeyMap::NotifyPadDisconnected(DEVICE_ID_PAD_0); } void TouchTracker::SendTouchEvent(float x, float y, int code, int pointerId) { diff --git a/ios/ViewControllerCommon.mm b/ios/ViewControllerCommon.mm index 2ee1c29b4b..8019daa8cc 100644 --- a/ios/ViewControllerCommon.mm +++ b/ios/ViewControllerCommon.mm @@ -144,6 +144,7 @@ - (void)controllerDidDisconnect:(NSNotification *)note { if (self.gameController == note.object) { + ShutdownController(self.gameController); self.gameController = nil; if ([[GCController controllers] count] > 0) {