diff --git a/EXPORT.json b/EXPORT.json index 2b785ab..d8d18ad 100644 --- a/EXPORT.json +++ b/EXPORT.json @@ -1372,9 +1372,9 @@ "sha256": "8ea7ca3fa1ba23a23cac4f35636f184263af0031a87352ca9cd398987a657ca2" }, "platforms/macos/App/MachineModel.swift": { - "bytes": 178684, + "bytes": 179328, "mode": "0644", - "sha256": "d9282b4c5c4e15caf4c6dd770370edd7d7406553dbfc6775522b8240bfe14a04" + "sha256": "ea316035ffba5a4c6efebc982ded86ff90232af7f42668bb836af7ff3108fa75" }, "platforms/macos/App/MachineSettings.swift": { "bytes": 1020, @@ -3087,9 +3087,9 @@ "sha256": "66ad7aba832e4f32efe3a8ecdea5dc54e53b815994db6f1fa9169a498d107564" }, "platforms/macos/Tests/SoftwareLibraryMachineLaunchTests.swift": { - "bytes": 27163, + "bytes": 27871, "mode": "0644", - "sha256": "75fda217f2996c2d87f7784e0a0aba000303ac030671957ce8862aa99236acfe" + "sha256": "1156150ca854eac302bf64ad177b95b490ac6b0da24dc40814ccf26bad2de925" }, "platforms/macos/Tests/SoftwareLibraryManualTests.swift": { "bytes": 11045, @@ -3122,9 +3122,9 @@ "sha256": "15b8a2b63f510a9617bf7930f9d15907c152d60beaeb74a4b38719a1b4d4de93" }, "platforms/macos/Tests/StartupTests.swift": { - "bytes": 48662, + "bytes": 49476, "mode": "0644", - "sha256": "3c8c32ffa3bf0198d1fa7ec247c984a0d163bbcfac9a73c187b590e44d83eec2" + "sha256": "23f622f398a0aff27e80f4bad49057aedb47fd68ffc7427b6f50826f435c7f0c" }, "platforms/macos/Tools/MCP/MCPGuestTools.h": { "bytes": 2219, diff --git a/platforms/macos/App/MachineModel.swift b/platforms/macos/App/MachineModel.swift index dd8a549..a6c325f 100644 --- a/platforms/macos/App/MachineModel.swift +++ b/platforms/macos/App/MachineModel.swift @@ -568,8 +568,12 @@ final class MachineModel: ObservableObject { private var polling = false private var imageGeneration: UInt64 = 0 private var imageRevision: UInt64 = 0 + private var observedInputGeneration: UInt64? private func accept(_ snapshot: VCCMachineSnapshot) { + let inputNeedsResynchronization = snapshot.state == .running && + (state != .running || snapshot.generation != observedInputGeneration) + observedInputGeneration = snapshot.generation diskEditorLocked = snapshot.diskEditorLocked printer.observe(snapshot) let basic = BASICDebugState(attached: snapshot.basicDebugAttached, @@ -631,6 +635,11 @@ final class MachineModel: ObservableObject { let nextHardware = HardwareState(snapshot: snapshot, activities: activity, sdcActivity: sdcActivity) if hardware != nextHardware { hardware = nextHardware } state = snapshot.state + // The core deliberately ignores host joystick submissions while paused. + // Reapply the configured interfaces only after a resume/new machine is + // running, even when neutral axes match the host's cached last sample. + // Do not initialize native input solely for receiving a snapshot. + if inputNeedsResynchronization { existingInputHub?.release() } frames = snapshot.frames error = snapshot.errorMessage guard snapshot.pixels != nil else { diff --git a/platforms/macos/Tests/SoftwareLibraryMachineLaunchTests.swift b/platforms/macos/Tests/SoftwareLibraryMachineLaunchTests.swift index e607ee3..8fa85b8 100644 --- a/platforms/macos/Tests/SoftwareLibraryMachineLaunchTests.swift +++ b/platforms/macos/Tests/SoftwareLibraryMachineLaunchTests.swift @@ -253,6 +253,11 @@ final class SoftwareLibraryMachineLaunchTests: XCTestCase { @MainActor func testManualDiskLaunchMountsWithoutInjectingCommands() async throws { let fixture = try Fixture(); defer { fixture.cleanup() } try await withMachine(fixture) { model, controller, _ in + var configuredInput = model.input.settings + configuredInput.right = PortSettings(source: .controller, interface: .tandy, device: "remembered-disconnected") + configuredInput.left = PortSettings(source: .mouse, interface: .cocoMax) + model.input.applyProfileSettings(configuredInput) + let inputEpoch = model.input.epoch let plan = try fixture.plan(cartridge: false) XCTAssertTrue(plan.commands.isEmpty); XCTAssertFalse(plan.automaticallyStarts) let prepared = try await model.prepareLibraryLaunch(plan) @@ -261,6 +266,10 @@ final class SoftwareLibraryMachineLaunchTests: XCTestCase { let running = await step(controller.snapshot) XCTAssertEqual(running.state, .running); XCTAssertTrue(running.disks[0].mounted) XCTAssertEqual(running.pasteRemaining, 0) + XCTAssertEqual(Int(running.joystickInputs[0].mode), configuredInput.right.interface.rawValue) + XCTAssertEqual(Int(running.joystickInputs[1].mode), configuredInput.left.interface.rawValue) + XCTAssertEqual(model.input.settings, configuredInput) + XCTAssertEqual(model.input.epoch, inputEpoch) XCTAssertEqual(model.diskAssignments.drives[0]?.url, plan.floppyURLs[0]) } } diff --git a/platforms/macos/Tests/StartupTests.swift b/platforms/macos/Tests/StartupTests.swift index 9b7f919..47a8757 100644 --- a/platforms/macos/Tests/StartupTests.swift +++ b/platforms/macos/Tests/StartupTests.swift @@ -356,10 +356,20 @@ extension StartupTests { "Preserving settings must also restore their interface to the newly loaded guest") var personal = try f.startup.appDefaults() personal.name = "Explicit personal input"; personal.input.right.source = .mouse + personal.input.right.interface = .cocoMax personal.input.left.source = .keyboard; personal.sound = false await model.loadProfile(personal) XCTAssertNil(model.profileError); XCTAssertEqual(model.input.settings, personal.input) XCTAssertFalse(try inputStore.loadState().automaticRightController) + let inputEpoch = model.input.epoch + model.input.poll() // A neutral sample while paused must not suppress resynchronization. + model.resume(); try await waitForStartup(model) + let resumed = await withCheckedContinuation { done in controller.snapshot { done.resume(returning: $0) } } + XCTAssertEqual(Int(resumed.joystickInputs[0].mode), personal.input.right.interface.rawValue, + "Ordinary resume must apply a profile's unchanged configured interface after paused submissions were ignored") + XCTAssertEqual(resumed.joystickInputs[0].buttons, 0) + XCTAssertEqual(model.input.epoch, inputEpoch, "Machine resynchronization is not a settings edit") + XCTAssertEqual(try inputStore.load(), personal.input) let reset = await model.restoreAppDefaults() XCTAssertTrue(reset); XCTAssertEqual(model.input.settings, .freshDefaults) XCTAssertTrue(try inputStore.loadState().automaticRightController)