Run a virtual iPhone on an Apple Silicon Mac.
Swift
Follow the mouse in a VM window that is not the key window
Jacky289f816dfef2
diff --git a/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachineView.swift b/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachineView.swiftindex 4bff9dc5..82da26c1 100644--- a/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachineView.swift+++ b/VPhoneExecutable/VPhoneVirtualization/UI/VirtualMachine/VPhoneVirtualMachineView.swift@@ -151,8 +151,10 @@ class VPhoneVirtualMachineView: VZVirtualMachineView {if let area = pointerTrackingArea {removeTrackingArea(area)}+ // Always, not only in the key window: a VM window opened behind+ // another app, or not yet clicked, should still show hover.let area = NSTrackingArea(- rect: .zero, options: [.mouseMoved, .cursorUpdate, .activeInKeyWindow, .inVisibleRect], owner: self,+ rect: .zero, options: [.mouseMoved, .cursorUpdate, .activeAlways, .inVisibleRect], owner: self,)addTrackingArea(area)pointerTrackingArea = area@@ -164,14 +166,16 @@ class VPhoneVirtualMachineView: VZVirtualMachineView {override func mouseMoved(with event: NSEvent) {super.mouseMoved(with: event)guard guestPointerFollowsMouse, let control else { return }- Self.hiddenCursor.set()+ if hidesHostCursor {+ Self.hiddenCursor.set()+ }control.movePointer(to: interfacePoint(convert(event.locationInWindow, from: nil)))}/// The guest's pointer stands in for the Mac's over the display, so the/// Mac's is hidden there, as Universal Control hides it on the iPad.override func cursorUpdate(with event: NSEvent) {- if guestPointerFollowsMouse {+ if hidesHostCursor {Self.hiddenCursor.set()} else {super.cursorUpdate(with: event)@@ -182,6 +186,12 @@ class VPhoneVirtualMachineView: VZVirtualMachineView {trackpadGesturesEnabled && control?.supportsPointerScroll == true}+ /// Only in the key window: over a window in the background the Mac's+ /// cursor is the one the user is steering with.+ private var hidesHostCursor: Bool {+ guestPointerFollowsMouse && window?.isKeyWindow == true+ }+/// A cursor with nothing to draw. `NSCursor.hide()` is counted and/// app-wide, so it would have to be balanced on every way out of the view.private static let hiddenCursor = NSCursor(image: NSImage(size: NSSize(width: 1, height: 1)), hotSpot: .zero)@@ -225,7 +235,9 @@ class VPhoneVirtualMachineView: VZVirtualMachineView {currentTouchSwipeAim = 0// Bring the guest's pointer back where the finger lifted.if guestPointerFollowsMouse, let control {- Self.hiddenCursor.set()+ if hidesHostCursor {+ Self.hiddenCursor.set()+ }control.movePointer(to: interfacePoint(localPoint))}}