People have dreamed of running macOS on iPad for more than a decade. Today, that dream comes true. With Virtual Mac, iPad finally breaks free from iPadOS, enabling pro apps like Xcode, Terminal, Final Cut Pro, Logic Pro, and Pixelmator Pro to run directly on device. Requires iPad Pro (M1, M2) or iPad Air (M1) running iPadOS 14 up to 16.3.1.
Shell
Swallow globe key and relay it as Fn to the VM
qwqVictorf0a93123df10
diff --git a/VirtualMac/vz/host/VirtualMacApp.m b/VirtualMac/vz/host/VirtualMacApp.mindex 548104f..eaaebb0 100644--- a/VirtualMac/vz/host/VirtualMacApp.m+++ b/VirtualMac/vz/host/VirtualMacApp.m@@ -668,6 +668,23 @@ static void sendKey(UIKeyboardHIDUsage usage, BOOL pressed) {(long)keyCode, pressed);}+// Send a guest key by its macOS virtual key code directly. Used for the globe+// key, which maps to the Fn key (kVK_Fn = 63) rather than a HID usage.+static void sendMacKey(NSInteger keyCode, BOOL pressed) {+ if (!gKeyboard)+ return;+ id event = ((id(*)(id, SEL, NSInteger, unsigned short))objc_msgSend)(+ m0(CLS("_VZKeyEvent"), "alloc"), S("initWithType:keyCode:"),+ pressed ? 0 : 1, (unsigned short)keyCode);+ ((void(*)(id, SEL, id))objc_msgSend)(+ gKeyboard, S("sendKeyEvents:"), @[event]);+ [event release];+ uint64_t count = __sync_add_and_fetch(&gKeyEventCount, 1);+ if (count <= 12)+ printf("[VirtualMac] input key=%llu mac=%ld pressed=%d\n",+ (unsigned long long)count, (long)keyCode, pressed);+}+static BOOL sendPresses(NSSet<UIPress *> *presses, BOOL pressed) {// When no guest keyboard is active, UIKit owns hardware key events (for// example numeric input in the VM configuration alert). Treating a press@@ -701,6 +718,11 @@ static void shellShortcutNotification(CFNotificationCenterRef center,usage = (UIKeyboardHIDUsage)0x2b;else if ([notification containsString:@"command-grave"])usage = (UIKeyboardHIDUsage)0x35;+ else if ([notification containsString:@"globe"]) {+ printf("[VirtualMac] SpringBoard globe relay pressed=%d\n", pressed);+ sendMacKey(63, pressed); // kVK_Fn+ return;+ }if (usage) {printf("[VirtualMac] SpringBoard shortcut relay usage=0x%lx pressed=%d\n",(unsigned long)usage, pressed);@@ -712,7 +734,7 @@ static void installShellShortcutRelay(void) {CFNotificationCenterRef center =CFNotificationCenterGetDarwinNotifyCenter();for (NSString *shortcut in @[@"command-space", @"command-tab",- @"command-grave"]) {+ @"command-grave", @"globe"]) {for (NSString *state in @[@"down", @"up"]) {NSString *name = [NSString stringWithFormat:@"com.mac.virtual.%@.%@", shortcut, state];diff --git a/VirtualMac/vz/tweak/VZKeyboardPassthrough.m b/VirtualMac/vz/tweak/VZKeyboardPassthrough.mindex 56abfde..03218ca 100644--- a/VirtualMac/vz/tweak/VZKeyboardPassthrough.m+++ b/VirtualMac/vz/tweak/VZKeyboardPassthrough.m@@ -10,6 +10,7 @@static IMP gOriginalKeyCommands;static IMP gOriginalApplicationKeyCommands;static IMP gOriginalHandleKeyHIDEvent;+static IMP gOriginalHandleKeyUIEvent;static IMP gOriginalShouldEnableSystemGesture;static IMP gOriginalShouldEnableSystemGesturePrivate;static IMP gOriginalFluidGestureShouldBegin;@@ -181,6 +182,34 @@ static void VZPostCommandShortcut(int64_t usage, BOOL pressed): "relayed consumed Command shortcut up to Virtual Mac");}+static void VZPostShortcut(const char *name, BOOL pressed)+{+ NSString *notification = [NSString stringWithFormat:+ @"com.mac.virtual.%s.%@", name, pressed ? @"down" : @"up"];+ CFNotificationCenterPostNotification(+ CFNotificationCenterGetDarwinNotifyCenter(),+ (CFStringRef)notification, NULL, NULL, YES);+ char buffer[128];+ snprintf(buffer, sizeof(buffer),+ "relayed %s %s to Virtual Mac", name, pressed ? "down" : "up");+ Log(buffer);+}++static BOOL VZIsGlobeUsage(int64_t usagePage, int64_t usage)+{+ // The globe/Fn key is an Apple vendor usage (AppleVendorTopCase page+ // 0xFF01 / 0xFF00 / 0xFF, usage 0x03). iPadOS may map it to a different+ // page. Be permissive: any non-keyboard page with usage 0x03 is almost+ // certainly the globe key. Also check Consumer page (0x0C) keyboard-layout+ // keys; 0x29D is what iPadOS keyboards actually send for the 🌐 key,+ // confirmed on-device.+ if (usage == 0x03 && usagePage != 0x07)+ return YES;+ if (usagePage == 0x0c)+ return usage == 0x22d || usage == 0x18a || usage == 0x29d;+ return NO;+}+static void VZHandleKeyHIDEvent(id self, SEL selector, CFTypeRef event){static VZIOHIDEventGetIntegerValue getIntegerValue;@@ -197,6 +226,13 @@ static void VZHandleKeyHIDEvent(id self, SEL selector, CFTypeRef event)BOOL pressed = getIntegerValue(event, VZHIDKeyboardDownField) != 0;if (usagePage == 0x07 && (usage == 0xe3 || usage == 0xe7)) {gCommandIsDown = pressed;+ } else if (VZIsGlobeUsage(usagePage, usage)) {+ // The globe/Fn key is a system key (input-source switching) that+ // iPadOS would otherwise consume. Relay it so the VM app can map+ // it to Fn, and swallow it so it never reaches the system's+ // input-method switcher.+ VZPostShortcut("globe", pressed);+ return;} else if (usagePage == 0x07 &&(usage == 0x2c || usage == 0x2b || usage == 0x35)) {uint64_t bit = 1ULL << (usage & 63);@@ -218,6 +254,43 @@ static void VZHandleKeyHIDEvent(id self, SEL selector, CFTypeRef event)self, selector, event);}+// The globe key also reaches UIKit's event layer, where iPadOS presents the+// input-method switcher. handleKeyHIDEvent: swallowing the raw HID event is+// not enough — the switcher still pops. Swallow the globe here too so the+// guest receives only the Darwin relay (Fn), never the system popup.+static void VZHandleKeyUIEvent(id self, SEL selector, id event)+{+ if (VZSharedApplicationIsTarget() &&+ VZSettingEnabled(@"KeyboardShortcutCapture")) {+ SEL hidEventSel = sel_registerName("_hidEvent");+ id hidEvent = nil;+ if ([event respondsToSelector:hidEventSel])+ hidEvent = ((id (*)(id, SEL))objc_msgSend)(event, hidEventSel);+ if (hidEvent) {+ static VZIOHIDEventGetIntegerValue getIntegerValue;+ if (!getIntegerValue)+ getIntegerValue = (VZIOHIDEventGetIntegerValue)dlsym(+ RTLD_DEFAULT, "IOHIDEventGetIntegerValue");+ if (getIntegerValue) {+ int64_t usagePage = getIntegerValue(+ (CFTypeRef)hidEvent, VZHIDKeyboardUsagePageField);+ int64_t usage = getIntegerValue(+ (CFTypeRef)hidEvent, VZHIDKeyboardUsageField);+ if (VZIsGlobeUsage(usagePage, usage)) {+ static unsigned char logged;+ if (!logged) {+ Log("swallowed globe in _handleKeyUIEvent:");+ logged = 1;+ }+ return;+ }+ }+ }+ }+ ((void (*)(id, SEL, id))gOriginalHandleKeyUIEvent)(+ self, selector, event);+}+static void VZScheduleOneShotOpen(void){if (access(gOpenAfterRespring, F_OK) != 0)@@ -328,4 +401,16 @@ static void VZInstallKeyboardPassthrough(void)fluidTouchMethod, (IMP)VZFluidGestureShouldReceiveTouch);Log("installed active-VM fluid multitasking-gesture suppression");+ // Swallow the globe key at the UIKit event layer to suppress the+ // input-method switcher popup that handleKeyHIDEvent: can't stop.+ Method keyUIEventMethod = class_getInstanceMethod(+ application, sel_registerName("_handleKeyUIEvent:"));+ if (keyUIEventMethod) {+ gOriginalHandleKeyUIEvent = method_setImplementation(+ keyUIEventMethod, (IMP)VZHandleKeyUIEvent);+ Log("installed _handleKeyUIEvent: globe input-method suppression");+ } else {+ Log("UIApplication _handleKeyUIEvent: unavailable");+ }+}